-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmakehash.py
More file actions
75 lines (64 loc) · 1.76 KB
/
makehash.py
File metadata and controls
75 lines (64 loc) · 1.76 KB
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
#!/usr/bin/env python
# coding:utf-8
# makehash.py
# Author: Wang Wei Qiang <wwqgtxx@gmail.com>
import sys
import os
import glob
sys.path += glob.glob('%s/*.egg' % os.path.dirname(os.path.abspath(__file__)))
sys.path += glob.glob('%s/lib/*.egg' % os.path.dirname(os.path.abspath(__file__)))
try:
if 'threading' in sys.modules:
del sys.modules['threading']
import gevent
import gevent.socket
import gevent.monkey
gevent.monkey.patch_all()
except (ImportError, SystemError):
gevent = None
try:
import OpenSSL
except ImportError:
OpenSSL = None
from simpleproxy import LocalProxyServer
from simpleproxy import server
from simpleproxy import logging
from simpleproxy import common as proxyconfig
from common import sysconfig as common
from common import FileUtil
from common import Config
from common import __config__
from common import __file__
import os
import sys
import thread
import urllib2
import random
def makehash(dir,topdown=True):
try :
print 'Generating '+common.CONFIG_SHA1+' table...'
FileUtil.if_has_file_remove(common.CONFIG_SHA1)
sha1 = Config(common.CONFIG_SHA1)
for root, dirs, files in os.walk(dir, topdown):
for name in files:
path = os.path.join(root,name)
newpath = path.replace(dir,'$path$')
regexpath = path.replace(dir,'.')
if regexpath.startswith(common.REGEX_START) or regexpath.endswith(common.REGEX_END):
continue
else:
sha1v = FileUtil.sumfile(path)
sha1.writeconfig('FILE_SHA1',newpath,sha1v)
print 'DONE generate '+common.CONFIG_SHA1+' table!'
return sha1
except Exception as e:
print 'FAIL to generate '+common.CONFIG_SHA1+' table!'
print e
sys.exit()
def main():
dir = FileUtil.cur_file_dir()
os.chdir(dir)
#sys.stdout.write(common.info())
makehash(dir)
if __name__ == '__main__':
main()