add output directory
This commit is contained in:
parent
bc39bb38a3
commit
742a4a7004
1 changed files with 9 additions and 3 deletions
12
fetcher.py
12
fetcher.py
|
|
@ -158,6 +158,7 @@ import RNS
|
|||
# global server link
|
||||
server_link = None
|
||||
file = None
|
||||
# outdir = None
|
||||
|
||||
def link_established(link):
|
||||
global server_link
|
||||
|
|
@ -170,17 +171,19 @@ def link_closed():
|
|||
def file_received(request_receipt):
|
||||
global file
|
||||
file = True
|
||||
|
||||
global outdir
|
||||
try:
|
||||
if type(request_receipt.response) == io.BufferedReader:
|
||||
if request_receipt.metadata != None:
|
||||
file_name = os.path.basename(request_receipt.metadata["name"].decode("utf-8"))
|
||||
file_handle = request_receipt.response
|
||||
file_destination = "."+"/"+file_name
|
||||
file_destination = outdir+"/"+file_name
|
||||
|
||||
counter = 0
|
||||
while os.path.isfile(file_destination):
|
||||
counter += 1
|
||||
file_destination = "."+"/"+file_name+"."+str(counter)
|
||||
file_destination = outdir+"/"+file_name+"."+str(counter)
|
||||
|
||||
shutil.move(file_handle.name, file_destination)
|
||||
|
||||
|
|
@ -193,7 +196,7 @@ def file_received(request_receipt):
|
|||
counter = 0
|
||||
while os.path.isfile(file_destination):
|
||||
counter += 1
|
||||
file_destination = "."+"/"+file_destination_name+"."+str(counter)
|
||||
file_destination = outdir+"/"+file_destination_name+"."+str(counter)
|
||||
|
||||
fh = open(file_destination, "wb")
|
||||
fh.write(file_data)
|
||||
|
|
@ -224,6 +227,7 @@ def response_progressed(req_receipt):
|
|||
|
||||
parser = argparse.ArgumentParser(description="request a resource from a target node")
|
||||
parser.add_argument("URL", help="the LXMF URL of the resource to be fetched")
|
||||
parser.add_argument("OUTDIR", help="the output directory to place the file")
|
||||
|
||||
args = parser.parse_args()
|
||||
arglist = args.URL.split(":")
|
||||
|
|
@ -232,6 +236,8 @@ resource_path = arglist[1]
|
|||
print(dest_hash)
|
||||
print(resource_path)
|
||||
|
||||
outdir = args.OUTDIR
|
||||
|
||||
|
||||
r = RNS.Reticulum()
|
||||
RNS.loglevel = RNS.LOG_DEBUG
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue