Module const
[hide private]
[frames] | no frames]

Source Code for Module const

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  #-------------------------------------------------------------------- 
  4  # Filename: const.py 
  5  # Author: Mazhugin Aleksey 
  6  # Created: 2019/07/25 
  7  # ID: $Id: const.py 63 2019-09-09 15:31:40Z Aleksey $ 
  8  # URL: $URL: file:///D:/svn_/pybag/trunc/src/const.py $ 
  9  # Copyright: Copyright (c) 2019, Mazhugin Aleksey. 
 10  # License: BSD 
 11  #-------------------------------------------------------------------- 
 12   
 13  """ 
 14  Global constants. 
 15  """ 
 16   
 17  #__docformat__ = "restructuredtext" # "epytext" 
 18   
 19   
 20   
 21  z_db_version = u'0.2'#: Database version. 
 22   
 23  z_db_marker = u'PYBAG DB version = ' #: Database marker. 
 24   
 25  z_db_marker_len = len(z_db_marker) #: Database marker length. 
 26   
 27  z_pbls = u'pybaglink start:' #: Symlink emulation start marker. 
 28   
 29  z_pble = u':pybaglink end' #: Symlink emulation end marker. 
 30   
 31  z_pblmaxlen = 4096 #: Maximum symlink emulation file length. 
 32   
 33   
 34   
 35   
 36  # Properties names. 
 37   
 38  P_OUTPUT = u'output' 
 39  P_SHOWTIPS = u'showtips' 
 40  P_WRITECOLSATEXIT = u'writecolsatexit' 
 41  P_TIPSNUMBER = u'tipsnumber' 
 42  P_GUI = u'GUI' 
 43  P_DEBUG = u'debug' 
 44  P_EMUL = u'emulation' 
 45  P_LOGGING = u'logging' 
 46  P_VERB = u'verbosity' 
 47  P_COLORIZE = u'colorize' 
 48  P_OUTFILTER = u'outfilter' 
 49   
 50   
 51   
 52  PYBAG_DEBUG_DEFAULT = u'0' #: Default value of L{cfg.PYBAG_DEBUG}. 
 53   
 54  PYBAG_LOG_DEFAULT = u'1' #: Default value of L{cfg.PYBAG_LOG}. 
 55   
 56  PYBAG_EMUL_DEFAULT = u'1' #: Default value of L{cfg.PYBAG_EMUL}. 
 57   
 58  PYBAG_COLORIZE_DEFAULT = u'1' #: Default value of L{cfg.PYBAG_COLORIZE}. 
 59   
 60  VERBOSE_DEFAULT = u'3' #: Default value of L{cfg.VERBOSE}. 
 61   
 62  CRC32BUF = 0xFFFFF #: CRC32 read buffer (2^20 == 1'048'576). 
 63   
 64  DBDUMPMAX = 500 #: DBDUMP count restrict. 
 65   
 66  LOOPN = 10000 #: Loops in cicles between CANCEL testing. 
 67   
 68   
 69   
 70  # Time shift constants. 
 71   
 72  TSDIRNONE = 0 #: No timeshift. 
 73  TSDIRBAG = 1 #: Timeshift to bag. 
 74  TSDIRORIG = 2 #: Timeshift to origin 
 75   
 76   
 77  # CONSTANTS for LOCK indexing. 
 78   
 79  LI_CANCEL = 0 
 80  LI_ERROR = 1 
 81  LI_PERCENT = 2 #: Percents of done for current function. 
 82  LI_PERCENT100 = 3 #: 100% percents for current function. 
 83  LI_DESC = 4 #: Action description. 
 84  LI_PERCENTPART = 5 #: Percents of global of current function 
 85  LI_PERCENTGLOBAL = 6 #: Global percents done 
 86  LI_FUN2 = 7 #: Function which must run after thread exited. 
 87  LI_UPDATEFILTER = 8 #: True if need update list by filter. 
 88  LI_FILTERRUNNING = 9 #: True if filter running. 
 89  LI_THREAD = 10 #: True if thread running. 
 90  LI_LENGTH = 11 
 91   
 92   
 93   
 94  # CONSTANTS for DB dictionary list. 
 95   
 96  # Indexes. 
 97   
 98  DBPATH = 0 #: Path as is in DB. 
 99   
100  IBAG = 100 #: Bag group index. 
101  ISYNC = 200 #: Original group index. 
102  IDB = 300 #: DB group index. 
103   
104  # Sub groups indexes. 
105   
106  IFLAG = 1 #: Flag subgroup. 
107  ISIZE = 2 #: Size subgroup. 
108  IMDATE = 3 #: Modify date subgroup. 
109  ICRC32 = 4 #: CRC32 subgroup. 
110  IREAD = 5 #: Read subgroup. 
111  IPATH = 6 #: Path subgroup. 
112  ILINK = 7 #: Link point subgroup. 
113   
114  DBBAGFLAG = IBAG + IFLAG 
115  DBBAGSIZE = IBAG + ISIZE 
116  DBBAGMDATE = IBAG + IMDATE 
117  DBBAGCRC32 = IBAG + ICRC32 
118  DBBAGREAD = IBAG + IREAD 
119  DBBAGPATH = IBAG + IPATH 
120  DBBAGLINK = IBAG + ILINK 
121   
122  DBDBFLAG = IDB + IFLAG 
123  DBDBSIZE = IDB + ISIZE 
124  DBDBMDATE = IDB + IMDATE 
125  DBDBCRC32 = IDB + ICRC32 
126  DBDBREAD = IDB + IREAD 
127  DBDBLINK = IDB + ILINK 
128  DBDBPATH = IDB + IPATH # Path into DB converted to OS. 
129   
130  DBORIGFLAG = ISYNC + IFLAG 
131  DBORIGSIZE = ISYNC + ISIZE 
132  DBORIGMDATE = ISYNC + IMDATE 
133  DBORIGCRC32 = ISYNC + ICRC32 
134  DBORIGREAD = ISYNC + IREAD 
135  DBORIGPATH = ISYNC + IPATH 
136  DBORIGLINK = ISYNC + ILINK 
137   
138  DBDIR = 15 #: Direction of syncronization. 
139  DBSYNC = 17 #: Syncronization status. 
140  DBCOMPARE = 18 #: Compare property from config. 
141  DBSYMLINK = 19 #: Symlink property from config. 
142  DBDESC = 20 #: Description of comparison, syncronization. 
143  DBDIRMAN = 21 #: Manual overwrite (GUI). 
144  DBDESCMAN = 22 #: Manual description (GUI). 
145  DBITEMID = 23 #: ItemId into treeCtrl (GUI). 
146  DBDIRREADED = 24 #: As L{DBDIR}, but after reading. 
147  DBDESCREADED = 25 #: As L{DBDESC}, but after reading. 
148  DBSYMLINKEMUL = 26 #: Emulate symlink or not for current item. 
149  DBBACKUP = 27 #: Backuped item. 
150   
151  # Values. 
152   
153  DBBACKUPYES = True #: Backuped item. 
154  DBBACKUPNO = False #: Not backuped item. 
155  DBREADYES = True #: Item was tried read. 
156  DBREADNONE = bool() #: Item not tried read. 
157  DBSYMEMULNONE = bool() # No emulation 
158  DBFLAGNONE = unicode() #: No flag. 
159  DBFLAGDIR = u'd' #: Directory. 
160  DBFLAGFILE = u'f' #: Regular file. 
161  DBFLAGSYMLINK = u's' #: Symlink. 
162  DBFLAGUNKNOWN = u'u' #: Unknown item type. 
163  DBMDATENONE = float() #: None modify date. 
164  DBNONE = int() #: Empty/None item. 
165  DBPATHNONE = unicode() #: Empty path. 
166  DBDESCNONE = unicode(u'Not compared.') #: Empty description. 
167  DBDESCMANNONE = unicode(u'') #: Empty description for manual (GUI). 
168  DBDESCOK = unicode(u'Ok.') #: Successfull description. 
169  DBLINKNONE = u'-' #: Fill string for item in DB if it's not a link. 
170  DBITEMNONE = None 
171   
172  # Direction flag. 
173   
174  DBDIRNONE = DBNONE #: Direction None. 
175  DBDIRBAG = 1 #: Direction left (to bag). 
176  DBDIRORIG = 2 #: Direction right (to orig). 
177  DBDIRDB = 4 #: Direction to DB. 
178  DBDIRCOPY = 8 #: Copy to. 
179  DBDIRDELETE = 16 #: Delete. 
180  DBDIRWARNING = 32 #: If Warning. 
181  DBDIRCONFLICT = 64 #: If conflict. 
182  DBDIRERROR = 128 #: If error occur. 
183  DBDIRNEW = 256 #: New item. 
184  DBDIRUNCHANGED = 512 #: Unchanged item. 
185  DBDIRFORCED = 1024 #: Indicate that file action is forced. 
186  DBDIRIGNORED = 2048 #: indicate ignored files. 
187  DBDIRDIFF = 4096 #: Different direction. 
188  DBDIROK = 8192 #: Ok flag. 
189  DBDIRRESTORE = 16384 #: Used for restore compared direction. 
190  DBDIRTS = 32768 #: Indicate timeshift. 
191   
192  DBSYNCNONE = DBNONE #: Syncronization None. 
193  DBSYNCERRREADBAG = 1 #: Error then read from bag. 
194  DBSYNCERRREADSYNC = 2 #: Error then read from orig. 
195  DBSYNCERRREAD = DBSYNCERRREADBAG | DBSYNCERRREADSYNC #: Error then read items. 
196  DBSYNCERRWRITEBAG = 4 #: Error then write to bag. 
197  DBSYNCERRWRITESYNC = 8 #: Error then write to orig. 
198  DBSYNCERRWRITE = DBSYNCERRWRITEBAG | DBSYNCERRWRITESYNC #: Error then write items. 
199  DBSYNCOK = 16 #: Syncronization saccessfull. 
200  DBSYNCERROTHER = 32 #: Other error then sync. 
201  DBSYNCERRCOMPARE = 64 #: Error from compare. 
202  DBSYNCERROR = DBSYNCERRREAD | DBSYNCERRWRITE | DBSYNCERROTHER | DBSYNCERRCOMPARE #: All errors. 
203  DBSYNCCOMPARE = 128 #: Compare and syncronize this record. 
204  DBSYNCIGNORED = 256 #: Ignored. 
205  DBSYNCCONFLICT = 512 #: Conflict. 
206   
207  # Force direction in conflicts. 
208   
209  DBFORCEDIRNONE = 0 #: Do nothing. 
210  DBFORCEDIRBAG = 1 #: In all conflicts copy to bag. 
211  DBFORCEDIRORIGIN = 2 #: In all conflicts copy to origin. 
212  DBFORCEDIROLDER = 4 #: In all conflicts use older. May be used with "NEWER", "OLDER" flags. 
213  DBFORCEDIRNEWER = 8 #: In all conflicts use newer. May be used with "NEWER", "OLDER" flags. 
214  DBFORCEDIRBAGALL = 16 #: All changes from origin to bag. 
215  DBFORCEDIRORIGINALL = 32 #: All changes from bag to origin. 
216  DBFORCEDIRORIGINCOPY = 64 #: Copying changes from bag to origin (do not delete from origin). 
217  DBFORCEDIRBAGCOPY = 128 #: Copying changes from origin to bag (do not delete from bag). 
218   
219  BACKUPDIR = DBFORCEDIRBAGALL #: Backup mode direction. 
220   
221  Z_DBFORCE = { 
222      u'no':DBFORCEDIRNONE, 
223      u'bag':DBFORCEDIRBAG, 
224      u'origin':DBFORCEDIRORIGIN, 
225      u'newer':DBFORCEDIRNEWER, 
226      u'older':DBFORCEDIROLDER, 
227      u'bagall':DBFORCEDIRBAGALL, 
228      u'originall':DBFORCEDIRORIGINALL, 
229      u'bagcopy':DBFORCEDIRBAGCOPY, 
230      u'origincopy':DBFORCEDIRORIGINCOPY, 
231      } #: Direction force array. 
232   
233  z_action_choise = [(u"No",DBFORCEDIRNONE), (u"To bag",DBFORCEDIRBAG), (u"To origin",DBFORCEDIRORIGIN), 
234      (u"Newer",DBFORCEDIRNEWER), (u"Older",DBFORCEDIROLDER), 
235      (u"Newer, to bag",DBFORCEDIRNEWER | DBFORCEDIRBAG), (u"Newer, to origin",DBFORCEDIRNEWER | DBFORCEDIRORIGIN), 
236      (u"Older, to bag",DBFORCEDIROLDER | DBFORCEDIRBAG), (u"Older, to origin",DBFORCEDIROLDER | DBFORCEDIRORIGIN), 
237      (u"To bag all",DBFORCEDIRBAGALL), (u"To origin all",DBFORCEDIRORIGINALL), (u"To bag copy",DBFORCEDIRBAGCOPY), 
238      (u"To origin copy",DBFORCEDIRORIGINCOPY), 
239      ] #: Actions choise for GUI. 
240   
241   
242   
243  # Column indexes. 
244  COL_NAME = 0 
245  COL_HEADING = 1 
246  COL_VISIBLE = 2 
247  COL_WIDTH = 3 
248  COL_FORMAT = 4 
249   
250  # Root properties constats. 
251   
252  P_IGNORE = u'ignore' #: Property ignore. 
253  P_SYMLINK = u'symlink' #: Property symbolic link. 
254  P_COMPARE = u'compare' #: Property compare. 
255  P_BACKUP = u'backup' #: Property backup. 
256  P_SELECTDEFAULT = u'selectdefault' #: Property selectdefault 
257   
258  P_IGNORENONE = u'' #: No ignores. 
259  P_SYMLINKIGNORE = u'ignore' #: Ignore symlink. 
260  P_SYMLINKIGNORENOEMUL = u'ignorenoemul' #: Ignore symlink, no emulation. 
261  P_SYMLINKCOPY = u'copy' #: Copy symlink. 
262  P_SYMLINKCOPYNOEMUL = u'copynoemul' #: Copy symlink, no emulation. 
263  P_COMPARESTAT = u'stat' #: Compare by statistic. 
264  P_COMPARECRC32 = u'crc32' #: Compare by CRC32. 
265  P_BACKUPYES = u'1' #: Backup. 
266  P_BACKUPNO = u'0' #: No backup. 
267  P_SELECTDEFAULTYES = u'1' #: Select by default 
268  P_SELECTDEFAULTNO = u'0' #: Unselect by default 
269   
270  P_SYMLINK_IGNORE = (P_SYMLINKIGNORE, P_SYMLINKIGNORENOEMUL) # All ignores options. 
271  P_SYMLINK_EMUL = (P_SYMLINKIGNORE, P_SYMLINKCOPY) # All with emulation options. 
272   
273  # Default config properties constants. 
274   
275  z_symlink_choice = [P_SYMLINKIGNORE, P_SYMLINKIGNORENOEMUL, P_SYMLINKCOPY, 
276      P_SYMLINKCOPYNOEMUL] 
277   
278  z_compare_choice = [P_COMPARESTAT, P_COMPARECRC32] 
279   
280  P_DEFIGNORE = P_IGNORENONE #: Default ignores - No ignores. 
281  P_DEFSYMLINK = P_SYMLINKCOPY #: Default symlink action - Copy symlinks. 
282  P_DEFCOMPARE = P_COMPARESTAT #: Default compare method - Compare only by statistic. 
283  P_DEFBACKUP = P_BACKUPNO #: Default not backup root. 
284  P_DEFSELECTDEFAULT = P_SELECTDEFAULTNO #: Default not select for sync 
285   
286  DBESCAPE = u' %' 
287  """Escape symbols. DBESCESC and DBSEP is autoadded in start of secuence. 
288  Used in previous to 0.2.1 versions. Now used inline symbols =  space only. 
289  """ 
290   
291  DBESCESC = u'#' #: Escape symbol/prefix for hex value. 
292   
293  DBSEP = u'/' #: DB path separator. 
294   
295  P_MDDELTA = u'mddelta' 
296  MDDELTA_DEFAULT = u'5.0' 
297   
298  REPORTDIR_DEFAULT = u'bonhdyfwce' 
299  """Report direction filter default settings.""" 
300   
301  REPORTFORMAT_DEFAULT = u's' 
302  """Report format default.""" 
303   
304  REPORTPATT_DEFAULT = u'!.*' 
305  """Report pattern default.""" 
306   
307  REPORTTYPE_DEFAULT = u'1234' 
308  """Report type default.""" 
309   
310  REPORTPAGE_DEFAULT = u'0' 
311  """Report page size default.""" 
312   
313  REPORTFILTER_DEFAULT = REPORTFORMAT_DEFAULT + REPORTDIR_DEFAULT + REPORTTYPE_DEFAULT  
314  """Report filter default settings.""" 
315   
316   
317  O_REPORTFORMAT = {u'l':u'%(forced)s %(dir)s %(err)s [%(path)s]\n\t%(desc)s', 
318      u's':u'%(forced)s %(dir)s %(err)s [%(path)s]', 
319      u'p':u'\t[%(path)s]-->\n\t  == "%(desc)s".' 
320      } 
321  """Report formats option. 
322  - B{l} - Long format of report. 
323  - B{s} - Short format of report. 
324  - B{p} - Old (as in previous version) format. 
325  - B{m} - Manual specified format. 
326  - B{z00} - List report by I{n} items per page. 
327  """ 
328   
329  O_REPORTFILTER = {u'b':DBDIRBAG, u'o':DBDIRORIG, 
330      u'n': DBDIRNEW, u'h':DBDIRCOPY, 
331      u'd':DBDIRDELETE, u'y':DBDIRTS, u'i':DBDIRIGNORED, 
332      u'u':DBDIRUNCHANGED, u'f':DBDIRFORCED, 
333      u'w':DBDIRWARNING, 
334      u'c':DBDIRCONFLICT, u'e':DBDIRERROR 
335      } 
336  """Report filter options. 
337  - B{b} - Operation with direction to bag. 
338  - B{o} - Operation with direction to origin. 
339  - B{n} - Operation with new files. 
340  - B{h} - Operation with changed (copied) files. 
341  - B{d} - Operation with deleted files. 
342  - B{y} - Timeshift operations. 
343  - B{i} - Ignored files. 
344  - B{u} - Unchanged files. 
345  - B{f} - Forced action. 
346  - B{w} - Warnings. 
347  - B{c} - Conflicts. 
348  - B{e} - Errors. 
349  """ 
350   
351  O_REPORTTYPE = {u'1':u'f', 
352      u'2': u'd', 
353      u'3':u's', 
354      u'4': u'u' 
355      } 
356  """Report type options. 
357  - B{1} - Files. 
358  - B{2} - Directories. 
359  - B{3} - Symlinks. 
360  - B{4} - Unknown. 
361  - B{r} - Path wilds or regexp filter. If not specified then all paths displayed. 
362  """ 
363   
364  z_backupmode = {P_BACKUPNO:DBFORCEDIRBAGCOPY, P_BACKUPYES:DBFORCEDIRBAGALL} 
365  """Backup mode === direction.""" 
366   
367  O_ACTION = [u'bag', u'origin', u'delete', u'skip', u'restore', 
368      u'tsbag', u'tsorigin', u'tsreset'] 
369  """Available actions in cli menu.""" 
370   
371  O_K_LIST = [u'c', u'i', u'copy', u'ignore', u'cn', u'in', u'copynoemul', u'ignorenoemul'] 
372  O_K_DICT = {u'c':P_SYMLINKCOPY, u'copy':P_SYMLINKCOPY, 
373      u'i':P_SYMLINKIGNORE, u'ignore':P_SYMLINKIGNORE, 
374      u'cn':P_SYMLINKCOPYNOEMUL, u'copynoemul':P_SYMLINKCOPYNOEMUL, 
375      u'in':P_SYMLINKIGNORENOEMUL, u'ignorenoemul':P_SYMLINKIGNORENOEMUL} 
376   
377  O_S_LIST = [u'stat', u'crc32'] 
378  O_S_DICT ={u'stat':P_COMPARESTAT, u'crc32':P_COMPARECRC32} 
379   
380  z_db_formatlist =[ 
381      (DBBAGFLAG,unicode,DBFLAGNONE,u'DBBAGFLAG'), 
382      (DBBAGSIZE,int,DBNONE,u'DBBAGSIZE'), 
383      (DBBAGMDATE,float,DBMDATENONE,u'DBBAGMDATE'), 
384      (DBBAGCRC32,int,DBNONE,u'DBBAGCRC32'), 
385      (DBBAGREAD,bool,DBREADNONE,u'DBBAGREAD'), 
386      (DBBAGPATH,unicode,DBPATHNONE,u'DBBAGPATH'), 
387      (DBBAGLINK,unicode,DBLINKNONE,u'DBBAGLINK'), 
388      (DBDBFLAG,unicode,DBFLAGNONE,u'DBDBFLAG'), 
389      (DBDBSIZE,int,DBNONE,u'DBDBSIZE'), 
390      (DBDBMDATE,float,DBMDATENONE,u'DBDBMDATE'), 
391      (DBDBCRC32,int,DBNONE,u'DBDBCRC32'), 
392      (DBDBREAD,bool,DBREADNONE,u'DBDBREAD'), 
393      (DBDBPATH,unicode,DBPATHNONE,u'DBDBPATH'), 
394      (DBDBLINK,unicode,DBLINKNONE,u'DBDBLINK'), 
395      (DBORIGFLAG,unicode,DBFLAGNONE,u'DBORIGFLAG'), 
396      (DBORIGSIZE,int,DBNONE,u'DBORIGSIZE'), 
397      (DBORIGMDATE,float,DBMDATENONE,u'DBORIGMDATE'), 
398      (DBORIGCRC32,int,DBNONE,u'DBORIGCRC32'), 
399      (DBORIGREAD,bool,DBREADNONE,u'DBORIGREAD'), 
400      (DBORIGPATH,unicode,DBPATHNONE,u'DBORIGPATH'), 
401      (DBORIGLINK,unicode,DBLINKNONE,u'DBORIGLINK'), 
402      (DBDIR,int,DBNONE,u'DBDIR'), 
403      (DBSYNC,int,DBNONE,u'DBSYNC'), 
404      (DBCOMPARE,unicode,P_DEFCOMPARE,u'DBCOMPARE'), 
405      (DBSYMLINK,unicode,P_DEFSYMLINK,u'DBSYMLINK'), 
406      (DBDESC,unicode,DBDESCNONE,u'DBDESC'), 
407      (DBDIRMAN,int,DBNONE,u'DBDIRMAN'), 
408      (DBDESCMAN,unicode,DBDESCMANNONE,u'DBDESCMAN'), 
409      (DBITEMID,int,DBITEMNONE,u'DBITEMID'), 
410      (DBDIRREADED,int,DBNONE,u'DBDIRREADED'), 
411      (DBDESCREADED,unicode,DBDESCNONE,u'DBDESCREADED'), 
412      (DBSYMLINKEMUL,bool,DBSYMEMULNONE,u'DBSYMLINKEMUL'), 
413      (DBBACKUP,bool,DBBACKUPNO,u'DBBACKUP'), 
414      ] #: Format list of tuples (index, type, default) for database. 
415