share manager
This commit is contained in:
@@ -1,9 +1,13 @@
|
|||||||
{
|
{
|
||||||
|
"__comment": [
|
||||||
|
"workers: number of parallel processes. single long upload reserves a process.",
|
||||||
|
"timeout: seconds for process to last. single long upload cant take longer than this.",
|
||||||
|
"uid: Docker runs as root, this changes owner of written files. -1 to skip chowning"
|
||||||
|
],
|
||||||
"workers": 8,
|
"workers": 8,
|
||||||
"timeout": 3600,
|
"timeout": 3600,
|
||||||
"uid_comment": "Docker runs as root, this changes owner of written files.",
|
|
||||||
"uid": 1000,
|
"uid": 1000,
|
||||||
"__comment": "most likely you will not change anything after this line",
|
"__do_not_edit": "most likely you will not change anything after this line",
|
||||||
"data_folder": "data",
|
"data_folder": "data",
|
||||||
"shares_file": "data/shares.json",
|
"shares_file": "data/shares.json",
|
||||||
"date_format": "%Y-%m-%d %H:%M"
|
"date_format": "%Y-%m-%d %H:%M"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import hashlib,argparse,json,sys
|
import hashlib,argparse,json,sys,os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
@@ -51,7 +51,10 @@ if opts.expire:
|
|||||||
})
|
})
|
||||||
|
|
||||||
if opts.shares:
|
if opts.shares:
|
||||||
shares = json.load(open(opts.shares,'rt'))
|
if os.path.exists(opts.shares):
|
||||||
|
shares = json.load(open(opts.shares,'rt'))
|
||||||
|
else:
|
||||||
|
shares = []
|
||||||
shares.append(share)
|
shares.append(share)
|
||||||
if opts.insert:
|
if opts.insert:
|
||||||
print("creating backup %s"%(opts.shares+".bkp",))
|
print("creating backup %s"%(opts.shares+".bkp",))
|
||||||
|
|||||||
79
utils/flees-manager.py
Executable file
79
utils/flees-manager.py
Executable file
@@ -0,0 +1,79 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import argparse,json,sys,os
|
||||||
|
from shutil import copyfile
|
||||||
|
|
||||||
|
|
||||||
|
def list_shares(shares):
|
||||||
|
print("\t".join( ('Name', 'Path') ))
|
||||||
|
for share in shares:
|
||||||
|
print("\t".join( (share['name'], share['path']) ))
|
||||||
|
|
||||||
|
|
||||||
|
def list_folders(shares,config):
|
||||||
|
folders = sorted(os.listdir(config['data_folder']))
|
||||||
|
print("\t".join( ('Path','Share') ))
|
||||||
|
for folder in folders:
|
||||||
|
full_path = os.path.join(config['data_folder'], folder)
|
||||||
|
if not os.path.isdir(full_path):
|
||||||
|
continue
|
||||||
|
share_name = "[unused by any share]"
|
||||||
|
for share in shares:
|
||||||
|
share_path = os.path.join(config['data_folder'], share['path'])
|
||||||
|
if os.path.samefile(full_path, share_path):
|
||||||
|
share_name = share['name']
|
||||||
|
break
|
||||||
|
print("\t".join( (folder, share_name) ))
|
||||||
|
|
||||||
|
def remove_share(name,shares,config):
|
||||||
|
share = [share for share in shares if share['name'] == name]
|
||||||
|
for share_ in share:
|
||||||
|
print("Removing share: %s"%( name, ))
|
||||||
|
print(json.dumps(share_, indent = 2, sort_keys = True))
|
||||||
|
|
||||||
|
shares = [share for share in shares if share['name'] != name]
|
||||||
|
|
||||||
|
share_file = config['shares_file']
|
||||||
|
print("creating backup %s"%(share_file+".bkp",))
|
||||||
|
copyfile(share_file, share_file+".bkp")
|
||||||
|
with open(share_file,'wt') as fp:
|
||||||
|
json.dump(shares, fp, indent = 2, sort_keys = True)
|
||||||
|
print("Removed %s from %s"%(name, share_file))
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Flees share manager')
|
||||||
|
parser.add_argument('-c','--config', action="store", dest="config", default = "data/config.json",
|
||||||
|
help = "Your current config.json file")
|
||||||
|
|
||||||
|
subparsers = parser.add_subparsers(help='sub-command help', dest='subparser_name')
|
||||||
|
|
||||||
|
parser_list = subparsers.add_parser('list', help = "List shares")
|
||||||
|
|
||||||
|
parser_folders = subparsers.add_parser('folders', help = "List folders and share names")
|
||||||
|
|
||||||
|
parser_remove = subparsers.add_parser('remove', help = "Remove a share")
|
||||||
|
parser_remove.add_argument(dest="name")
|
||||||
|
|
||||||
|
|
||||||
|
opts = parser.parse_args()
|
||||||
|
|
||||||
|
if os.path.exists(opts.config):
|
||||||
|
config = json.load(open(opts.config,'rt'))
|
||||||
|
else:
|
||||||
|
print("config file does not exist!")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if os.path.exists(config['shares_file']):
|
||||||
|
shares = json.load(open(config['shares_file'],'rt'))
|
||||||
|
else:
|
||||||
|
print("shares_file does not exist!")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if opts.subparser_name == 'list':
|
||||||
|
list_shares(shares)
|
||||||
|
elif opts.subparser_name == 'folders':
|
||||||
|
list_folders(shares,config)
|
||||||
|
elif opts.subparser_name == 'remove':
|
||||||
|
remove_share(opts.name,shares,config)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user