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

Source Code for Module cfg

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  #-------------------------------------------------------------------- 
  4  # Filename: cfg.py 
  5  # Author: Mazhugin Aleksey 
  6  # Created: 2019/07/25 
  7  # ID: $Id: cfg.py 63 2019-09-09 15:31:40Z Aleksey $ 
  8  # URL: $URL: file:///D:/svn_/pybag/trunc/src/cfg.py $ 
  9  # Copyright: Copyright (c) 2019, Mazhugin Aleksey. 
 10  # License: BSD 
 11  #-------------------------------------------------------------------- 
 12   
 13   
 14  """ 
 15  Global configuration variables. 
 16  """ 
 17   
 18  #__docformat__ = "restructuredtext" # "epytext" 
 19   
 20   
 21  import os, platform, re 
 22  import threading 
 23   
 24  from const import TSDIRNONE, MDDELTA_DEFAULT, REPORTFORMAT_DEFAULT,\ 
 25      REPORTPATT_DEFAULT, REPORTTYPE_DEFAULT, REPORTPAGE_DEFAULT,\ 
 26      REPORTFILTER_DEFAULT, LI_LENGTH, LI_CANCEL, LI_PERCENT, LI_PERCENT100,\ 
 27      LI_PERCENTGLOBAL, LI_PERCENTPART, LI_DESC, LI_FUN2, LI_UPDATEFILTER,\ 
 28      LI_FILTERRUNNING, LI_THREAD 
 29   
 30   
 31  arguments = None #: Arguments == sys.argv 
 32   
 33  z_epdl = None 
 34  z_epde = None 
 35  z_epse = None 
 36  Z_INEP = None 
 37  z_outep = None 
 38   
 39   
 40   
 41  Z_APP = None #: Application. 
 42   
 43  Z_GUI = None #: GUI top frame. 
 44   
 45  ISGUI = False #: True if GUI used. 
 46   
 47  PYBAG_COLORIZE = True #: Colorize console output (default True). 
 48   
 49  PYBAG_DEBUG = False #: Debug mode. If True (default False) then out all debug messages. Prepend to message "-->" string. 
 50   
 51  PYBAG_LOG = True #: Logging mode. If True (by default) then out all log messages. Prepend to message "#" string. 
 52   
 53  PYBAG_EMUL = True #: Emulation mode. If True (by default) then do not real changes (emulation mode). 
 54   
 55   
 56  TSBAG = 0 #: Timeshift for bag. 
 57  TSORIG = 0 #: Timeshift for origin. 
 58  TSDIR = TSDIRNONE #: Timeshift direction 
 59   
 60  VERBOSE = 3 #: Verbosity level. 
 61   
 62  BACKUPMODE = False #: Backup mode in synchronization, normal. 
 63       
 64  TIMEFORMAT = u'%Y-%m-%d %H:%M:%S' 
 65   
 66  IMGINDEX = {} #: Image list index for GUI 
 67   
 68  WRITECOLSATEXIT = False #: If true - write gui columns at exit in config. 
 69   
 70  SHOWTIPS = 0 #: If true then show tips at start up. 
 71  TIPSNUMBER = 0 #: Next tips index for show. 
 72   
 73   
 74   
 75   
 76  Z_LISTKS = [] #: Temporary keys when update list filter. 
 77   
 78  IsDBReaded = False #: Flag marked if DB readed. 
 79               
 80  IsDBCompared = False #: Flag marked if DB compared. 
 81   
 82  IsDBSynced = False #: Flag marked if DB synchronized. 
 83               
 84   
 85  # Columns in default order [(configname, colname, show, size, align), ...] 
 86  Z_COLUMN_CHOISE_DEFAULT = [] 
 87  """Columns in default order for GUI list.""" 
 88   
 89  Z_COLUMN_CHOISE = [] 
 90  """Columns.""" 
 91   
 92   
 93   
 94  MDDELTA = MDDELTA_DEFAULT #: Modify time available difference for equality. Default is 5.0 second. 
 95   
 96  REPORTFORMAT = REPORTFORMAT_DEFAULT 
 97  """Report format, short by default.""" 
 98   
 99  REPORTPATT = REPORTPATT_DEFAULT 
100  """Report wilds or RegExp filter for paths.""" 
101   
102  REPORTPATTCMP = None 
103  """Compiled report pattern.""" 
104   
105   
106   
107  REPORTTYPE = REPORTTYPE_DEFAULT 
108  """Report type, all by default.""" 
109   
110   
111   
112  REPORTPAGE = REPORTPAGE_DEFAULT 
113  """Report page size in items, unlimit by default.""" 
114   
115   
116   
117  REPORTFILTER = REPORTFILTER_DEFAULT 
118  """Report filter settings.""" 
119   
120  # Options parameter list and dictionaries. 
121   
122  REPORTSHOW = True 
123   
124   
125  ##u't':DBDIRNOTFORCED, 
126   
127   
128   
129  SYMLINKEMUL = True 
130  """If True then used symlink emulation if no native support. 
131  Used as default parameter in symlink functions (L{cli.symlink}, L{cli.readlink}, L{cli.symlinktest}).""" 
132   
133  OSSEP = os.sep #: Os path separator. 
134   
135  OSASEP = os.altsep #: Alternative os path separator. 
136   
137  OSWIN = platform.system().lower().startswith('windows') 
138   
139  fstream = None #: Output log stream. 
140   
141  Z_CP = None #: ConfigParser instance. 
142   
143  Z_DB = {} #: Database. 
144   
145  Z_KS = [] #: List of sorted in ascending order L{Z_DB} keys. 
146   
147  z_re_rootsec=re.compile(ur'(r\d+)') #: RegExp for root options names. 
148   
149   
150 -class lock_list(object):
151 """ 152 Class target for easy multithreading access to variables (in list). 153 154 You create instance of this class and can from any thread easy access to 155 you variables by index (as in dictionary). 156 Example:: 157 LOCK = lock_list(10) 158 LOCK[3] = False 159 val = LOCK[3] 160 161 All I{get}, I{set} and I{del} for index key will be auto locked. 162 163 @note: Safe for multithreading. 164 """ 165
166 - def __init__(self, length):
167 """ 168 Initialize instance. 169 """ 170 self._lock = threading.Lock() 171 self._attrs = range(length)
172
173 - def __getitem__(self, key):
174 """ 175 Return value for index. 176 If no such key then raise IndexError. 177 """ 178 self._lock.acquire() 179 try: 180 return self._attrs[key] 181 finally: 182 self._lock.release()
183
184 - def __setitem__(self, key, val):
185 """ 186 Set value for index. 187 """ 188 self._lock.acquire() 189 try: 190 self._attrs[key] = val 191 finally: 192 self._lock.release()
193
194 - def __delitem__(self, key):
195 """ 196 Delete index key. 197 If no such key then raise IndexError. 198 199 @raise IndexError: Index error. 200 """ 201 self._lock.acquire() 202 try: 203 del self._attrs[key] 204 finally: 205 self._lock.release()
206 ##end lock_list 207 208 LOCK = lock_list(LI_LENGTH) #: Initialize LOCK instance. It used in multithreading 209 # and must be locked then accessed. 210 211 212 LOCK[LI_CANCEL] = False 213 LOCK[LI_PERCENT] = 0 214 LOCK[LI_PERCENT100] = 100 215 LOCK[LI_PERCENTGLOBAL] = 100 216 LOCK[LI_PERCENTPART] = 0 217 LOCK[LI_DESC] = u'Operation description' 218 LOCK[LI_FUN2] = False 219 LOCK[LI_UPDATEFILTER] = False 220 LOCK[LI_FILTERRUNNING] = False 221 LOCK[LI_THREAD] = False 222