total_items = resultdata['count']

    itemlist = resultdata['items']
    returned_items = len(itemlist)

    if total_items == 0: print("Note: No items returned.")
    else:
        # get the path for each report and add it to the result set
        # this is not very efficient. I will try to improve it

        for i in range(0, returned_items):

            id = itemlist[i]["id"]
            name = itemlist[i]["name"]
            path_to_report = getpath("/reports/reports/" + id)

            # add the path as an attribute of flag for delete
            if path_to_report.startswith(folderpath):
                itemlist[i]["fullreport"] = path_to_report + name
            else:
                itemlist[i]["fullreport"] = 'delete'

# remove non matches before printing
        newlist = [i for i in itemlist if not (i['fullreport'] == 'delete')]
        resultdata['items'] = newlist
        resultdata['count'] = len(newlist)

        printresult(resultdata,
                    output_style,
                    colsforcsv=[
Exemple #2
0
# Define exception handler so that we only output trace info from errors when in debug mode
def exception_handler(exception_type,
                      exception,
                      traceback,
                      debug_hook=sys.excepthook):
    if debug:
        debug_hook(exception_type, exception, traceback)
    else:
        print "%s: %s" % (exception_type.__name__, exception)


sys.excepthook = exception_handler

parser = argparse.ArgumentParser()
parser.add_argument(
    "-u",
    "--objecturi",
    help=
    "Object URI of folder or other object that can be contained within a folder.",
    required=True)
parser.add_argument("-d", "--debug", action='store_true', help="Debug")
args = parser.parse_args()
objecturi = args.objecturi
debug = args.debug

path = getpath(objecturi)

if path is not None:
    print path
Exemple #3
0
#First, use the /folders/{folderId}/members endpoint to ask for a list of objects which are in the folder passed in by objecturi
#See Folders API documentation in swagger at http://swagger.na.sas.com/apis/folders/v1/apidoc.html#op:getAncestors
endpoint = objecturi + '/members'
if recursive:
    endpoint = endpoint + '?recursive=true&limit=10000'
else:
    endpoint = endpoint + '?limit=10000'
method = 'get'

#make the rest call
members_result_json = callrestapi(endpoint, method)

if debug:
    print(members_result_json)
    #print('members_result_json is a '+type(members_result_json).__name__+' object') #members_result_json is a dict object

members = members_result_json['items']

for member in members:
    outstr = ''
    path = getpath(member['uri'])
    outstr = outstr + path + ',' + member['id'] + ',' + member[
        'name'] + ',' + member['type']
    if 'description' in member:
        outstr = outstr + ',' + member['description']
    else:
        outstr = outstr + ','
    outstr = outstr + ',' + member['uri']
    print outstr