Browse Source

Bug/unicode (#113)

* teext encode ascii

* bracket remove

* unicodeliterals

* unicode fixes

* unicode fixes

* update exportfoldertree.py

Co-authored-by: cloud-user <cloud-user@race.sas.com>
master
Gerry Nelson 3 years ago
committed by GitHub
parent
commit
024df0138b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      exportfoldertree.py
  2. 1
      listgroupsandmembers.py
  3. 4
      listmemberswithpath.py
  4. 18
      sharedfunctions.py

32
exportfoldertree.py

@ -11,6 +11,7 @@
#
# Change History
#
# SEP2022 Added option to specify the root folder to start at
#
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
#
@ -28,7 +29,7 @@
#
# Import Python modules
import argparse, sys, subprocess, uuid, time, os, glob
import argparse, sys, subprocess, uuid, time, os, glob, json
from sharedfunctions import getfolderid, callrestapi,getapplicationproperties
@ -44,11 +45,14 @@ cliexe=propertylist["sascli.executable"]
clicommand=os.path.join(clidir,cliexe)
# 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 = argparse.ArgumentParser(description="Export the complete Viya folder tree or the members of a folder to a set of Viya Packages.")
parser.add_argument("-d","--directory", help="Directory to store Export Packages",required='True')
parser.add_argument("-f","--folder", help="Folder to start export at (root is default)",default="NONE")
parser.add_argument("-q","--quiet", help="Suppress the are you sure prompt.", action='store_true')
args= parser.parse_args()
basedir=args.directory
folder=args.folder
quietmode=args.quiet
@ -79,11 +83,22 @@ if areyousure.upper() =='Y':
for file in filelist:
os.remove(file)
# retrieve root folders
reqtype='get'
if folder !='NONE':
folderinfo=getfolderid(folder)
results=(folderinfo[3])
folderid=results["id"]
reqval='/folders/folders/'+folderid+'/members'
else:
# retrieve root folders
reqval='/folders/rootFolders'
resultdata=callrestapi(reqval,reqtype)
print(json.dumps(resultdata,indent=2))
# loop root folders
if 'items' in resultdata:
@ -96,11 +111,16 @@ if areyousure.upper() =='Y':
# export each folder and download the package file to the directory
for i in range(0,returned_items):
if folder=='NONE':
id=resultdata['items'][i]["id"]
folderuri='/folders/folders/'+id
else:
folderuri=resultdata['items'][i]["uri"]
package_name=str(uuid.uuid1())
json_name=resultdata['items'][i]["name"].replace(" ","")+'_'+str(i)
command=clicommand+' transfer export -u /folders/folders/'+id+' --name "'+package_name+'"'
command=clicommand+' transfer export -u '+folderuri+' --name "'+package_name+'"'
print(command)
subprocess.call(command, shell=True)
@ -114,7 +134,7 @@ if areyousure.upper() =='Y':
print(command)
subprocess.call(command, shell=True)
print("NOTE: Viya root folders exported to json files in "+path)
print("NOTE: Viya folders exported to json files in "+path)
else:
print("NOTE: Operation cancelled")

1
listgroupsandmembers.py

@ -34,6 +34,7 @@
debug=False
# Import Python modules
from __future__ import unicode_literals
import argparse
import sys
from sharedfunctions import callrestapi

4
listmemberswithpath.py

@ -38,6 +38,7 @@
debug=False
# Import Python modules
from __future__ import unicode_literals
import argparse
import sys
from sharedfunctions import callrestapi,getpath
@ -95,4 +96,7 @@ for member in members:
else:
outstr=outstr+','
outstr=outstr+','+member['uri']
try:
print(outstr)
except UnicodeEncodeError:
print(outstr.encode('ascii','replace'))

18
sharedfunctions.py

@ -56,6 +56,7 @@
# Import Python modules
from __future__ import print_function
from __future__ import unicode_literals
import requests
import sys
import json
@ -65,7 +66,6 @@ import collections
import inspect
import re
pp = pprint.PrettyPrinter(indent=4)
# validate rest api is not used at this time
@ -444,7 +444,13 @@ def csvresults(resultdata,columns=[]):
if z==numvals: sep=''
else: sep=','
if key != 'links' and key in columns: print('"'+str(val)+'"'+sep, end="")
if key != 'links' and key in columns:
try:
print('"'+str(val)+'"'+sep, end="")
except UnicodeEncodeError:
newval=val.encode('ascii','replace')
print('"'+str(newval)+'"'+sep, end="")
print("\n",end="")
@ -476,7 +482,13 @@ def csvresults(resultdata,columns=[]):
if z==numvals: sep=''
else: sep=','
if key != 'links': print('"'+str(val)+'"'+sep,end="")
if key != 'links':
try:
print('"'+str(val)+'"'+sep, end="")
except UnicodeEncodeError:
newval=val.encode('ascii','replace')
print('"'+str(newval)+'"'+sep, end="")
print("\n",end="")

Loading…
Cancel
Save