• R/O
  • SSH

pyrepo: Commit

Library with common primitives for Python_ programming language


Commit MetaInfo

Revisionf0e86356a4eb188f17a5dfcf5a0f95c85a2cd7f3 (tree)
Time2014-08-14 23:30:35
Authors.gusarov
Commiters.gusarov

Log Message

initial commit

Change Summary

Incremental Difference

diff -r 000000000000 -r f0e86356a4eb pack.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pack.py Thu Aug 14 18:30:35 2014 +0400
@@ -0,0 +1,50 @@
1+#!/usr/bin/env python3
2+
3+# This script quickly creates a backup archive with proper name
4+
5+import os
6+import getpass
7+import subprocess
8+import sys
9+import tarfile
10+import time
11+from time import strftime
12+
13+__author__ = 'Sergey Gusarov'
14+
15+def fmtSizeOf(num):
16+ for x in ['bytes','KB','MB','GB','TB']:
17+ if num < 1024.0:
18+ return "%3.1f %s" % (num, x)
19+ num /= 1024.0
20+
21+def main():
22+ rev=os.popen('hg identify --num').read().replace('+', 'M').replace('\n', '')
23+ date=strftime("%d_%m_%Y", time.localtime(time.time()))
24+ user=getpass.getuser()
25+ dir_to_pack=os.path.dirname(os.path.realpath(__file__))
26+ prj=os.path.basename(dir_to_pack)
27+
28+ # TODO: tar progress by adding one-by-one files or external module
29+ if sys.version_info.major >= 3:
30+ if sys.version_info.minor >= 3:
31+ use_lzma=True
32+ else:
33+ use_lzma=False
34+ else:
35+ use_lzma=False
36+
37+ if use_lzma:
38+ file=os.path.join('..', prj+'_'+date+'_hg'+rev+'_'+user+'.tar.lzma')
39+ tar=tarfile.open(file, 'w:xz')
40+ else:
41+ file=os.path.join('..', prj+'_'+date+'_hg'+rev+'_'+user+'.tar.bz2')
42+ tar=tarfile.open(file, 'w:bz2')
43+
44+ tar.add(dir_to_pack, arcname=prj)
45+ tar.close()
46+
47+ fileSize=os.path.getsize(file)
48+ print(file+' : '+str(fmtSizeOf(fileSize)))
49+
50+main()
diff -r 000000000000 -r f0e86356a4eb readme.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/readme.rst Thu Aug 14 18:30:35 2014 +0400
@@ -0,0 +1,13 @@
1+======
2+Pymisc
3+======
4+
5+Общие сведения
6+--------------
7+
8+Библиотека различных примитивов для языка Python
9+
10+Системные требования
11+--------------------
12+
13+Python3 и выше
Show on old repository browser