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