generated from IBM/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.19.0 - see what's new in README.md - RM-only: changeset create/deli…
…ver, create folder, both with simple examples
- Loading branch information
Showing
44 changed files
with
4,146 additions
and
3,070 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 0.18.0 | ||
current_version = 0.19.0 | ||
commit = True | ||
tag = True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
app = 'elmoslcquery' | ||
description = 'Commandline OSLC query for ELM' | ||
version = '0.18.0' | ||
version = '0.19.0' | ||
license = 'MIT' | ||
author_name = 'Ian Barnard' | ||
author_mail = '[email protected]' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
## | ||
## © Copyright 2023- IBM Inc. All rights reserved | ||
# SPDX-License-Identifier: MIT | ||
## | ||
|
||
# example of creating a folder path | ||
# provide on the commandline (each surrounded by " if it contains a space) the apths of folders you want to create - paths MUST start with / | ||
|
||
# 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/ | ||
|
||
# Also see section 2 of https://jazz.net/library/article/1197 | ||
|
||
# | ||
# folders are found using a OSLC Query capability for folders - this returns one level at a time | ||
# so will likely need a series of queries to find an existing folder | ||
# this is all implemented in load_fodlers() | ||
# new create_folders() will create a folder path and update the loaded folders so a full reload isn't needed | ||
# | ||
|
||
import logging | ||
import os.path | ||
import sys | ||
import time | ||
|
||
import lxml.etree as ET | ||
|
||
import elmclient.server as elmserver | ||
import elmclient.utils as utils | ||
import elmclient.rdfxml as rdfxml | ||
|
||
# setup logging - see levels in utils.py | ||
#loglevel = "INFO,INFO" | ||
loglevel = "TRACE,OFF" | ||
levels = [utils.loglevels.get(l,-1) for l in loglevel.split(",",1)] | ||
if len(levels)<2: | ||
# assert console logging level OFF if not provided | ||
levels.append(None) | ||
if -1 in levels: | ||
raise Exception( f'Logging level {loglevel} not valid - should be comma-separated one or two values from DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF' ) | ||
utils.setup_logging( filelevel=levels[0], consolelevel=levels[1] ) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
utils.log_commandline( os.path.basename(sys.argv[0]) ) | ||
|
||
jazzhost = 'https://jazz.ibm.com:9443' | ||
|
||
username = 'ibm' | ||
password = 'ibm' | ||
|
||
jtscontext = 'jts' | ||
rmcontext = 'rm' | ||
|
||
# the project+compontent+config that will be updated | ||
proj = "rm_optout_p1" | ||
comp = proj | ||
conf = f"{comp} Initial Stream" | ||
|
||
# caching control | ||
# 0=fully cached (but code below specifies queries aren't cached) - if you need to clear the cache, delet efolder .web_cache | ||
# 1=clear cache initially then continue with cache enabled | ||
# 2=clear cache and disable caching | ||
caching = 2 | ||
|
||
################################################################################## | ||
if __name__=="__main__": | ||
if len(sys.argv) < 2: | ||
raise Exception( 'Provide one or more space-separated paths on the commandline' ) | ||
|
||
|
||
print( f"Attempting to create paths '{sys.argv[1:]}' in project '{proj}' in configuration {conf}" ) | ||
print( f"Using credentials user '{username}' password '{password}'") | ||
|
||
# create our "server" which is how we connect to DOORS Next | ||
# 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) | ||
elmserver.setupproxy(jazzhost,proxyport=8888) | ||
theserver = elmserver.JazzTeamServer(jazzhost, username, password, verifysslcerts=False, jtsappstring=f"jts:{jtscontext}", appstring='rm', cachingcontrol=caching) | ||
|
||
# create the RM application interface | ||
dnapp = theserver.find_app( f"rm:{rmcontext}", ok_to_create=True ) | ||
|
||
# open the project | ||
p = dnapp.find_project(proj) | ||
|
||
# find the component | ||
c = p.find_local_component(comp) | ||
comp_u = c.project_uri | ||
print( f"{comp_u=}" ) | ||
|
||
# select the configuration | ||
config_u = c.get_local_config(conf) | ||
print( f"{config_u=}" ) | ||
c.set_local_config(config_u) | ||
|
||
for path in sys.argv[1:]: | ||
|
||
thefolder = c.find_folder(path) | ||
|
||
# check if the path doesn't exist | ||
if thefolder is None: | ||
# have to create it! | ||
# get the parent | ||
thefolder = c.create_folder( path ) | ||
print( f"Folder '{path}' created uri is {thefolder.folderuri}" ) | ||
else: | ||
print( f"Folder '{path}' already exists" ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
## | ||
## © Copyright 2021- IBM Inc. All rights reserved | ||
# SPDX-License-Identifier: MIT | ||
## | ||
|
||
# extended example of using the type system import API, creating an automatically-named changeset, importing, delivering the CS | ||
# also see https://jazz.net/wiki/bin/view/Main/DNGTypeImport | ||
|
||
# the names for project/component/configs involved are hard-coded for simplicity | ||
|
||
|
||
import csv | ||
import datetime | ||
import logging | ||
import os.path | ||
import sys | ||
import time | ||
|
||
import lxml.etree as ET | ||
import tqdm | ||
|
||
import elmclient.server as elmserver | ||
import elmclient.utils as utils | ||
import elmclient.rdfxml as rdfxml | ||
|
||
|
||
# setup logging - see levels in utils.py - TRACE means you can use log2seq to get a html sequence diagram | ||
#loglevel = "INFO,INFO" | ||
loglevel = "TRACE,OFF" | ||
levels = [utils.loglevels.get(l,-1) for l in loglevel.split(",",1)] | ||
if len(levels)<2: | ||
# assert console logging level OFF if not provided | ||
levels.append(None) | ||
if -1 in levels: | ||
raise Exception( f'Logging level {loglevel} not valid - should be comma-separated one or two values from DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF' ) | ||
utils.setup_logging( filelevel=levels[0], consolelevel=levels[1] ) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
utils.log_commandline( os.path.basename(sys.argv[0]) ) | ||
|
||
jazzhost = 'https://jazz.ibm.com:9443' | ||
|
||
username = 'ibm' | ||
password = 'ibm' | ||
|
||
jtscontext = 'jts' | ||
rmcontext = 'rm' | ||
|
||
src_proj = "rm_optin_p1" | ||
src_comp = "rm_optin_p1" | ||
src_config = "rm_optin_p1 Initial Stream" | ||
tgt_proj = "rm_optin_p2" | ||
tgt_comp = "rm_optin_p2" | ||
tgt_config = "rm_optin_p2 Initial Stream" | ||
|
||
cs_name = "Typesystem import cs" | ||
|
||
# caching control | ||
# 0=fully cached (but code below specifies queries aren't cached) - if you need to clear the cache, delet efolder .web_cache | ||
# 1=clear cache initially then continue with cache enabled | ||
# 2=clear cache and disable caching | ||
caching = 2 | ||
|
||
|
||
################################################################################## | ||
if __name__=="__main__": | ||
|
||
# first file handler: | ||
datetimestamp = '{:%Y%m%d-%H%M%S}'.format(datetime.datetime.now()) | ||
csname = f"{cs_name} {datetimestamp}" | ||
# create our "server" which is how we connect to DOORS Next | ||
# 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) | ||
elmserver.setupproxy(jazzhost,proxyport=8888) | ||
theserver = elmserver.JazzTeamServer(jazzhost, username, password, verifysslcerts=False, jtsappstring=f"jts:{jtscontext}", appstring='rm', cachingcontrol=caching) | ||
|
||
# create the RM application interface | ||
dnapp = theserver.find_app( f"rm:{rmcontext}", ok_to_create=True ) | ||
|
||
# open the source project | ||
src_p = dnapp.find_project(src_proj) | ||
|
||
# find the component | ||
src_c = src_p.find_local_component(src_comp) | ||
src_comp_u = src_c.project_uri | ||
print( f"{src_comp_u=}" ) | ||
|
||
# select the configuration | ||
src_config_u = src_c.get_local_config(src_config) | ||
print( f"{src_config_u=}" ) | ||
src_c.set_local_config(src_config_u) | ||
|
||
|
||
# open the target project | ||
tgt_p = dnapp.find_project(tgt_proj) | ||
|
||
# find the component | ||
tgt_c = tgt_p.find_local_component(tgt_comp) | ||
tgt_comp_u = tgt_c.project_uri | ||
print( f"{tgt_comp_u=}" ) | ||
|
||
# select the configuration | ||
tgt_config_u = tgt_c.get_local_config(tgt_config) | ||
print( f"{tgt_config_u=}" ) | ||
tgt_c.set_local_config(tgt_config_u) | ||
|
||
if tgt_config_u is None or src_config_u is None: | ||
raise Exception( "Source or target config not found!" ) | ||
|
||
# create the changeset in the target config | ||
cs_u = tgt_c.create_changeset( csname ) | ||
print( f"{cs_u=}" ) | ||
|
||
# switch to the changeset config for the import | ||
tgt_c.set_local_config(cs_u) | ||
|
||
# find the CreationFactory URI for type-delivery session | ||
typeimport_u = tgt_c.get_factory_uri( resource_type="http://www.ibm.com/xmlns/rdm/types/TypeImportSession" ) | ||
|
||
# create the RDF body with the source and target configurations | ||
content = f"""<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:types="http://www.ibm.com/xmlns/rdm/types/"> | ||
<types:TypeSystemCopySession> | ||
<types:target rdf:resource="{tgt_config_u}"/> | ||
<types:source rdf:resource="{src_config_u}"/> | ||
</types:TypeSystemCopySession> | ||
</rdf:RDF>""" | ||
|
||
# initiate the delivery session - if successful will return 202 with a task tracker location | ||
response = tgt_c.execute_post_rdf_xml( reluri=typeimport_u, data=content, cacheable=False, intent="Initiate typesystem import",action='start following task tracker' ) | ||
logger.debug( f" {response.status_code=} {response=}" ) | ||
|
||
# get the location | ||
location = response.headers.get('Location') | ||
|
||
# check for 202 and location | ||
if response.status_code == 202 and location is not None: | ||
# wait for the tracker to finished | ||
result = tgt_c.wait_for_tracker( location, interval=1.0, progressbar=True, msg=f"Importing typesystem") | ||
# TODO: success result is now the xml of the verdict | ||
# result None is a success! | ||
print( f"{result=}" ) | ||
if result is not None and type(result) is not str: | ||
print( f"Failed Result={result}" ) | ||
else: | ||
print( f"Success! {result=}" ) | ||
else: | ||
raise Exception( "Typesystem import failed!" ) | ||
|
||
# now deliver the changeset | ||
tgt_c.deliver_changeset() | ||
|
Oops, something went wrong.