##// END OF EJS Templates
Litle info messages update
Marcin Kuzminski -
r26:b3307ca6 default
parent child Browse files
Show More
@@ -1,52 +1,53 b''
1 1 import logging
2 2 from mercurial import config
3 3 import tarfile
4 4 import os
5 5 import datetime
6 6 import sys
7 7 logging.basicConfig(level = logging.DEBUG,
8 8 format = "%(asctime)s %(levelname)-5.5s %(message)s")
9 9
10 10 class BackupManager(object):
11 11 def __init__(self):
12 12
13 13 dn = os.path.dirname
14 14 self.backup_file_path = os.path.join(dn(dn(dn(__file__))), 'data')
15 15 cfg = config.config()
16 16 try:
17 17 cfg.read(os.path.join(dn(dn(dn(__file__))), 'hgwebdir.config'))
18 18 except IOError:
19 19 logging.error('Could not read hgwebdir.config')
20 20 sys.exit()
21 21 self.set_repos_path(cfg.items('paths'))
22 22 logging.info('starting backup for %s', self.repos_path)
23 23 logging.info('backup target %s', self.backup_file_path)
24 24
25 25 if not os.path.isdir(self.repos_path):
26 26 raise Exception('Not a valid directory in %s' % self.repos_path)
27 27
28 28 def set_repos_path(self, paths):
29 29 repos_path = paths[0][1].split('/')
30 30 if repos_path[-1] in ['*', '**']:
31 31 repos_path = repos_path[:-1]
32 32 if repos_path[0] != '/':
33 33 repos_path[0] = '/'
34 34 self.repos_path = os.path.join(*repos_path)
35 35
36 36 def backup_repos(self):
37 37 today = datetime.datetime.now().weekday() + 1
38 38 bckp_file = os.path.join(self.backup_file_path,
39 39 "mercurial_repos.%s.tar.gz" % today)
40 40 tar = tarfile.open(bckp_file, "w:gz")
41 41
42 42 for dir in os.listdir(self.repos_path):
43 43 logging.info('backing up %s', dir)
44 44 tar.add(os.path.join(self.repos_path, dir), dir)
45 45 tar.close()
46 logging.info('finished backup of mercurial repositories')
46 47
47 48
48 49 if __name__ == "__main__":
49 50 bm = BackupManager()
50 51 bm.backup_repos()
51 52
52 53
General Comments 0
You need to be logged in to leave comments. Login now