diff --git a/application.properties b/application.properties index 228f3e9..4c1de3a 100644 --- a/application.properties +++ b/application.properties @@ -1,2 +1,2 @@ sascli.location=/opt/sas/viya/home/bin -sascli.executable=sas.admin \ No newline at end of file +sascli.executable=sas-viya \ No newline at end of file diff --git a/exportfoldertree.py b/exportfoldertree.py index 80ffb92..a2c3566 100755 --- a/exportfoldertree.py +++ b/exportfoldertree.py @@ -7,7 +7,7 @@ # Pass in a directory and this tool will export the complete viya folder # structure to a sub-directory named for the current date and time # There will be a json file for each viya folder at the root level. -# +# # # Change History # @@ -30,15 +30,20 @@ # Import Python modules import argparse, sys, subprocess, uuid, time, os, glob -from sharedfunctions import getfolderid, callrestapi +from sharedfunctions import getfolderid, callrestapi,getapplicationproperties -# get python version +# get python version version=int(str(sys.version_info[0])) -# CHANGE THIS VARIABLE IF YOUR CLI IS IN A DIFFERENT LOCATION -clidir='/opt/sas/viya/home/bin/' +# get cli location from properties +propertylist=getapplicationproperties() + +clidir=propertylist["sascli.location"] +cliexe=propertylist["sascli.executable"] + +cli_command=os.path.join(clidir,cliexe) -# get input parameters +# get input parameters parser = argparse.ArgumentParser(description="Export the complete Viya folder tree") parser.add_argument("-d","--directory", help="Directory for Export",required='True') parser.add_argument("-q","--quiet", help="Suppress the are you sure prompt.", action='store_true') @@ -56,11 +61,11 @@ if os.path.exists(basedir): if version > 2: areyousure=input("The folder exists any existing json files in it will be deleted. Continue? (Y)") else: - areyousure=raw_input("The folder already exists any existing json files in it will be deleted. Continue? (Y)") + areyousure=raw_input("The folder already exists any existing json files in it will be deleted. Continue? (Y)") else: areyousure="Y" -else: areyousure="Y" +else: areyousure="Y" # prompt is Y if user selected Y, its a new directory, or user selected quiet mode if areyousure.upper() =='Y': @@ -69,7 +74,7 @@ if areyousure.upper() =='Y': # create directory if it doesn't exist if not os.path.exists(path): os.makedirs(path) - else: + else: filelist=glob.glob(path+"/*.json") for file in filelist: os.remove(file) @@ -81,31 +86,31 @@ if areyousure.upper() =='Y': # loop root folders if 'items' in resultdata: - + total_items=resultdata['count'] - + returned_items=len(resultdata['items']) - + if total_items == 0: print("Note: No items returned.") else: # export each folder and download the package file to the directory - for i in range(0,returned_items): - + for i in range(0,returned_items): + id=resultdata['items'][i]["id"] package_name=str(uuid.uuid1()) json_name=resultdata['items'][i]["name"].replace(" ","")+'_'+str(i) - + command=clidir+'sas-admin transfer export -u /folders/folders/'+id+' --name "'+package_name+'"' - print(command) + print(command) subprocess.call(command, shell=True) - reqval='/transfer/packages?filter=eq(name,"'+package_name+'")' + reqval='/transfer/packages?filter=eq(name,"'+package_name+'")' package_info=callrestapi(reqval,reqtype) - + package_id=package_info['items'][0]['id'] - + completefile=os.path.join(path,json_name+'.json') - command=clidir+'sas-admin transfer download --file '+completefile+' --id '+package_id + command=clidir+'sas-admin transfer download --file '+completefile+' --id '+package_id print(command) subprocess.call(command, shell=True) diff --git a/listreports.py b/listreports.py index a360fb9..3c858a9 100755 --- a/listreports.py +++ b/listreports.py @@ -32,11 +32,6 @@ from sharedfunctions import getfolderid, callrestapi, getpath, printresult, geta # get python version version=int(str(sys.version_info[0])) -propertylist=getapplicationproperties() - -clidir=propertylist["sascli.location"] -cliexe=propertylist["sascli.executable"] - # get input parameters parser = argparse.ArgumentParser(description="List Viya Reports and their folder path.") parser.add_argument("-n","--name", help="Name contains?",default=None) diff --git a/sharedfunctions.py b/sharedfunctions.py index 2f556c5..a69de7e 100755 --- a/sharedfunctions.py +++ b/sharedfunctions.py @@ -686,6 +686,6 @@ def getapplicationproperties(): myparams=dict(line.strip().split('=') for line in open(prop_file) if line[0].isalpha()) print(myparams) - return myparms + return myparams