|
| 1 | +## |
| 2 | +## © Copyright 2023- IBM Inc. All rights reserved |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +## |
| 5 | + |
| 6 | +# example of creating a folder path |
| 7 | +# provide on the commandline (each surrounded by " if it contains a space) the apths of folders you want to create - paths MUST start with / |
| 8 | + |
| 9 | +# For info about folder create API see https://rhnaranjo.wordpress.com/2012/06/25/folder-support-added-to-rrc-4-0-oslc-rm-api-implementation/ |
| 10 | + |
| 11 | +# Also see section 2 of https://jazz.net/library/article/1197 |
| 12 | + |
| 13 | +# |
| 14 | +# folders are found using a OSLC Query capability for folders - this returns one level at a time |
| 15 | +# so will likely need a series of queries to find an existing folder |
| 16 | +# this is all implemented in load_fodlers() |
| 17 | +# new create_folders() will create a folder path and update the loaded folders so a full reload isn't needed |
| 18 | +# |
| 19 | + |
| 20 | +import logging |
| 21 | +import os.path |
| 22 | +import sys |
| 23 | +import time |
| 24 | + |
| 25 | +import lxml.etree as ET |
| 26 | + |
| 27 | +import elmclient.server as elmserver |
| 28 | +import elmclient.utils as utils |
| 29 | +import elmclient.rdfxml as rdfxml |
| 30 | + |
| 31 | +# setup logging - see levels in utils.py |
| 32 | +#loglevel = "INFO,INFO" |
| 33 | +loglevel = "TRACE,OFF" |
| 34 | +levels = [utils.loglevels.get(l,-1) for l in loglevel.split(",",1)] |
| 35 | +if len(levels)<2: |
| 36 | + # assert console logging level OFF if not provided |
| 37 | + levels.append(None) |
| 38 | +if -1 in levels: |
| 39 | + raise Exception( f'Logging level {loglevel} not valid - should be comma-separated one or two values from DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF' ) |
| 40 | +utils.setup_logging( filelevel=levels[0], consolelevel=levels[1] ) |
| 41 | + |
| 42 | +logger = logging.getLogger(__name__) |
| 43 | + |
| 44 | +utils.log_commandline( os.path.basename(sys.argv[0]) ) |
| 45 | + |
| 46 | +jazzhost = 'https://jazz.ibm.com:9443' |
| 47 | + |
| 48 | +username = 'ibm' |
| 49 | +password = 'ibm' |
| 50 | + |
| 51 | +jtscontext = 'jts' |
| 52 | +rmcontext = 'rm' |
| 53 | + |
| 54 | +# the project+compontent+config that will be updated |
| 55 | +proj = "rm_optout_p1" |
| 56 | +comp = proj |
| 57 | +conf = f"{comp} Initial Stream" |
| 58 | + |
| 59 | +# caching control |
| 60 | +# 0=fully cached (but code below specifies queries aren't cached) - if you need to clear the cache, delet efolder .web_cache |
| 61 | +# 1=clear cache initially then continue with cache enabled |
| 62 | +# 2=clear cache and disable caching |
| 63 | +caching = 2 |
| 64 | + |
| 65 | +################################################################################## |
| 66 | +if __name__=="__main__": |
| 67 | + if len(sys.argv) < 2: |
| 68 | + raise Exception( 'Provide one or more space-separated paths on the commandline' ) |
| 69 | + |
| 70 | + |
| 71 | + print( f"Attempting to create paths '{sys.argv[1:]}' in project '{proj}' in configuration {conf}" ) |
| 72 | + print( f"Using credentials user '{username}' password '{password}'") |
| 73 | + |
| 74 | + # create our "server" which is how we connect to DOORS Next |
| 75 | + # first enable the proxy so if a proxy is running it can monitor the communication with server (this is ignored if proxy isn't running) |
| 76 | + elmserver.setupproxy(jazzhost,proxyport=8888) |
| 77 | + theserver = elmserver.JazzTeamServer(jazzhost, username, password, verifysslcerts=False, jtsappstring=f"jts:{jtscontext}", appstring='rm', cachingcontrol=caching) |
| 78 | + |
| 79 | + # create the RM application interface |
| 80 | + dnapp = theserver.find_app( f"rm:{rmcontext}", ok_to_create=True ) |
| 81 | + |
| 82 | + # open the project |
| 83 | + p = dnapp.find_project(proj) |
| 84 | + |
| 85 | + # find the component |
| 86 | + c = p.find_local_component(comp) |
| 87 | + comp_u = c.project_uri |
| 88 | + print( f"{comp_u=}" ) |
| 89 | + |
| 90 | + # select the configuration |
| 91 | + config_u = c.get_local_config(conf) |
| 92 | + print( f"{config_u=}" ) |
| 93 | + c.set_local_config(config_u) |
| 94 | + |
| 95 | + for path in sys.argv[1:]: |
| 96 | + |
| 97 | + thefolder = c.find_folder(path) |
| 98 | + |
| 99 | + # check if the path doesn't exist |
| 100 | + if thefolder is None: |
| 101 | + # have to create it! |
| 102 | + # get the parent |
| 103 | + thefolder = c.create_folder( path ) |
| 104 | + print( f"Folder '{path}' created uri is {thefolder.folderuri}" ) |
| 105 | + else: |
| 106 | + print( f"Folder '{path}' already exists" ) |
| 107 | + |
0 commit comments