CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cmstc.py
Go to the documentation of this file.
1 """CMS TagCollector Python API
2 """
3 
4 __author__ = "Miguel Ojeda"
5 __copyright__ = "Copyright 2010-2011, CERN CMS"
6 __credits__ = ["Miguel Ojeda"]
7 __license__ = "Unknown"
8 __maintainer__ = "Miguel Ojeda"
9 __email__ = "mojedasa@cern.ch"
10 __status__ = "Staging"
11 
12 _tagcollector_url = 'https://cmstags.cern.ch/tc/'
13 
14 import urllib
15 import urllib2
16 import cookielib
17 try:
18  import json
19 except ImportError:
20  import simplejson as json
21 import getpass
22 import ws_sso_content_reader
23 
25  """CMS TagCollector Python API"""
26 
27  def __init__(self,useCert=False):
28  self._url = _tagcollector_url
29  self.useCert = useCert
30  self.login = False
31  if self.useCert:
32  self.login = True
33  self._cj = cookielib.CookieJar()
34  self._opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self._cj))
35 
36  def __del__(self):
37  if self.login: self.signOut()
38 
39  def _open(self, page, params = None, data = None):
40  url = self._url + page + '?'
41  if params:
42  url += urllib.urlencode(params)
43  if data:
44  data = urllib.urlencode(data)
45  if self.useCert:
46  return ws_sso_content_reader.getContent(url, '~/.globus/usercert.pem', '~/.globus/userkey.pem', data)
47  try:
48  return self._opener.open(url, data).read()
49  except urllib2.HTTPError, e:
50  raise Exception(e.read().strip())
51 
52  def _openjson(self, page, params = None, data = None):
53  return json.loads(self._open(page, params, data))
54 
55  def signIn(self, username, password):
56  if self.useCert: return
57  """Sign in to TagCollector."""
58  self._open('signIn', data = {'password': password, 'user_name': username})
59  self.login = True
60 
61  def signInInteractive(self):
62  if self.useCert: return
63  """Sign in to TagCollector, asking for the username and password."""
64  username = raw_input('Username: ')
65  password = getpass.getpass()
66  self.signIn(username, password)
67  return username
68 
69  def signOut(self):
70  if self.useCert: return
71  """Sign out of TagCollector."""
72  self._open('signOut')
73  self.login = False
74 
75  def getPackageTags(self, package):
76  """Get the tags published in TagCollector for a package.
77  Note: TagCollector's published tags are a subset of CVS' tags."""
78  return self._openjson('public/py_getPackageTags', {'package': package})
79 
80  def getPackageTagDescriptionFirstLine(self, package, tag):
81  """Get the first line of the descriptions of a tag."""
82  return self._openjson('public/py_getPackageTagDescriptionFirstLine', {'package': package, 'tag': tag})
83 
84  def getPackageTagReleases(self, package, tag):
85  """Get the releases where a tag is."""
86  return self._openjson('public/py_getPackageTagReleases', {'package': package, 'tag': tag})
87 
88  def getReleasesTags(self, releases, diff = False):
89  """Get the tags of one or more release.
90  Optionally, return only the tags that differ between releases."""
91  releases = json.dumps(releases)
92  diff = json.dumps(diff)
93  return self._openjson('public/py_getReleasesTags', {'releases': releases, 'diff': diff})
94 
95  def getReleaseTags(self, release):
96  """Get the tags of one release."""
97  return self.getReleasesTags((release, ))
98 
99  def getTagsetTags(self, tagset):
100  """Get the tags of one tagset."""
101  return self._openjson('public/py_getTagsetTags', {'tagset': tagset})
102 
103  def getTagsetInformation(self, tagset):
104  """Get the information of one tagset."""
105  return self._openjson('public/py_getTagsetInformation', {'tagset': tagset})
106 
107  def getPendingApprovalTags(self, args, allow_multiple_tags = False):
108  """Prints Pending Approval tags of one or more releases,
109  one or more tagsets, or both (i.e. it joins all the tags).
110  Prints an error if several tags appear for a single package.
111  Suitable for piping to addpkg (note: at the moment,
112  addpkg does not read from stdin, use "-f" instead)."""
113  args = json.dumps(args)
114  allow_multiple_tags = json.dumps(allow_multiple_tags)
115  return self._openjson('public/py_getPendingApprovalTags', {'args': args, 'allow_multiple_tags': allow_multiple_tags})
116 
117  def getTagsetsTagsPendingSignatures(self, user_name, show_all, author_tagsets, release_names = None):
118  """Prints Pending Signature tags of one or more releases,
119  one or more tagsets, or both (i.e. it joins all the tags).
120  Prints an error if several tags appear for a single package.
121  Suitable for piping to addpkg (note: at the moment,
122  addpkg does not read from stdin, use "-f" instead)."""
123  if not release_names == None:
124  return self._openjson('public/py_getTagsetsTagsPendingSignatures', {'user_name': user_name, 'show_all': show_all, 'author_tagsets': author_tagsets, 'release_names': json.dumps(release_names)})
125  else:
126  return self._openjson('public/py_getTagsetsTagsPendingSignatures', {'user_name': user_name, 'show_all': show_all, 'author_tagsets': author_tagsets})
127 
128  def commentTagsets(self, tagset_ids, comment):
129  """Comment one or more tagsets.
130  Requirement: Signed in."""
131  tagset_ids = json.dumps(tagset_ids)
132  if len(comment) < 1:
133  raise Exception("Error: Expected a comment.")
134  self._open('commentTagsets', {'tagset_ids': tagset_ids, 'comment': comment})
135 
136  def signTagsets(self, tagset_ids, comment = ''):
137  """Sign one or more tagsets.
138  Requirement: Signed in as a L2."""
139  tagset_ids = json.dumps(tagset_ids)
140  self._open('signTagsets', {'tagset_ids': tagset_ids, 'comment': comment})
141 
142  def signTagsetsAll(self, tagset_ids, comment = ''):
143  """Sign all one or more tagsets.
144  Requirement: Signed in as a top-level admin."""
145  tagset_ids = json.dumps(tagset_ids)
146  self._open('signTagsetsAll', {'tagset_ids': tagset_ids, 'comment': comment})
147 
148  def rejectTagsetsPendingSignatures(self, tagset_ids, comment = ''):
149  """Reject one or more tagsets Pending Signatures.
150  Requirement: Signed in as a L2s or as a Release Manager
151  for the tagset's release or as the author of the tagset."""
152  tagset_ids = json.dumps(tagset_ids)
153  self._open('rejectTagsetsPendingSignatures', {'tagset_ids': tagset_ids, 'comment': comment})
154 
155  def approveTagsets(self, tagset_ids, comment = ''):
156  """Approve one or more tagsets.
157  Requirement: Signed in as a Release Manager for each tagset's release."""
158  tagset_ids = json.dumps(tagset_ids)
159  self._open('approveTagsets', {'tagset_ids': tagset_ids, 'comment': comment})
160 
161  def bypassTagsets(self, tagset_ids, comment = ''):
162  """Bypass one or more tagsets.
163  Requirement: Signed in as a Release Manager for each tagset's release."""
164  tagset_ids = json.dumps(tagset_ids)
165  self._open('bypassTagsets', {'tagset_ids': tagset_ids, 'comment': comment})
166 
167  def rejectTagsetsPendingApproval(self, tagset_ids, comment = ''):
168  """Reject one or more tagsets Pending Approval.
169  Requirement: Signed in as a Release Manager."""
170  tagset_ids = json.dumps(tagset_ids)
171  self._open('rejectTagsetsPendingApproval', {'tagset_ids': tagset_ids, 'comment': comment})
172 
173  def removeTagsets(self, tagset_ids, comment = ''):
174  """Remove one or more tagsets from the History (i.e. stack of the release).
175  Requirement: Signed in as a Release Manager."""
176  tagset_ids = json.dumps(tagset_ids)
177  self._open('removeTagsets', {'tagset_ids': tagset_ids, 'comment': comment})
178 
180  """Get New Package Requests which are Pending Approval."""
181  return self._openjson('public/py_getPackagesPendingApproval')
182 
183  def getPackageManagersRequested(self, package):
184  """Get the Package Managers (administrators and developers) requested in a New Package Request."""
185  return self._openjson('public/py_getPackageManagersRequested', {'package': package})
186 
187  def search(self, term):
188  """Searches for releases, packages, tagsets, users and categories.
189  Requirement: Signed in."""
190  return self._openjson('search', {'term': term})
191 
192  def approvePackage(self, package):
193  """Approve a New Package Request.
194  Requirement: Signed in as a Creator (i.e. people in the top-level .admin/developers file).
195  Warning: This does *not* create the package in CVS."""
196  self._open('approveNewPackageRequest', {'package_name': package})
197 
198  def getIBs(self, filt = '', limit = 10):
199  """Get the name and creation date of Integration Builds.
200  By default, it only returns the latest 10 IBs.
201  Optionally, filter by name."""
202  return self._openjson('public/py_getIBs', {'filt': filt, 'limit': limit})
203 
204  def deprecateReleases(self, *releases):
205  """ Deprecate releases"""
206  if not self.login:
207  raise Exception("Error: Not logged in?!")
208  self._open('deprecateReleases', {"releases": ",".join(releases)})
209 
210  def createRelease(self, base_release_name, new_release_name, new_state, new_private, new_type, new_description, release_managers, copy_queues, tags):
211  """Create a new release.
212  Requirement: Signed in as a release manager."""
213  if self.login:
214  self._open('copyRelease', {'release_name': base_release_name, 'new_release_name': new_release_name, 'new_state': new_state, 'new_private': new_private, 'new_type': new_type, 'new_description': new_description, 'release_managers': release_managers, 'copy_queues': copy_queues, 'tags': tags})
215  else:
216  raise Exception("Error: Not logged in?!")
217 
218  def requestCustomIB(self, release_name, architectures, tags):
219  """Request a CustomIB.
220  Requirement: Signed in."""
221  if self.login:
222  self._open('requestCustomIB', {'release_name': release_name, 'architecture_names': architectures, 'tags': tags})
223  else:
224  raise Exception("Error: Not logged in?!")
225 
226  def getReleaseArchitectures(self, release, default='0'):
227  """Returns release architectures."""
228  return self._openjson('public/py_getReleaseArchitectures', {'release': release, 'default': default})
def rejectTagsetsPendingSignatures
Definition: cmstc.py:148
def getPackageManagersRequested
Definition: cmstc.py:183
def signInInteractive
Definition: cmstc.py:61
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
def getReleasesTags
Definition: cmstc.py:88
def signTagsetsAll
Definition: cmstc.py:142
def getPackagesPendingApproval
Definition: cmstc.py:179
def getTagsetTags
Definition: cmstc.py:99
def approveTagsets
Definition: cmstc.py:155
def getTagsetInformation
Definition: cmstc.py:103
def getTagsetsTagsPendingSignatures
Definition: cmstc.py:117
def getReleaseArchitectures
Definition: cmstc.py:226
def getPackageTagReleases
Definition: cmstc.py:84
def getReleaseTags
Definition: cmstc.py:95
def rejectTagsetsPendingApproval
Definition: cmstc.py:167
def commentTagsets
Definition: cmstc.py:128
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def getPackageTags
Definition: cmstc.py:75
list object
Definition: dbtoconf.py:77
def getPackageTagDescriptionFirstLine
Definition: cmstc.py:80
def getPendingApprovalTags
Definition: cmstc.py:107
def approvePackage
Definition: cmstc.py:192
def requestCustomIB
Definition: cmstc.py:218