diff options
author | Boris Nagaev <bnagaev@gmail.com> | 2017-01-13 01:05:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-13 01:05:19 (GMT) |
commit | f7edc4323786f82567d6425ebddffb7d0102e1fd (patch) | |
tree | 1f4ad12d3892065cdc04c6f0a215c2e9462f1b91 /tools/update_backup.py | |
parent | e31376b0c70adf3580c34ed41870148d61d6477f (diff) | |
parent | 4a7b9526f08bfcf9bf84b68dbfb030f2227a6ce0 (diff) | |
download | mxe-f7edc4323786f82567d6425ebddffb7d0102e1fd.zip mxe-f7edc4323786f82567d6425ebddffb7d0102e1fd.tar.gz mxe-f7edc4323786f82567d6425ebddffb7d0102e1fd.tar.bz2 |
Merge pull request #1627 from LuaAndC/pkg-backup-tools
add tools to create and update backup of packages
Diffstat (limited to 'tools/update_backup.py')
-rwxr-xr-x | tools/update_backup.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/update_backup.py b/tools/update_backup.py new file mode 100755 index 0000000..0069216 --- /dev/null +++ b/tools/update_backup.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +""" Update backup of MXE packages. +""" + +import argparse +import hashlib +import os +import shutil + +def make_checksum(filepath): + hasher = hashlib.sha256() + with open(filepath, 'rb') as f: + for chunk in iter(lambda: f.read(1024 ** 2), b''): + hasher.update(chunk) + return hasher.hexdigest() + +def update_backup(mxe_pkg_dir, backup_dir): + for f in os.listdir(mxe_pkg_dir): + sha = make_checksum(os.path.join(mxe_pkg_dir, f)) + new_name = '%s_%s' % (f, sha) + if os.path.exists(os.path.join(backup_dir, new_name)): + print("File %s is already backuped" % new_name) + continue + shutil.copy( + os.path.join(mxe_pkg_dir, f), + os.path.join(backup_dir, new_name), + ) + print("Backup file %s" % new_name) + +def main(): + parser = argparse.ArgumentParser( + description=__doc__, + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + ) + parser.add_argument( + '--backup-dir', + type=str, + help='Path to backup', + required=True, + ) + args = parser.parse_args() + mxe_tools_dir = os.path.dirname(os.path.realpath(__file__)) + mxe_pkg_dir = os.path.join(mxe_tools_dir, '..', 'pkg') + update_backup( + mxe_pkg_dir, + args.backup_dir, + ) + +if __name__ == '__main__': + main() |