• Select language EN RU

PYBAG command line interface

Commands and options

Command line:

pybag.py --command -option1 -option2 argument1 argument2 ...

Warning

At once may be executed only one command.

Note

Use emulation mode -m1 (default is on) before real files operation (exclude --dist). For real operation you need use option -m0.

Commands

Without commands and options run GUI interface (as --gui command).

add

--add { -kFLAG -sFLAG -eFILEMASK -bFLAG -xDEF -rDIR } path1 {path2 ...}

Add new roots to bag.

If option -k -e -s is not specified then will be used it’s default values (symlink ignore, all files, stat comparison). In next step you must synchronize pybag with –sync command. Options in this command set properties for added roots and for next synchronizations. In the future you can manualy edit pybag.cfg for change root properties.

Options:

  • -kFLAG - Symlink action. Emulation turn off will increase speed, FLAG is:

    • c, copy - copy symlink, emulate if need.

    • cn, copynoemul - copy symlink, do not emulate symlink.

    • i, ignore - ignore symlink, emulation check if need. It is default.

    • in, ignorenoemul - ignore symlink, do not emulation check.

  • -sFLAG - Set compare method for files comparison. FLAG is comparison method:

    • stat or no flag or empty - use only stat information (size, modify date) - default. For directory and symlink modify date do not used.

    • crc32 - use CRC32 check then syncronize (If state information is equal then check additional by CRC32).

  • -eFILEMASK - Exclude from process all files and folders liked FILEMASK. You may get few optins -e. Default all files processed. FILEMASK may be:

    • Wildcards - multiply * mean any symbol any times, and question symbol ? mean one any symbol. For example: *.exe.

    • Regular expression - if starts with exlamination !, for example: !(.*\.bak$)|(.*\.pyc).

  • -b - Backup mode:

    • 0 - No backup. This is default.

    • 1 - This is will be a backup copy of original files. In this mode all synchronization will be one way (to bag, as direction bagall in command sync) and faster up 2 times then default (no backup) synchronization, becouse only original files will be readed and copied to bag if need.

  • -xDEF - Mark root as default. If not specified then by default root is default.

    • 0 - Root not default.

    • 1 - Root is default.

  • -rDIR - Add all items from directory DIR as roots. You may get few optins -r.

If you have backup root in bag from previous versions you can set to this roots into configuration file option: backup = 1, and use it now as backup (synchronization will be up 2 times faster).

Example:

> python pybag.py --add -kc -e".*,*~" "/home/user/docs1" "/home/user/memo.txt" "/home/user/news"

where:

  • kc - copy symlink,

  • e".*,*~" - ignore all hidden files (started from dot), and ignore all backup copies (ends with tilda).

  • Last parameters - paths to directories and files that you want add to bag.

remove

--remove root1 {root2 ...}

Remove roots from bag. Do not remove any items from origin location.

gui

--gui

Run program with GUI.

dist

--dist {-z} {-i} {-a} {-rROOT1 ...} {path1}

Distribute PYBAG program to specified location.

This do clear distribute without any files in current bag. If options -r or -a is given then in destination path also adjust pybag.cfg to point original to this (current) point. If you point path1 into other pybag then adding all to it. If you initialize -i then you may not specify path1. With other options path1 is required.

Options:

  • -z - Copy all additional files (manual, license and etc.). Create folder pybagfiles if need. Not copied roots.

  • -i - Initialize - Create pybagfiles directory, configuration file and DB file. If path1 not specified then initialize current location, overwise into specified location. Create only absent items, do not change exists. If path1 not exists then try create this directory.

  • -a - Copy all roots (if given this option, then options -r mark roots that will not be copied).

  • -rROOT - Distribute only specified roots (if option -a used then mark not copied roots).

Examples:

> python pybag.py --dist -i -m0

Initialize current location.

> python pybag.py --dist -i -a -m0 "/work/user/bag"

Initialize location /work/user/bag. Copy to it pybag.py, also add all roots from current location to new bag location.

sync

--sync { -fFILE } {-dDIR} {-dDIR} {-sMDDELTA} { -pA } { -bFLAG } { -gOUTFILTER } { -yFLAGVALUE } {path1}

Synchronize current bag with original files. If path1 specified then syncronize with specified location (path1). If no -f option given then try sync all pybag roots in path path1/r. If specified -f then path1 must correspond path in option. After comparing files you will be need confirm continue synchronization by action y or cancel by n.

Options:

  • -fFILE - Syncronize or copy only specified file FILE, where FILE is a relative path to /pybagfiles. For example: you have file pybag/pybagfiles/project/bin/file1.py, for synchronize you must write pybag --sync -f"project/bin/file1.py".

    For synchronize not all roots use -f option: pybag --sync -f"root1" -f"root5" - synchronize only roots “root1” and “root5”.

  • -xDEF - Select roots for synchronization. If not specified then select only default roots. Also this option is ignored when specified -f option.

    • all - All roots.

    • default - Only default roots. If not specified then select only default roots. Also this option is ignored when specified -f option.

  • -dDIR Direction for synchronization copy if conflicts occurs:

    • bag - write changed files into bag if conflicts.

    • origin - write changed files into copy or original location if conflicts.

    • newer - newer files overwrite older if conflicts.

    • older - older files overwrite newer if conflicts.

    • no - do not change files if conflicts. Is default.

    • bagall - write all changes from origin to bag.

    • originall - write all changes from bag to origin.

    • bagcopy - copy all changes to bag, but do not delete from bag anything.

    • origincopy - copy all changes to origin, but do not delete from origin anything.

    newer and older may be given with bag and origin simulteniously (for example -dbag -dnewer ). First will be checked newer and older, after used bag and origin.

    Warning

    Do not mix other direction flags, result may be umbigous.

  • -sMDDELTA - Set modify date delta in seconds (float number). If dates different less then MDDELTA then they assign equal. Override configuration file settings (only for current command).

  • -bFLAG - Set backup mode (for backuped roots).

    • 0 - Standart backup mode (default) - fast and one way (copy changes from origin to bag). All files that have in bag and not in origin will not be changed.

    • 1 - Synchronization backup - do full syncronization with origin (do bag same as origin). All files that have in bag but not in origin will be removed from bag.

  • -pA - Set autocontinue synchronization:

    • y - Yes, continue.

    • n - No, cancel.

    If you not use autoanswer (option -p) then will be displayed interactive menu. In this menu you can use next commands:

    • h - Display short help about menu.

    • d DIR DIR - change rules for autoconflict resolution (after change direction comparison will be repeated, and menu displayed again).

    • m FLAG - change emulation level. May be 0 or 1.

    • v FLAG - change verbosity level. May be 0 or 1.

    • y - continue syncronization.

    • n - cancel syncronization.

    • g OUTFILTER - change output filter. For details see option -g.

    • r - repeat report.

    • a #ACTION FILTER - manual force action ACTION with paths FILTER.

      • ACTION may be next:

        • delete - delete item,

        • bag - copy to bag or ignore if origin deleted,

        • origin - copy to origin or ignore if bag deleted,

        • skip - skip action (mark unchanged),

        • restore - restore automatic action,

        • tsbag - time shift to bag, FILTER select template (usualy *),

        • tsorigin - time shift to origin, FILTER select template (usualy *),

        • tsreset - reset time shift operation FILTER select template (usualy not need).

      • # mean + or - or nothing (for example: a +skip !.*\.exe ):

        • + - is interactive action, ask for each path user confirmation.

        • - - do not list paths and not need in confirmation.

        • nothing - is list paths but not need in confirmation.

      • FILTER - path mask:

        • Wildcards - (as fnmatch function) multiply * mean any symbol any times, and question symbol ? mean one any symbol. For example: *.exe.

        • Regular expression - if starts with exlamination !, for example: !(.*\.bak$)|(.*\.pyc).

        If filter not specified then used all files (same as *).

        After using ts... action items will be recompared and reset all actions. First use ts... action and after it use other actions.

  • -gOUTFILTER - Set format for report about compared files. Default is -gsbonhdyftwce1234 - display in report all operation with: new, copied, deleted, forced and not forced files, errors, conflicts and warnings for all direction in short format.

    • x - Do not show report at all. You can view report later by choose r option in interactive menu.

    • l - Long format of report: %(forced)s %(dir)s %(err)s [%(path)s]\n\t%(desc)s.

    • s - Short format of report: %(forced)s %(dir)s %(err)s [%(path)s].

    • p - Previous version (0.2 and early) format: \t[%(path)s]-->\n\t  == "%(desc)s".

    • m..FORMAT.. - Manual specified format as “print” function. .. - is separator (may be any two symbols). In format string may be used keywords written in next format: %(forced)s. Available keywords is:

      • err - displayed w, c, e or “space” - warning, conflict, error or nothing.

      • forced - displayed ! or “space” - Operation forced or not.

      • path - Item path (in OS format).

      • desc - Description.

      • type - displayed f, d, s ,”space” - Item type, file, directory, symlink or unknown (normaly this is must not be).

      • mdatedb - Modification date in DB, seconds.

      • gmdatedb - GMT modification date in DB, “YYYY-DD-MM HH-HH-SS”.

      • lmdatedb - Local modification date in DB, “YYYY-DD-MM HH-HH-SS”.

      • crc32db - CRC32 in DB, “0xFFFFFFFF”.

      • sizedb - Size in DB.

      • mdatebag - Modification date in bag, seconds.

      • gmdatebag - GMT modification date in bag, “YYYY-DD-MM HH-HH-SS”.

      • lmdatebag - Local modification date in bag, “YYYY-DD-MM HH-HH-SS”.

      • crc32bag - CRC32 in bag, “0xFFFFFFFF”.

      • sizebag - Size in bag.

      • mdateorigin - Modification date in origin, seconds.

      • gmdateorigin - GMT modification date in origin, “YYYY-DD-MM HH-HH-SS”.

      • lmdateorigin - Local modification date in origin, “YYYY-DD-MM HH-HH-SS”.

      • crc32origin - CRC32 in origin, “0xFFFFFFFF”.

      • sizeorigin - Size in origin.

      • symlinkdb - Link point in DB, “-” otherwise.

      • symlinkbag - Link point in bag, “-” otherwise.

      • symlinkorigin - Link point in origin, “-” otherwise.

      • timeshift - Time shift operation:

        • b - time shift to bag,

        • o - time shift to origin,

        • “space” - no time shift.

      • dir - Direction, displayed by next symbols:

        • <<< - New in origin, copy to bag.

        • >>> - New in bag, copy o origin.

        • <-- - Changed in origin, copy to bag.

        • --> - Changed in bag, copy to origin.

        • xxx - Delete item.

        • --- - Ignored item.

        • === - Unchanged item.

        • <== - Unchanged item, time shift to bag.

        • ==> - Unchanged item, time shift to origin.

        • *** - Error in filter and programm. (Note author if this situation appears).

    • z00 - List report by 00 items per page.

    • b - Operation with direction to bag.

    • o - Operation with direction to origin.

    • n - Operation with new files.

    • h - Operation with changed (copied) files.

    • d - Operation with deleted files.

    • i - Ignored files.

    • u - Unchanged files.

    • f - Forced action.

    • y - Time shift operation.

    • w - Warnings.

    • c - Conflicts.

    • e - Errors.

    • 1 - Files.

    • 2 - Directories.

    • 3 - Symlinks.

    • 4 - Unknown items (normaly this is must not be).

    • r..PATT.. - Path wildcards or regular expression filter. If not specified then displayed all.

    When you vew report by page (used option -z00) then in page menu you can:

    • Press ENTER for view next page,

    • Enter NUMBER for new page size,

    • Enter q for quit from report,

    • Enter a for list all items.

For backup purpose add root as backup:

python pybag.py --add -b1 root

If you have backup bag from previous versions you can set to this roots into configuration file option: backup = 1, and use it now as backup (synchronization will be in 2 times faster).

relocate

--relocate -rROOT=NEWPATH { -rROOT=NEWPATH ...}

Realocate root. Replace origin path for ROOT by new NEWPATH. (Realy change only configuration file).

stat

--stat { -xDEF -rROOT -rROOT ... }

Show statistics about bag. If no option -r specified then shown statistics for all roots.

  • -xDEF - Select roots. If this option not specified then select all roots. If specified -r option then this option ignored.

    • all - All roots.

    • default - Only default roots.

  • -rROOT - shown statistics only for specified roots.

cleandb

--cleandb

Clean DB from old records (old roots which already removed).

help

--help

or:

-h

or:

--usage

Display help information.

version

--version

Show version.

author

--author

Show author.

license

--license

Show license.

about

--about

About information.

debug

--debug {name ...}

Set turn on simple and debug logging and call _debug function. For debug purpouse only. Must be first in options list. If get name then call only this methods (“_test_name”) if exists.

Warning

Right tests will be only into source distribution. In copied files ( for example distributed with –dist ) number tests will be failed.

Common options

This options may be used for all commands.

v

-vLEVEL

Set verbosity level -1 … 5. Default assign 3.

  • -1 - No output. Only log file.

  • 0 - Only global errors.

  • 1 - Very small output, only about success and errors.

  • 2 - As 1 and conflicts.

  • 3 - Normal output. Common information and errors, conflicts, warnings.

  • 4 - Large output. As 3 and file operation.

  • 5 - Huge output. As 4 and logging.

l

-lFLAG

Enable 1 or disable 0 logging. FLAG may be 0 or 1. Default assign 1.

t

-tFLAG

Enable 1 or disable 0 out debug information to logging. FLAG may be 0 or 1. Default assign 1.

c

-cFLAG

Enable 1 or disable 0 colorization in console. Default is 1.

m

-mFLAG

Enable 1 or disable 0 emulation. FLAG may be 0 or 1.

Do not realy perform write operation. Do all actions as real command but do not change any files. Default assign 0. Usually this option use with -l or -t options for logging emulation result.

Common information

Directory structure.

  • doc/ - Documentation directory. - _build - Build documentation.

    • api/ - API documentation.

    • html/ - User manual.

    • rst - source of documentation.

  • pybagfiles/ - Directory where files saved in bag.

  • pybag.db - File list database, gziped text in utf-8.

  • pybag.cfg - Configuration file in utf-8.

  • pybag.log - Log file in utf-8.

  • ...~ - File ends with tilda “~” is backup.

PYBAG copy all you files and folders into ./pybagfiles folder.

Data base file.

Information about all entities in pybagfiles folder written into DB ./pybag.db - gziped text file in utf-8 encoding. In DB saves files in bag size, modify date, crc32 for all files in bag.

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, where:

  • F - flag:

    • d-directory,

    • f-file,

    • s-symlink,

    • ''- unknown type.

  • SIZE - file size in decimal or 0 for directories.

  • MDATE - modification date in YYYY/MM/DD-HH:mm:ss.

  • CRC32 - crc32 in decimal signed integer if exist or 0.

  • path_to_file - bag path (safe for any OS, see source code for detiles) to item into pybagfiles.

  • link_point - if item link then it’spoint, otherwise -.

Configuration file.

It is pybag.cfg file where saved preferences.

Format is next:

  • [root] - global preference:

    • version = PYBAG version.

    • ignore = global ignores. Default = '’-process all files. Patterns as fnmatch separated commas ‘,’ or regular expression started from exlamination ‘!’.

    • symlink = copy | copynoemul | ignore | ignorenoemul. Default = copy.

    • compare = stat | crc32. Compare method, stat - by size and modify date, crc32 - by crc32. Default = stat.

    • mddelta = Time differense in seconds for assign files equal then compare modify date (float). Default is 1.0 sec.

    • nextid = next free sequence id (integer).

    • emulation = 0 | 1. Emulation level.

    • debug = 0 | 1. Debug level.

    • logging = 1 | 0. Logging level.

    • verbosity = -15. Verbosity level.

    • colorize = 1 | 0. Colorize console output or not.

    • outfilter = format string. Format string for report.

    • backup = 0 | 1. Backup marker for roots.

    • r### = F path where F - flag (f``=file, ``d``=directory, ``s``=symlink), ``path - path to root ###, where ### is root id. Last part of path is a start path in pybagfiles folder.

  • [r###_pref] - local preference if need default none:

    • ignore = as above.

    • symlink = as above.

    • compare = as above.

    • backup = as above.

    • selectdefault = 1 | 0. Mark root as default.

  • [GUI] - GUI preferences:

    • writecolsatexit = Write column position when exit from program ( only if emuletion turn off). 0 | 1. Default is 0.

    • output - Show output window. 0 | 1. Default is 1.

    • showtips - Show tips window at start up. 0 | 1. Default is 1.

    • column# - Columns preferences. # is a column order. Format is: column0 = name, visible, width. Where cfgname - is a column name, visible - column visibility 0 or 1, width - column width in pixels ( from 0 to 2000). Allowed column name is next:

      • stateicon - Item state icon.

      • actionicon - Item action icon.

      • err - Item errors mark (e - error, c - conflict, w - warning).

      • forced - Forced state (! - item action is forced).

      • dir - Action direction.

      • path - Item path in bag.

      • desc - Description.

      • type - Item type

      • mdatedb - Item date in DB, float.

      • gmdatedb - Item date in DB, GMT.

      • lmdatedb - Item date in DB, Local.

      • crc32db - Item CRC32 sum in DB.

      • sizedb - Item size in DB, bytes.

      • symlinkdb - Symlink in DB.

      • mdatebag - Item date in bag, float.

      • gmdatebag - Item date in bag, GMT.

      • lmdatebag - Item date in bag, Local.

      • crc32bag - Item CRC32 sum in bag.

      • sizebag - Item size in bag, bytes.

      • symlinkbag - Symlink in bag.

      • mdateorigin - Item date in origin, float.

      • gmdateorigin - Item date in origin, GMT.

      • lmdateorigin - Item date in origin, Local.

      • crc32origin - Item CRC32 sum in origin.

      • sizeorigin - Item size in origin, bytes.

      • symlinkorigin - Symlink in origin.

      • tymeshift - Time shift.

    • filter_#### = 0 or 1. Filter with name #### allowed or disabled. Filters may be next:

      • filter_ok - synchronization OK,

      • filter_bag - Item action to bag,

      • filter_orig - Item action to origin,

      • filter_del - Delete item,

      • filter_ch - Item was changed,

      • filter_new - Item is new,

      • filter_err - Error in item,

      • filterconf - Conflict in item,

      • filter_warn - Warning in item,

      • filter_forced - Item action is forced,

      • filter_unch - Item is unchanged,

      • filter_file - Item type is file,

      • filter_dir - Item type is directory,

      • filter_sym - Item type is symlink,

      • filter_unk - Item type is unknown,

      • filter_ign - Item is ignored.

      • filter_ts - Time shift operation.