This repository has been archived by the owner on Dec 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exup.py
executable file
·90 lines (71 loc) · 2.35 KB
/
exup.py
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
#!/usr/bin/python
from subprocess import call
import sys, os, ftputil, shutil, ConfigParser, m2secret, exupconfig
class ExUp:
def run(self):
repo = raw_input('Enter the name of the repository you wish to export & upload: ')
if not repo:
print "No repo entered"
return 1
if not os.path.exists(exupconfig.REPOROOT + repo):
print "Repo doesn't exist"
return 1
svnpath = "file://" + exupconfig.REPOROOT + repo
tag = raw_input('Enter the tag (blank for trunk): ')
if tag:
svnpath += "/tag/" + tag
else:
svnpath += "/trunk"
export = './' + repo
if os.path.exists(export):
print "Unable to export to current directory, '" + export + '" already exists'
return 1
host = False
try:
retcode = call(["svn", "export", svnpath, export])
if (retcode > 0):
print "SVN export failed."
return 1
config = ConfigParser.RawConfigParser()
config.readfp(open(exupconfig.FTPCONFIGFILE))
ftphost = config.get(repo,'host')
ftpuser = config.get(repo,'user')
secretkey = raw_input('Enter your encryption key for the FTP password (or blank for unencrypted): ')
if secretkey:
secret = m2secret.Secret()
secret.deserialize(config.get(repo,'pass'))
ftppass = secret.decrypt(secretkey)
else:
ftppass = config.get(repo,'pass')
try:
print "Logging into:", ftphost, "with login:", ftpuser, "..."
host = ftputil.FTPHost(ftphost, ftpuser, ftppass)
except AttributeError:
print "FTP connection failed: please check ftp host and login and try again..."
return 1
except ftputil.ftp_error.FTPError, err:
print "FTP connection failed: please check ftp host, login and password and try again..."
print err
return 1
exportl = len(export)
spath = config.get(repo,'path')
for root, dirs, files in os.walk(export):
prefix = root[exportl:]
if (len(prefix) > 0):
prefix = prefix[1:] + '/'
for d in dirs:
if not host.path.isdir(spath + prefix + d):
host.makedirs(spath + prefix + d)
print "created directory", spath + d
for f in files:
if host.upload_if_newer(export + '/' + prefix + f, spath + prefix + f):
print "uploaded", spath + prefix + f
finally:
if host:
host.close()
if os.path.exists(export):
shutil.rmtree(export)
return 0
if __name__ == '__main__':
exup = ExUp()
sys.exit(exup.run())