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
|
# global server link
|
||||||
server_link = None
|
server_link = None
|
||||||
file = None
|
file = None
|
||||||
|
# outdir = None
|
||||||
|
|
||||||
def link_established(link):
|
def link_established(link):
|
||||||
global server_link
|
global server_link
|
||||||
|
|
@ -170,17 +171,19 @@ def link_closed():
|
||||||
def file_received(request_receipt):
|
def file_received(request_receipt):
|
||||||
global file
|
global file
|
||||||
file = True
|
file = True
|
||||||
|
|
||||||
|
global outdir
|
||||||
try:
|
try:
|
||||||
if type(request_receipt.response) == io.BufferedReader:
|
if type(request_receipt.response) == io.BufferedReader:
|
||||||
if request_receipt.metadata != None:
|
if request_receipt.metadata != None:
|
||||||
file_name = os.path.basename(request_receipt.metadata["name"].decode("utf-8"))
|
file_name = os.path.basename(request_receipt.metadata["name"].decode("utf-8"))
|
||||||
file_handle = request_receipt.response
|
file_handle = request_receipt.response
|
||||||
file_destination = "."+"/"+file_name
|
file_destination = outdir+"/"+file_name
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
while os.path.isfile(file_destination):
|
while os.path.isfile(file_destination):
|
||||||
counter += 1
|
counter += 1
|
||||||
file_destination = "."+"/"+file_name+"."+str(counter)
|
file_destination = outdir+"/"+file_name+"."+str(counter)
|
||||||
|
|
||||||
shutil.move(file_handle.name, file_destination)
|
shutil.move(file_handle.name, file_destination)
|
||||||
|
|
||||||
|
|
@ -193,7 +196,7 @@ def file_received(request_receipt):
|
||||||
counter = 0
|
counter = 0
|
||||||
while os.path.isfile(file_destination):
|
while os.path.isfile(file_destination):
|
||||||
counter += 1
|
counter += 1
|
||||||
file_destination = "."+"/"+file_destination_name+"."+str(counter)
|
file_destination = outdir+"/"+file_destination_name+"."+str(counter)
|
||||||
|
|
||||||
fh = open(file_destination, "wb")
|
fh = open(file_destination, "wb")
|
||||||
fh.write(file_data)
|
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 = 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("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()
|
args = parser.parse_args()
|
||||||
arglist = args.URL.split(":")
|
arglist = args.URL.split(":")
|
||||||
|
|
@ -232,6 +236,8 @@ resource_path = arglist[1]
|
||||||
print(dest_hash)
|
print(dest_hash)
|
||||||
print(resource_path)
|
print(resource_path)
|
||||||
|
|
||||||
|
outdir = args.OUTDIR
|
||||||
|
|
||||||
|
|
||||||
r = RNS.Reticulum()
|
r = RNS.Reticulum()
|
||||||
RNS.loglevel = RNS.LOG_DEBUG
|
RNS.loglevel = RNS.LOG_DEBUG
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue