import os import sys import urllib2 from opster import command dispatc

 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
import os
import sys
import urllib2
from opster import command, dispatch
def _process_entries(data):
items = data.split(chr(0x0C))[1:]
dirs = []
files = []
for j in items:
params = j.split('\n')
params = [x for x in params if x]
if len(params) >= 2:
if params[1] == 'dir':
dirs.append(params[0])
elif params[1] == 'file':
files.append(params[0])
return dirs, files
def _scan(url, path):
fname = 'http://%s/.svn/entries' % url
try:
f = urllib2.urlopen(fname)
data = f.read()
f.close()
dirs, files = _process_entries(data)
# Download files
for f in files:
if os.path.exists('%s/%s' % (path, f)):
continue
print '... %s/%s' % (path, f)
furl = 'http://%s/.svn/text-base/%s.svn-base' % (url, f)
#print furl
if not os.path.exists(path):
os.makedirs(path)
try:
of = file('%s/%s' % (path, f), 'wb')
fi = urllib2.urlopen(furl)
of.write(fi.read())
fi.close()
of.close()
except Exception, e:
print e
print 'Failed to download %s' % furl
# Process directories
for d in dirs:
_scan('%s/%s' % (url, d), '%s/%s' % (path, d))
except Exception, e:
print e
print 'No %s present' % fname
@command()
def scan(url):
_scan(url, '%s' % url)
dispatch()