insert to existing conf
This commit is contained in:
60
utils/create-share.py
Executable file
60
utils/create-share.py
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
import hashlib,argparse,json,sys
|
||||
from datetime import datetime
|
||||
from shutil import copyfile
|
||||
|
||||
parser = argparse.ArgumentParser(description='Flees share template generator')
|
||||
|
||||
parser.add_argument('-n','--name', action="store", dest="name", required = True)
|
||||
parser.add_argument('-p','--path', action="store", dest="path", required = True,help= "path relative to data folder")
|
||||
parser.add_argument('-P','--public', action="store_true", dest="public", default = False)
|
||||
parser.add_argument('-u','--upload', action="store_true", dest="upload", default = False)
|
||||
parser.add_argument('--pass-plain', action="store", dest="plain", default = False)
|
||||
parser.add_argument('--pass-hashed', action="store", dest="hashed", default = False)
|
||||
parser.add_argument('-e','--expire', action="store", dest="expire", default = False, help = "expire date in format 2018-12-24 21:00")
|
||||
parser.add_argument('-s','--shares', action="store", dest="shares", default = False,
|
||||
help = "Your current shares.json file")
|
||||
parser.add_argument('-i','--insert', action="store_true", dest="insert", default = False,
|
||||
help = "If 'shares' defined, insert new share directly in the shares.json file")
|
||||
|
||||
opts = parser.parse_args()
|
||||
|
||||
share = {
|
||||
'name': opts.name,
|
||||
'path': opts.path,
|
||||
'public': opts.public,
|
||||
'upload': opts.upload,
|
||||
}
|
||||
if opts.plain:
|
||||
share.update({
|
||||
'pass_plain': opts.plain
|
||||
})
|
||||
if opts.hashed:
|
||||
share.update({
|
||||
'pass_hash': hashlib.sha256(opts.hashed).hexdigest()
|
||||
})
|
||||
if opts.expire:
|
||||
try:
|
||||
date_object = datetime.strptime(opts.expire,"%Y-%m-%d %H:%M")
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
sys.exit(1)
|
||||
share.update({
|
||||
'expire': opts.expire
|
||||
})
|
||||
|
||||
if opts.shares:
|
||||
shares = json.load(open(opts.shares,'rt'))
|
||||
shares.append(share)
|
||||
if opts.insert:
|
||||
print("creating backup %s"%(opts.shares+".bkp",))
|
||||
copyfile(opts.shares,opts.shares+".bkp")
|
||||
with open(opts.shares,'wt') as fp:
|
||||
json.dump(shares, fp, indent = 2, sort_keys = True)
|
||||
print("Wrote file %s"%(opts.shares,))
|
||||
else:
|
||||
print(json.dumps(shares, indent = 2, sort_keys = True))
|
||||
else:
|
||||
print(json.dumps(share, indent = 2, sort_keys = True))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user