Public » Kiln Backup
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

Working version of kilnbackup

Changeset 2332d9fa0a12

by Profile picture of User 4Stefan Rusek <stefan@rusek.org>

Changes to 2 files · Browse files at 2332d9fa0a12 Diff from another changeset...

Change 1 of 1 Show Entire File .hgignore Stacked
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
@@ -0,0 +1,10 @@
+syntax: glob +_ReSharper* +*/bin/* +*/obj/* +*.suo +*.user +*.swp +*~ +*.pyc +*.cfg
Change 1 of 1 Show Entire File kilnbackup.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@@ -0,0 +1,92 @@
+#! /usr/bin/env python + +import ConfigParser, sys, urllib, urllib2, cookielib, os, subprocess, shutil + +config = ConfigParser.ConfigParser() +config.read("kilnbackup.cfg") + +save = False + +if not config.has_section('kiln'): + config.add_section('kiln') + +settings = dict(config.items('kiln')) + +def prompt(msg): + print(prompt) + value = sys.stdin.readline().strip() + if not value: + sys.exit() + return value + +def check(section, option, msg): + if settings.get(option): + return + value = prompt(msg) + global save + save = True + config.set(section, option, value) + settings[option] = value + +check("kiln", "server", "Enter the name of the fogbugz server (eg https://company.fogbugz.com)") +check("kiln", "username", "Username:") +check("kiln", "password", "Password:") + +if save: + f = open("kilnbackup.cfg", "w") + config.write(f) + f.flush() + f.close() + +server = settings["server"] + +def get_repos(): + cj = cookielib.CookieJar() + handler = urllib2.HTTPCookieProcessor(cj) + opener = urllib2.build_opener(handler) + + data = urllib.urlencode({ + "pre":"preLogon", "fRememberPassword":"1", "dest":"", + "sPerson":settings["username"], "sPassword":settings["password"]}) + response = opener.open(server + "/default.asp", data) + response.read() + response.close() + + response = opener.open(server + "/kiln/Api/Repos/") + js = response.read() + response.close() + + return js + +def jseval(js): + return eval(js, {"null":None, "true":True, "false":False}) + +def build_url(path): + url = server + path + return url.replace("://", "://%s:%s@" % ( + urllib.quote(settings["username"], ''), + urllib.quote(settings["password"], '') + )) + +for repo in jseval(get_repos()): + url = build_url(repo["url"]) + name = os.path.split(repo["url"])[-1] + + if (os.path.exists(name)): + hgrc = ConfigParser.ConfigParser() + hgrc.read("%s/.hg/hgrc" % name) + + if not hgrc.has_section('paths') or hgrc.get('paths', 'default') != url: + print "Deleting old repo", name + shutil.rmtree(name) + + if os.path.exists(name): + os.chdir(name) + print "Pulling latest changes to", name + subprocess.call(['hg', 'pull']) + os.chdir("..") + else: + print "Cloninng", name + subprocess.call(['hg', 'clone', '-U', url, name]) + +