64 lines
1.7 KiB
Python
Executable File
64 lines
1.7 KiB
Python
Executable File
#!/bin/python3
|
|
import os
|
|
import sys
|
|
import logging
|
|
import json
|
|
import requests
|
|
import argparse
|
|
|
|
from subject import main
|
|
|
|
# Identity attributes
|
|
# {'username' : '', 'full_name' : '', 'email' : '', public_key : '' }
|
|
|
|
logging.basicConfig(format='%(levelname)s\t- %(message)s')
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.INFO)
|
|
|
|
state = main(sys.argv)
|
|
|
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
|
|
|
#get file
|
|
#file handle - file(optonal)
|
|
def getFile(args):
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("-k", '--key', nargs=1, help="Path to the key file")
|
|
parser.add_argument("-r", '--repo', nargs=1, help="Address:Port of the repository")
|
|
parser.add_argument("-v", '--verbose', help="Increase verbosity", action="store_true")
|
|
|
|
parser.add_argument('filehandle', nargs='?', default=None)
|
|
parser.add_argument('file', nargs='?', default=None)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
if not args.filehandle:
|
|
logger.error("Need a file handle.")
|
|
sys.exit(1)
|
|
#else:
|
|
# if not os.path.isfile(BASE_DIR + args.filehandle):
|
|
# logger.error("File '" + args.filehandle + "' not found" )
|
|
# sys.exit(1)
|
|
|
|
#Get file
|
|
try:
|
|
file = requests.get(f'http://{state['REP_ADDRESS']}/file/get/' + args.filehandle + '/content')
|
|
file.raise_for_status()
|
|
except requests.exceptions.RequestException as errex:
|
|
logger.error("Failed to obtain response from server.")
|
|
sys.exit(-1)
|
|
|
|
print(file)
|
|
|
|
if not args.file:
|
|
sys.stdout.write(file.text)
|
|
else:
|
|
with open(BASE_DIR + args.file, "wb") as f:
|
|
f.write(file.content)
|
|
|
|
sys.exit(0)
|
|
|
|
if __name__ == '__main__':
|
|
getFile(sys.argv[1:]) |