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

Module cli

source code

PYBAG - Crossplatform files synchronization and backup portable tools.


Version: 0.5.0

Author: Mazhugin Aleksey

Copyright: Copyright (c) 2019, Mazhugin Aleksey.

License: Copyright (c) 2007 ... 2019, Mazhugin Aleksey All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Mazhugin Aleksey nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Classes [hide private]
  command_class
  z_gp_class
Global preferences saver class.
  z_r
Class for result return from commands.
Functions [hide private]
 
init_dirs()
Initialize directories.
source code
 
cmd_gui(cmd)
Start GUI.
source code
 
command(cmd)
Start command interface.
source code
Class object or bool.
parse_command()
Start command parser.
source code
bool
test_init()
Test if programm location already initialized.
source code
bool
init_program()
Initialize program environment.
source code
bool
initpath(path)
Initialize bag in path.
source code
bool
initdb(path, db={})
Initialize database file in specified path.
source code
bool
initconfig(path)
Initialize configuration file in specified path.
source code
bool
initpybagfiles(path)
Initialize pybagfiles directory in specified path.
source code
 
deinit_program()
Deinitialize program structures and close opened files.
source code
str
transreport(opt=None)
Translate report option -g into global variables.
source code
dict
dbread(path=None)
Read database file pybag.db (gzipped).
source code
 
dbsave(dbdict, path=None, patht=None)
Save database to file.
source code
 
dbdumprow(dbrow, tab=u' ....->')
Dump DB row to string.
source code
 
dbdump(db, tab=u'DBDUMP:')
Dump DB to string.
source code
 
dbnormalize(db)
Normalize DB - convert values to right type and past default if absent.
source code
list
splitpaths(path)
Return list of path's parts.
source code
 
splitpathsdb(path)
See splitpaths.
source code
 
getpathdirdb(path)
For DB format paths return parent directory for given path.
source code
 
dbstartswith(dbpath, idx)
Test if dbpath starts with idx.
source code
 
path2db(path)
Convert path to DB format (separate by DBSEP).
source code
 
path2os(path)
Convert path to OS format from DB.
source code
 
walk(path, onerror=None)
Top-down directory walker.
source code
 
symlinktest(path, useemul=None)
Test file for symlink emulation or real.
source code
 
readlink(path, useemul=None)
Read symbolic link point.
source code
 
symlink(link, path, useemul=None)
Save symbolic link point.
source code
 
rmdirr(path)
Delete directory recursively.
source code
 
copytree(src, dst, symlinks=False, exclude=[])
Copy files tree from "src" to "dst".
source code
list or None
validatepaths(root, bagpath=None, syncpath=None)
Validate paths.
source code
 
getcrc32(path)
Calculate CRC32 for given file.
source code
tuple
dbwalkfiles(db, root, path, isbag, dbindex)
Walk throw bagpath files from pybagfiles and syncpath for original files.
source code
str
transopt(opt, cmd)
Translate option in command.
source code
 
cmd_(cmd)
No command, only option.
source code
 
cmd_unknown(cmd)
Unknown command.
source code
 
f_stat(cmd)
Show info about bag files.
source code
 
f_dist(cmd)
Distribute PYBAG program to specified location.
source code
 
cmd_dist(cmd)
Distribute PYBAG program to specified location.
source code
 
cmd_stat(cmd)
Show statistic about bag files.
source code
 
f_usage(cmd) source code
 
cmd_usage(cmd)
Print usage information.
source code
 
cmd_version(cmd)
Show version.
source code
 
cmd_author(cmd)
Show author.
source code
 
cmd_license(cmd)
Show license.
source code
 
cmd_copyright(cmd)
Show copyright.
source code
 
cmd_about(cmd)
Show about.
source code
 
f_help(cmd) source code
 
cmd_help(cmd)
Print usage information.
source code
 
cmd_add(cmd) source code
 
f_add(cmd) source code
 
cmd_remove(cmd)
Remove roots from bag.
source code
 
cmd_cleandb(cmd)
Remove not exists paths/roots from DB.
source code
 
cmd_relocate(cmd)
Relocate specified root (change its origin into configuration file).
source code
 
outreport(db=None, ks=None)
Output comparison report from database db in console.
source code
stirng.
do_action(action, _filter, interactive=True, listpaths=True)
Perform changes into db[DBDIR] to specified action.
source code
 
cmd_sync(cmd)
Synchronize files.
source code
bool
f_syncread(cmd)
Read DB, files.
source code
 
f_synccompare(direction)
Compare DB.
source code
 
f_syncsync()
Syncronize DB.
source code
 
f_syncclear()
Clear DB.
source code
 
main()
Main function.
source code
 
_debug()
Debug function.
source code
 
_test_debugTrue()
Only for test
source code
 
__test_debugFalse()
Only for test
source code
 
_test_gp_class() source code
 
_test_dbnormalize() source code
 
_test_splitpaths() source code
 
_test_dbread() source code
 
_test_findroot() source code
 
_test_validatepaths() source code
 
_test_dbwalkfiles() source code
 
_test_transopt() source code
 
_test_path2db() source code
 
_test_path2os() source code
 
_test_readlink() source code
 
_test_symlink() source code
 
_test_getcrc32() source code
 
_test_transreport() source code
 
mainstart() source code
Variables [hide private]
  climenu = ...
Menu for display in command line version in synchronization.
  climenuhelp = ...
Menu help for display in command line version in synchronization.
  pagemenu = ...
  dir_root = u''
Current path to pybag location (folder).
  dir_files = u''
Files folder.
  dir_db = u''
Data base file path.
  dir_dbt = u''
Data base temp file path.
  dir_cfg = u''
Configuration file path.
  dir_cfgt = u''
Configuration temp file path.
  stdout_wrapper = termcolors.StreamProxy(None, True)
  BACKUPDIR = 16
  COL_FORMAT = 4
  COL_HEADING = 1
  COL_NAME = 0
  COL_VISIBLE = 2
  COL_WIDTH = 3
  CRC32BUF = 1048575
  DBBACKUP = 27
  DBBACKUPNO = False
  DBBACKUPYES = True
  DBBAGCRC32 = 104
  DBBAGFLAG = 101
  DBBAGLINK = 107
  DBBAGMDATE = 103
  DBBAGPATH = 106
  DBBAGREAD = 105
  DBBAGSIZE = 102
  DBCOMPARE = 18
  DBDBCRC32 = 304
  DBDBFLAG = 301
  DBDBLINK = 307
  DBDBMDATE = 303
  DBDBPATH = 306
  DBDBREAD = 305
  DBDBSIZE = 302
  DBDESC = 20
  DBDESCMAN = 22
  DBDESCMANNONE = u''
  DBDESCNONE = u'Not compared.'
  DBDESCOK = u'Ok.'
  DBDESCREADED = 25
  DBDIR = 15
  DBDIRBAG = 1
  DBDIRCONFLICT = 64
  DBDIRCOPY = 8
  DBDIRDB = 4
  DBDIRDELETE = 16
  DBDIRDIFF = 4096
  DBDIRERROR = 128
  DBDIRFORCED = 1024
  DBDIRIGNORED = 2048
  DBDIRMAN = 21
  DBDIRNEW = 256
  DBDIRNONE = 0
  DBDIROK = 8192
  DBDIRORIG = 2
  DBDIRREADED = 24
  DBDIRRESTORE = 16384
  DBDIRTS = 32768
  DBDIRUNCHANGED = 512
  DBDIRWARNING = 32
  DBDUMPMAX = 500
  DBESCAPE = u' %'
  DBESCESC = u'#'
  DBFLAGDIR = u'd'
  DBFLAGFILE = u'f'
  DBFLAGNONE = u''
  DBFLAGSYMLINK = u's'
  DBFLAGUNKNOWN = u'u'
  DBFORCEDIRBAG = 1
  DBFORCEDIRBAGALL = 16
  DBFORCEDIRBAGCOPY = 128
  DBFORCEDIRNEWER = 8
  DBFORCEDIRNONE = 0
  DBFORCEDIROLDER = 4
  DBFORCEDIRORIGIN = 2
  DBFORCEDIRORIGINALL = 32
  DBFORCEDIRORIGINCOPY = 64
  DBITEMID = 23
  DBITEMNONE = None
  DBLINKNONE = u'-'
  DBMDATENONE = 0.0
  DBNONE = 0
  DBORIGCRC32 = 204
  DBORIGFLAG = 201
  DBORIGLINK = 207
  DBORIGMDATE = 203
  DBORIGPATH = 206
  DBORIGREAD = 205
  DBORIGSIZE = 202
  DBPATH = 0
  DBPATHNONE = u''
  DBREADNONE = False
  DBREADYES = True
  DBSEP = u'/'
  DBSYMEMULNONE = False
  DBSYMLINK = 19
  DBSYMLINKEMUL = 26
  DBSYNC = 17
  DBSYNCCOMPARE = 128
  DBSYNCCONFLICT = 512
  DBSYNCERRCOMPARE = 64
  DBSYNCERROR = 111
  DBSYNCERROTHER = 32
  DBSYNCERRREAD = 3
  DBSYNCERRREADBAG = 1
  DBSYNCERRREADSYNC = 2
  DBSYNCERRWRITE = 12
  DBSYNCERRWRITEBAG = 4
  DBSYNCERRWRITESYNC = 8
  DBSYNCIGNORED = 256
  DBSYNCNONE = 0
  DBSYNCOK = 16
  IBAG = 100
  ICRC32 = 4
  IDB = 300
  IFLAG = 1
  ILINK = 7
  IMDATE = 3
  IPATH = 6
  IREAD = 5
  ISIZE = 2
  ISYNC = 200
  LI_CANCEL = 0
  LI_DESC = 4
  LI_ERROR = 1
  LI_FILTERRUNNING = 9
  LI_FUN2 = 7
  LI_LENGTH = 11
  LI_PERCENT = 2
  LI_PERCENT100 = 3
  LI_PERCENTGLOBAL = 6
  LI_PERCENTPART = 5
  LI_THREAD = 10
  LI_UPDATEFILTER = 8
  LOOPN = 10000
  MDDELTA_DEFAULT = u'5.0'
  O_ACTION = [u'bag', u'origin', u'delete', u'skip', u'restore',...
  O_K_DICT = {u'c': u'copy', u'cn': u'copynoemul', u'copy': u'co...
  O_K_LIST = [u'c', u'i', u'copy', u'ignore', u'cn', u'in', u'co...
  O_REPORTFILTER = {u'b': 1, u'c': 64, u'd': 16, u'e': 128, u'f'...
  O_REPORTFORMAT = {u'l': u'%(forced)s %(dir)s %(err)s [%(path...
  O_REPORTTYPE = {u'1': u'f', u'2': u'd', u'3': u's', u'4': u'u'}
  O_S_DICT = {u'crc32': u'crc32', u'stat': u'stat'}
  O_S_LIST = [u'stat', u'crc32']
  PYBAG_COLORIZE_DEFAULT = u'1'
  PYBAG_DEBUG_DEFAULT = u'0'
  PYBAG_EMUL_DEFAULT = u'1'
  PYBAG_LOG_DEFAULT = u'1'
  P_BACKUP = u'backup'
  P_BACKUPNO = u'0'
  P_BACKUPYES = u'1'
  P_COLORIZE = u'colorize'
  P_COMPARE = u'compare'
  P_COMPARECRC32 = u'crc32'
  P_COMPARESTAT = u'stat'
  P_DEBUG = u'debug'
  P_DEFBACKUP = u'0'
  P_DEFCOMPARE = u'stat'
  P_DEFIGNORE = u''
  P_DEFSELECTDEFAULT = u'0'
  P_DEFSYMLINK = u'copy'
  P_EMUL = u'emulation'
  P_GUI = u'GUI'
  P_IGNORE = u'ignore'
  P_IGNORENONE = u''
  P_LOGGING = u'logging'
  P_MDDELTA = u'mddelta'
  P_OUTFILTER = u'outfilter'
  P_OUTPUT = u'output'
  P_SELECTDEFAULT = u'selectdefault'
  P_SELECTDEFAULTNO = u'0'
  P_SELECTDEFAULTYES = u'1'
  P_SHOWTIPS = u'showtips'
  P_SYMLINK = u'symlink'
  P_SYMLINKCOPY = u'copy'
  P_SYMLINKCOPYNOEMUL = u'copynoemul'
  P_SYMLINKIGNORE = u'ignore'
  P_SYMLINKIGNORENOEMUL = u'ignorenoemul'
  P_SYMLINK_EMUL = (u'ignore', u'copy')
  P_SYMLINK_IGNORE = (u'ignore', u'ignorenoemul')
  P_TIPSNUMBER = u'tipsnumber'
  P_VERB = u'verbosity'
  P_WRITECOLSATEXIT = u'writecolsatexit'
  REPORTDIR_DEFAULT = u'bonhdyfwce'
  REPORTFILTER_DEFAULT = u'sbonhdyfwce1234'
  REPORTFORMAT_DEFAULT = u's'
  REPORTPAGE_DEFAULT = u'0'
  REPORTPATT_DEFAULT = u'!.*'
  REPORTTYPE_DEFAULT = u'1234'
  TSDIRBAG = 1
  TSDIRNONE = 0
  TSDIRORIG = 2
  VERBOSE_DEFAULT = u'3'
  Z_DBFORCE = {u'bag': 1, u'bagall': 16, u'bagcopy': 128, u'newe...
  __package__ = None
  z_action_choise = [(u'No', 0), (u'To bag', 1), (u'To origin', ...
  z_backupmode = {u'0': 128, u'1': 16}
  z_compare_choice = [u'stat', u'crc32']
  z_db_formatlist = [(101, <type 'unicode'>, u'', u'DBBAGFLAG'),...
  z_db_marker = u'PYBAG DB version = '
  z_db_marker_len = 19
  z_db_version = u'0.2'
  z_pble = u':pybaglink end'
  z_pblmaxlen = 4096
  z_pbls = u'pybaglink start:'
  z_symlink_choice = [u'ignore', u'ignorenoemul', u'copy', u'cop...

Imports: shutil, sys, time, getopt, atexit, ConfigParser, gzip, binascii, traceback, codecs, os, re, cfg, log, prt0, prt1, prt2, prt3, prt4, prt5, dbg, z_u, prt, log_clear, init_encoding, __header__, _usage, __about__, termcolors


Function Details [hide private]

parse_command()

source code 

Start command parser.

Returns: Class object or bool.
Object ret if OK, else False. ret contains next attributes:
  • cmd - command name, str.
  • fs - files list, list.
  • option name - (option, values), list.

test_init()

source code 

Test if programm location already initialized.

Returns: bool
True if initialized.

init_program()

source code 

Initialize program environment.

Test current program location for initialization. Ask user for initialization if need and initialize if user agree. In initialization time (if user agree) set emulation off. After return it in previous state. Create needed files and folders if it not exist. Read configuration file.

Returns: bool
True if initialization successful, otherwise False.

initpath(path)

source code 

Initialize bag in path. Create path if need. Do not change already exists files.

Parameters:
  • path (str) - Path to initialize bag.
Returns: bool
True if successfull or False otherwise.

initdb(path, db={})

source code 

Initialize database file in specified path. If not exists then create DB == db (by default is empty DB).

Parameters:
  • path (str) - Path to initialize DB.
  • db (dict = {}) - DB for initializing.
Returns: bool
True if successfull, False overwise.

initconfig(path)

source code 

Initialize configuration file in specified path.

If not exists then create next configuration file:

   # PYBAG configuraton file.
   
   [root]
   
   nextid = 1
   ignore =
   compare = stat
   symlink = copy
   colorize = 1
   
   # Subroots sections.
Parameters:
  • path (str) - Path to initialize configuration file.
Returns: bool
True if successfull, False overwise.

initpybagfiles(path)

source code 

Initialize pybagfiles directory in specified path.

If not exists then create empty directory "pybagfiles".

Parameters:
  • path (str) - Path to initialize pybagfiles directory.
Returns: bool
True if successfull, False overwise.

transreport(opt=None)

source code 

Translate report option -g into global variables.

Parameters:
  • opt (str) - Option value.
Returns: str
u'' - empty string if all OK. Error string otherwise.

dbread(path=None)

source code 

Read database file pybag.db (gzipped). If errors occurs then setup z_r.e to error message. In DB files placed in next format:

  • DB_VERSION_MARKER DB_VERSION
  • F SIZE MDATE CRC32 path_to_file1_in_pybagfiles link_point1
  • F SIZE MDATE CRC32 path_to_file2_in_pybagfiles link_point2
  • ... and so on.

All lines must end with newline.:

  • "F" - flag: d-directory, f-file, s-symlink, ''-is empty entry.
  • "SIZE" - file size in decimal or "-" for directories.
  • "MDATE" - modification date in YYYY/MM/DD-HH:mm:ss.
  • "CRC32" - crc32 in hex if exist or "-".
  • "path_to_file" - bag path to item into pybagfiles id "db" format.
  • "link_point" - if item link then it's point in "db" format, otherwise '-'.

All lines must end with newline. Read only DB information.

Parameters:
  • path (str = None) - Path from reading DB. If None then use dir_db.
Returns: dict
DB dictionary. In z_r return output and errors. In returned dbdictionary key is normalized/cased path (relative to pybag), value is dict of next items (see in pybag description).

dbsave(dbdict, path=None, patht=None)

source code 

Save database to file. If errors occurs hen setup z_r.e to error message. In DB files placed in next format:

  • DB_VERSION_MARKER DB_VERSION
  • F SIZE MDATE CRC32 path_to_file1_in_pybagfiles link_point1
  • F SIZE MDATE CRC32 path_to_file2_in_pybagfiles link_point2
  • ... and so on.

For details format see dbread.

Parameters:
  • path (str = None) - Path from save DB. If None then use dir_db.
  • patht (str = None) - Path from save backup DB. If None then use "path"+"~".
  • dbdict (dict) - DB dictionary. See dbread for details.

dbdumprow(dbrow, tab=u' ....->')

source code 

Dump DB row to string. Dump only items from z_db_formatlist.

dbdump(db, tab=u'DBDUMP:')

source code 

Dump DB to string. Dump only items from z_db_formatlist.

dbnormalize(db)

source code 

Normalize DB - convert values to right type and past default if absent. If no such index or wrong values or type then create and set to default.

Returns:
Output and errors in z_r and changed input db.

splitpaths(path)

source code 

Return list of path's parts.

Parameters:
  • path (str) - Path.
Returns: list
List of splited parts of path. If path empty then empty list.

Warning: Normalize path before splitting. See os.path.normpath().

splitpathsdb(path)

source code 

See splitpaths. Used for DB format paths.

getpathdirdb(path)

source code 

For DB format paths return parent directory for given path. If no parent return empty string u''.

path2db(path)

source code 

Convert path to DB format (separate by DBSEP).

Warning: Path started from root "/" converted wrongly - "/" character changed to os separator. For example "/abc/def.ghi" converted to "\/abc/def.ghi" under Windows and "#002F/abc/def.ghi" under unix.

walk(path, onerror=None)

source code 

Top-down directory walker. return in iterate (r,d,f), as python standard os.walk. Note: Default python os.walk some times generate error in mixing encodings in file names ... may be it bug?

symlinktest(path, useemul=None)

source code 

Test file for symlink emulation or real. Return True if symlink, False overwise.

Parameters:
  • useemul (bool) - If true then use symlink emulation if no native support.

readlink(path, useemul=None)

source code 

Read symbolic link point. Use native function if support or emulate. If filesystem not support link then also emulate it.

Emulate file format is: "pybaglink start:xxxxxxxxxx:pybaglink end". File encoding is "utf_8".

Parameters:
  • useemul (bool) - If true then use symlink emulation if no native support.
Raises:
  • IOError - if error then read link.

symlink(link, path, useemul=None)

source code 

Save symbolic link point. Use native function if support or emulate. If filesystem not support link then also emulate it. Before create new link you must remove previous.

Emulate file format is: "pybaglink start:xxxxxxxxxx:pybaglink end". File encoding is "utf_8".

Parameters:
  • useemul (bool) - If true then use symlink emulation if no native support.
Raises:
  • IOError - if error then save link.

rmdirr(path)

source code 

Delete directory recursively. Delete everything reachable from the directory named in 'path', (do not follow for symbolic link).

Warning: This is dangerous! For example, if path == '/home', it could delete all your home files.

!!! ROOT FOLDERS ('/' and 'C:') CAN NOT BE DELETED THIS FUNCTION!!!

If you want delete root folder you must delete it manualy.

copytree(src, dst, symlinks=False, exclude=[])

source code 

Copy files tree from "src" to "dst". "dst" must be a directory. If "symlinks" True then also copy symlinks (default False). If symlinks not supported then they emulated. If "dst" not exists then create it. From copying exluded items equal "exclude" list.

validatepaths(root, bagpath=None, syncpath=None)

source code 

Validate paths.

Parameters:
  • root (str) - Root (r1, r2, ...).
  • bagpath (str { = None }) - Root path in pybag. If None then get from root config.
  • syncpath (str { = None }) - Syncronization path. If empty then used base (config) path.
Returns: list or None
list [root, bagpath, syncpath, dbindex] or None if path wrong. All path returned in absolute form, dbindex is normalized.

getcrc32(path)

source code 

Calculate CRC32 for given file. Return 0 for other situation (directory, link, absent).

dbwalkfiles(db, root, path, isbag, dbindex)

source code 

Walk throw bagpath files from pybagfiles and syncpath for original files.

Parameters:
  • db (dict) - Database dictionary.
  • root (str) - Root name for read configuration.
  • path (str) - Absolut path for walking. Path must exists.
  • dbindex (str) - Index into DB equivalent path.
  • isbag (bool) - True if walk throw bag, False for origin.
Returns: tuple
(success, ignored) tuple and changed input db:
  • success - bool, True if Ok, False if error or path not exists.
  • ignored - int, number of ignored items.
Raises:
  • ValueError - Raise if path is not absolut.

Warning: path must be in absolute normalized format and must exists. Usually this function get arguments that returned by validatepaths.

transopt(opt, cmd)

source code 

Translate option in command. Get from "cmd" list "cmd.x" where x - is "opt". Get value from dictionary O_X_DICT[O_X_LIST[cmd.x[-1]]]. If no "cmd.x" then return O_X_DICT[O_X_LIST[0]]. If not supported option then return empty string ''.

Parameters:
  • opt (str) - Option symbol: 'k', 's'.
  • cmd (object) - Command object.
Returns: str
Translated option value or empty string.

cmd_unknown(cmd)

source code 

Unknown command. Print message about unknown command.

f_stat(cmd)

source code 

Show info about bag files.

Returns:
String with statistics.

outreport(db=None, ks=None)

source code 

Output comparison report from database db in console.

Filter output

do_action(action, _filter, interactive=True, listpaths=True)

source code 

Perform changes into db[DBDIR] to specified action.

Parameters:
  • action (basestr) - Action string O_ACTION.
  • _filter (string.) - Filter string, "wilds" or "!regexp". If not specified then used "!.*" - match all paths.
  • interactive (bool) - If True then ask from user confirmation.
  • listpaths (bool) - If True then list all affected paths.
Returns: stirng.
String with error or empty string if all ok.

cmd_sync(cmd)

source code 

Synchronize files.

Algorithm:

  • Test for attributes.
  • Append paths to lists.
  • dbread.
  • Loop for all paths:
    • dbwalkfiles.
  • dbcomparefiles.
  • dbsyncfiles.
  • dbcleardb
  • Print results.
  • Save DB.

f_syncread(cmd)

source code 

Read DB, files.

Returns: bool
Number of ignores. Result in z_r.

f_synccompare(direction)

source code 

Compare DB.

Return tuple of number modified items.

Parameters:
  • direction (int { DBFORCEDIR*** constants }) - Forced direction in conflicts.

Warning: All paths (BAG, Origin) must be filled. And DB must be normalized.

f_syncsync()

source code 

Syncronize DB.

Return tuple of modified and errored items.

f_syncclear()

source code 

Clear DB. Remove from DB unused record (successfully deleted and ignored items).

_debug()

source code 

Debug function.

Test functions.


Variables Details [hide private]

climenu

Menu for display in command line version in synchronization.

Value:
u'''
Enter action (h - for help):

'''

climenuhelp

Menu help for display in command line version in synchronization.

Value:
u'''
<g>Menu help:</g>
<g>-------------</g>
    <y>d DIR DIR</y> - change rules for autoconflict resolution
        (after change direction comparison will be repeated,
        and menu displayed again). DIR is next:
        [<c>bag</c>, <c>origin</c>, <c>no</c>, <c>newer</c>, <c>older<\
/c>, <c>bagall</c>, <c>originall</c>,
...

pagemenu

Value:
u'''
<y>ENTER</y> - next page,  "<y>NUMBER</y>" - page size, "<y>q</y>" - q\
uit report, "<y>a</y>" - list all.
'''

O_ACTION

Value:
[u'bag',
 u'origin',
 u'delete',
 u'skip',
 u'restore',
 u'tsbag',
 u'tsorigin',
 u'tsreset']

O_K_DICT

Value:
{u'c': u'copy',
 u'cn': u'copynoemul',
 u'copy': u'copy',
 u'copynoemul': u'copynoemul',
 u'i': u'ignore',
 u'ignore': u'ignore',
 u'ignorenoemul': u'ignorenoemul',
 u'in': u'ignorenoemul'}

O_K_LIST

Value:
[u'c',
 u'i',
 u'copy',
 u'ignore',
 u'cn',
 u'in',
 u'copynoemul',
 u'ignorenoemul']

O_REPORTFILTER

Value:
{u'b': 1,
 u'c': 64,
 u'd': 16,
 u'e': 128,
 u'f': 1024,
 u'h': 8,
 u'i': 2048,
 u'n': 256,
...

O_REPORTFORMAT

Value:
{u'l': u'''%(forced)s %(dir)s %(err)s [%(path)s]
	%(desc)s''',
 u'p': u'''	[%(path)s]-->
	  == "%(desc)s".''',
 u's': u'%(forced)s %(dir)s %(err)s [%(path)s]'}

Z_DBFORCE

Value:
{u'bag': 1,
 u'bagall': 16,
 u'bagcopy': 128,
 u'newer': 8,
 u'no': 0,
 u'older': 4,
 u'origin': 2,
 u'originall': 32,
...

z_action_choise

Value:
[(u'No', 0),
 (u'To bag', 1),
 (u'To origin', 2),
 (u'Newer', 8),
 (u'Older', 4),
 (u'Newer, to bag', 9),
 (u'Newer, to origin', 10),
 (u'Older, to bag', 5),
...

z_db_formatlist

Value:
[(101, <type 'unicode'>, u'', u'DBBAGFLAG'),
 (102, <type 'int'>, 0, u'DBBAGSIZE'),
 (103, <type 'float'>, 0.0, u'DBBAGMDATE'),
 (104, <type 'int'>, 0, u'DBBAGCRC32'),
 (105, <type 'bool'>, False, u'DBBAGREAD'),
 (106, <type 'unicode'>, u'', u'DBBAGPATH'),
 (107, <type 'unicode'>, u'-', u'DBBAGLINK'),
 (301, <type 'unicode'>, u'', u'DBDBFLAG'),
...

z_symlink_choice

Value:
[u'ignore', u'ignorenoemul', u'copy', u'copynoemul']