-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_module.py
58 lines (48 loc) · 1.84 KB
/
install_module.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
import os,sys
cachePath = "/home/brendan/secpy/lib/secPy"
def AddPath():
sys.path.append(cachePath)
def ensure(directory):
if not os.path.exists(directory):
os.makedirs(directory)
def install_package(path):
import pymultihash as pmh
os.chdir(path)
paths = []
for root, dir, files in os.walk("."):
for item in files:
if(len(item)>3 and item[-3:]==".py"):
path = root+"/"+item
hval = None
with open(path,"r") as fp:
data = fp.read()
hval = pmh.genHash(data,0x12)
paths.append((hval,path))
cert = "\n".join(map(lambda x: " ".join(x),paths))
certhash = pmh.genHash(cert,0x12)
hashed_cert = certhash+"\n"+cert
working_path = os.path.join(cachePath,certhash)
#print("Working Path",working_path)
ensure(working_path)
with open(os.path.join(working_path,"certfile.txt"),"w") as fp:
fp.write(hashed_cert)
for h, fname in paths:
dest = os.path.join(working_path,fname)
dirname = os.path.dirname(dest)
ensure(dirname)
with open(fname,"r") as read_fp:
with open(dest,"w") as write_fp:
write_fp.write(read_fp.read())
print("Package Name is:")
print(certhash)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Adds files to a content address package library')
parser.add_argument('path', type=str,
help='path to the root of a package')
parser.add_argument('--cachePath',type=str, default="/usr/lib/secPy/",
help='changes the cache to which the package is stored')
args = parser.parse_args()
package_path = args.path
cachePath = args.cachePath
install_package(package_path)