diff --git a/Tools/PyUtils/bin/get-tag-diff.py b/Tools/PyUtils/bin/get-tag-diff.py index c5a9d2664f082f366bfb770ccdbf6c078e7564cc..93ed4037df41441da2c274e8f410de4535385788 100755 --- a/Tools/PyUtils/bin/get-tag-diff.py +++ b/Tools/PyUtils/bin/get-tag-diff.py @@ -89,22 +89,21 @@ def parseCMAKEPath(dumpfilename): if len(allProjects)==0 or allProjects[0]=="": return None - print allProjects,allProjects + #print "allProjects:",allProjects cmakePackages=dict() for projPath in reversed(allProjects): #We want to scan projects in reverse order (so that packages patch overwrite others) if not os.access(projPath+"/packages.txt",os.R_OK): print "WARNING, no packages.txt file found in",projPath else: - thisProject=None + #Guess project name: + thisProject=projPath.split("/")[-4] + #print "Current project is ",thisProject packagesFile=open(projPath+"/packages.txt") for l in packagesFile: ls=l.strip() - if thisProject is None and ls.startswith("# Packages built in"): - thisProject=ls.split(" ")[4] - #print "Current project",thisProject - - if not ls.startswith("#"): + #print "Working on",ls + if not ls.startswith("#") and len(ls.split(" "))>1: packagePath=ls.split(" ")[0] fullPackVersion=ls.split(" ")[1] packageName=fullPackVersion.split("-")[0] @@ -163,7 +162,7 @@ def getPackageDict(setupcmd): asetupscriptfile.write("cd %s\n" % tempdir) asetupscriptfile.write("set CMTPATH=""\n") asetupscriptfile.write("set CMAKE_PREFIX_PATH=""\n") - asetupscriptfile.write("source /afs/cern.ch/atlas/software/dist/AtlasSetup/scripts/asetup.sh %s\n" %setupcmd) + asetupscriptfile.write("source /afs/cern.ch/atlas/software/dist/AtlasSetup/scripts/asetup.sh %s,notest\n" %setupcmd) #asetupscriptfile.write("echo $CMTPATH\n") #asetupscriptfile.write("echo $CMAKE_PREFIX_PATH\n") asetupscriptfile.write("if [ $? -ne 0 ]; then \n exit -1\nfi\n") @@ -171,7 +170,7 @@ def getPackageDict(setupcmd): asetupscriptfile.write("echo $CMAKE_PREFIX_PATH > cmakepath.txt\n") asetupscriptfile.close() - sc=subprocess.call(["/bin/bash",asetupscriptname]) + sc=subprocess.call(["/bin/bash",asetupscriptname],env=dict()) if sc!=0: print "ERROR asetup %s failed!" % setupcmd diff --git a/Tools/PyUtils/python/AmiLib.py b/Tools/PyUtils/python/AmiLib.py index fea74983e1c4bde5e0cbf9d4fd6a98e56ba6b27e..3a13493b033524e9edd27c326c8f6f66a3afdd7a 100644 --- a/Tools/PyUtils/python/AmiLib.py +++ b/Tools/PyUtils/python/AmiLib.py @@ -144,7 +144,7 @@ def badresult(result, checkForValidRows=True, expectCommandStatus=True): ## @brief Convert the AMI result rows into a list of dictionaries # @param take_rowsets List of rowsets to use: # None=use all -# string=take rowset if type matches the string +# list of strings=take rowset if type matches the string # @note The rowset type is added to each element dictionary def amijsontodict(result, take_rowsets=None): take_rowset_indexes = [] @@ -166,6 +166,19 @@ def amijsontodict(result, take_rowsets=None): answer.append(answer_dict) return answer +## @brief Iterator over a 'tree' AMI result set +# @param tree Root of AMI tree dictionary +def tree_iter(tree): + for d in tree: + y = {} + for k,v in d.iteritems(): + if k=='treeBranch': + for sub in tree_iter(v): + yield sub + else: + y[k] = v + yield y + ### classes ------------------------------------------------------------------- class PyUtilsAMIException(Exception): @@ -320,7 +333,7 @@ class Client(object): if bad: errmsg = "Bad AMI result for projects of package {0}: {1}".format(full_pkg_name, msg) self.msg.error(errmsg) - raw_result_list = amijsontodict(result) + raw_result_list = amijsontodict(result,['Package_version_history']) self.msg.debug(pprint.pformat(raw_result_list)) # Use a set to remove duplicated results in the key we're interested in @@ -418,14 +431,12 @@ class Client(object): return self.get_releases(project, lambda x : x!='terminated') def get_releases(self, project, relStatusCond=lambda x : True): - """return the list of open releases for a given ``project``""" + """return the list of releases for a given ``project``""" - result = self.exec_cmd(cmd='SearchQuery', - args={'-sql': '"select * from releases r,groups g where g.identifier=r.groupFK and g.groupName=\'{0}\'"'.format(project), - '-project': 'TagCollector', - '-processingStep': 'production'}, - defaults=False - ) + result = self.exec_cmd(cmd='TCFormGetReleaseTreeDevView', + args={'-groupName' : project, + '-expandedRelease' : '*', + }) bad, msg = badresult(result) if bad: @@ -433,11 +444,12 @@ class Client(object): self.msg.error(errmsg) raise PyUtilsAMIException(errmsg) - result_list = amijsontodict(result) releases = [] - for release in result_list: - if 'releaseName' in release and '-' not in release['releaseName']: - releases.append(release['releaseName']) + for r in tree_iter(result['AMIMessage'][0]['Result'][0]['tree']): + if not '@releaseName' in r: continue + if relStatusCond(r['@status']): + releases.append(r['@releaseName']) + releases.sort(key=lambda x: [int(y) if y.isdigit() else 0 for y in x.split('.')]) self.msg.debug(pprint.pformat(releases)) return releases diff --git a/Tools/PyUtils/python/AthFile/impl.py b/Tools/PyUtils/python/AthFile/impl.py index 115139ed00e51e350fb9e5f64ff0b5fbd8e4afa1..bcebc88f3f0c20301cd4b81cca553fe8f11bddaf 100644 --- a/Tools/PyUtils/python/AthFile/impl.py +++ b/Tools/PyUtils/python/AthFile/impl.py @@ -7,7 +7,7 @@ from __future__ import with_statement -__version__ = "$Revision: 723532 $" +__version__ = "$Revision: 768238 $" __author__ = "Sebastien Binet" __doc__ = "implementation of AthFile-server behind a set of proxies to isolate environments" @@ -29,7 +29,7 @@ except: pass ### globals ------------------------------------------------------------------- -DEFAULT_AF_RUN = os.environ.get('DEFAULT_AF_RUN', False) +DEFAULT_AF_RUN = os.environ.get('DEFAULT_AF_RUN', True) '''Revert to old file peeking via Athena sub-process if True.''' DEFAULT_AF_CACHE_FNAME = os.environ.get('DEFAULT_AF_CACHE_FNAME', diff --git a/Tools/PyUtils/python/scripts/__init__.py b/Tools/PyUtils/python/scripts/__init__.py index b71a3ab330a9c4d06da893358f447c3c430d5b0d..9ad4c7039df940c4338d71c13b562e4d6614c83f 100644 --- a/Tools/PyUtils/python/scripts/__init__.py +++ b/Tools/PyUtils/python/scripts/__init__.py @@ -30,5 +30,8 @@ acmdlib.register('cmt.new-asgtool', 'PyUtils.scripts.cmt_newasgtool:main') acmdlib.register('cmt.new-pyalg', 'PyUtils.scripts.cmt_newpyalg:main') acmdlib.register('cmt.new-jobo', 'PyUtils.scripts.cmt_newjobo:main') acmdlib.register('cmt.new-analysisapp', 'PyUtils.scripts.cmt_newanalysisapp:main') + +acmdlib.register('jira.issues', 'PyUtils.scripts.jira_issues:main') +# acmdlib.register('jira.issue', 'PyUtils.scripts.jira_issue:main') ## diff --git a/Tools/PyUtils/python/scripts/cmt_newasgtool.py b/Tools/PyUtils/python/scripts/cmt_newasgtool.py index e8ccea20c15afbaafad789626858deb649aedfba..f52a363b923b556d621d9b40cce188eb30dce20c 100644 --- a/Tools/PyUtils/python/scripts/cmt_newasgtool.py +++ b/Tools/PyUtils/python/scripts/cmt_newasgtool.py @@ -9,7 +9,7 @@ from __future__ import with_statement -__version__ = "$Revision: 753292 $" +__version__ = "$Revision: 756300 $" __author__ = "Will Buttinger" __doc__ = "streamline and ease the creation of new AsgTool" @@ -161,6 +161,10 @@ class I%(klass)s : public virtual asg::IAsgTool { #include "AsgTools/AnaToolHandle.h" #include "%(pkg)s/I%(klass)s.h" +//next line needed for using the concrete tool in this unit test +//external users cannot do this +#include "../Root/%(namespace_klass)s.cxx" + using namespace asg::msgUserCode; int main() { @@ -177,6 +181,9 @@ int main() { //myTool->isSelected(....); put test code here + //next line is how to gain access to concrete instance of the tool ... only ok for unit tests + //%(namespace2)s%(klass)s* tool = dynamic_cast<%(namespace2)s%(klass)s*>(&*myTool); + return 0; //zero = success } """ @@ -189,6 +196,11 @@ int main() { #include "AsgTools/UnitTest.h" #include <gtest/gtest.h> +//next line needed for using the concrete tool in this unit test +//external users cannot do this +#include "../Root/%(namespace_klass)s.cxx" + + using namespace asg::msgUserCode; //first arg: name of fixture (if applicable), second arg: name of the test (special prefixes have special meanings) @@ -201,6 +213,11 @@ TEST (%(klass)sTest, basicTest) { // ASSERT_TRUE( myTool->isSelected( ...goodObject.. ) ); + //next line is how to gain access to concrete instance of the tool ... only ok for unit tests + //%(namespace2)s%(klass)s* tool = dynamic_cast<%(namespace2)s%(klass)s*>(&*myTool); + + + } int main (int argc, char **argv) @@ -283,20 +300,23 @@ def main(args): myfile.write("library %s *.cxx ../Root/*.cxx components/*.cxx\n" % (full_pkg_name)) myfile.write("apply_pattern component_library\n") - if not foundBaseComps or len(libraryLines)>0: + if not foundBaseComps or len(libraryLines)>0 or not hasxAODBase or not hasAtlasROOT: #must add a use statement to the requirements file #put inside public blocks lineCount=0 inPrivate=False if not foundBaseComps: print "::: INFO Adding AsgTools to requirements file" + if not hasAtlasROOT: print "::: INFO Adding AtlasROOT to requirements file" + if not hasxAODBase: print "::: INFO Adding xAODBase to requirements file" for line in fileinput.input('cmt/requirements', inplace=1): lineCount+=1 - if not foundBaseComps and lineCount==lastUse+1: + if (not foundBaseComps or not hasAtlasROOT or not hasxAODBase) and lineCount==lastUse+1: if inPrivate: print "end_private" - print "" - print "use AsgTools AsgTools-* Control/AthToolSupport" - print "" + if not foundBaseComps: + print "" + print "use AsgTools AsgTools-* Control/AthToolSupport" + print "" if not hasAtlasROOT: print "#uncomment the next line to use ROOT libraries in your package" print "#use AtlasROOT AtlasROOT-* External" diff --git a/Tools/PyUtils/python/scripts/jira_issues.py b/Tools/PyUtils/python/scripts/jira_issues.py new file mode 100644 index 0000000000000000000000000000000000000000..9687e459b48173930db603aad887c394fe707339 --- /dev/null +++ b/Tools/PyUtils/python/scripts/jira_issues.py @@ -0,0 +1,104 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +# @file PyUtils.scripts.jira +# @purpose Interface with CERN JIRA instance +# @author Edward Moyse +# @date July 2016 + +__version__ = "$Revision: 717788 $" +__doc__ = "Interface with CERN JIRA instance." +__author__ = "Edward Moyse" + +# Tried to use jira module, but apparently doesn't support cookie-based authenticatoon. + +# pip install --user requests +import requests +import os +import PyUtils.acmdlib as acmdlib + +### functions ----------------------------------------------------------------- + +def queryJira(querystring, cookies): + # Now, let's make this request! + base_url = "https://its.cern.ch/jira/rest/api/2/" + url = base_url+querystring + + r = requests.get(url, cookies=cookies) + if r.status_code != 200: + if r.status_code == 401: + print 'Authorisation has failed. Have you got a valid SSO cookie? If not, re-run "cern-get-sso-cookie -u https://its.cern.ch/jira/loginCern.jsp -o jira.txt" ' + else: + print "Something has gone wrong! The response is: ", r.text + return + + import json + response = json.loads(r.text) + return response + +@acmdlib.command(name='jira.issues') +@acmdlib.argument('-c', '--cookies', + required=False, + default = 'jira.txt', + help='the CERN SSO cookies file') +@acmdlib.argument('-r', '--release', + required=False, + help='Limit the response to the specified release') +@acmdlib.argument('-m', '--myissues', + action='store_true', + default=True, + required=False, + help='Limit the response your own issues') +@acmdlib.argument('-q', '--query', + required=False, + help='Use the specified query string i.e. "search?jql=assignee=currentUser()+and+resolution=Unresolved"') +@acmdlib.argument('-s', '--status', + required=False, + help='Limit the search to issues with this status, e.g. "Open"') + +def main(args): + """Interface to the CERN JIRA instance""" + + import requests + + #authentication + try: + cookiesFile = file(args.cookies, 'r') + cookies = {} + for line in cookiesFile: + text = line.split() + if 'JSESSIONID' in line: + cookies['JSESSIONID'] = text[-1] + if 'atlassian.xsrf.token' in line: + cookies['atlassian.xsrf.token'] = text[-1] + except: + print "Problems opening cookie file at ", args.cookies + return 1 + + querystring = "" + if (args.query): + print "Will use the following search string: ",args.query + querystring = args.query + else: + querystring = "search?jql=resolution=Unresolved" + if (args.myissues): + querystring += "+AND+assignee=currentUser()" + if (args.release): + querystring += "+AND+affectedVersion="+args.release + if (args.status): + querystring += "+AND+status="+args.status + + response = queryJira(querystring, cookies) + if not response: + return 1 + + # Now lets get some information out + issues = response['issues'] + print + print 'Key'.ljust(20), 'Summary'.ljust(20) + print '---'.ljust(20), '-------'.ljust(20) + for issue in issues: + print issue['key'].ljust(20), issue['fields']['summary'].ljust(20) + return + + + \ No newline at end of file diff --git a/Tools/PyUtils/python/scripts/tc_submit_tag.py b/Tools/PyUtils/python/scripts/tc_submit_tag.py index 0fcb4fe11f70fb95424c0f918f016819325ef5a8..d98ddc9dbf89a35f2bec4830642c99e4badc31af 100644 --- a/Tools/PyUtils/python/scripts/tc_submit_tag.py +++ b/Tools/PyUtils/python/scripts/tc_submit_tag.py @@ -5,7 +5,7 @@ # @author Sebastien Binet # @date February 2010 -__version__ = "$Revision: 717788 $" +__version__ = "$Revision: 766754 $" __doc__ = "Submit one or more TAGs to TagCollector." __author__ = "Sebastien Binet, Frank Winklmeier" @@ -238,7 +238,9 @@ def main(args): for p in pkg_list: if not 'packageTag' in p: pkg = (p['packagePath']+p['packageName']).strip('/') # CMTise path - p['packageTag'] = cmt.CmtWrapper().get_latest_pkg_tag(pkg) + #p['packageTag'] = cmt.CmtWrapper().get_latest_pkg_tag(pkg) + from PyUtils.WorkAreaLib import get_latest_pkg_tag + p['packageTag'] = get_latest_pkg_tag(pkg) print 'Using latest tag %s' % (p['packageTag']) # query for missing options