aboutsummaryrefslogtreecommitdiff
path: root/wmfphablib
diff options
context:
space:
mode:
Diffstat (limited to 'wmfphablib')
-rwxr-xr-xwmfphablib/bzlib.py70
-rwxr-xr-xwmfphablib/config.py3
-rwxr-xr-xwmfphablib/phabapi.py50
-rwxr-xr-xwmfphablib/rtlib.py11
-rw-r--r--wmfphablib/util.py9
5 files changed, 91 insertions, 52 deletions
diff --git a/wmfphablib/bzlib.py b/wmfphablib/bzlib.py
index f0c66ab..3b63ce6 100755
--- a/wmfphablib/bzlib.py
+++ b/wmfphablib/bzlib.py
@@ -8,25 +8,34 @@ dupe_literals = ['This bug has been marked as a duplicate of bug',
# Some issues are just missing instead of constant failures we skip
-missing = [15368, 15369, 15370, 15371, 15372, 15373, 15374]
+#missing = [15368, 15369, 15370, 15371, 15372, 15373, 15374]
+missing = []
def is_sensitive(name):
return name.strip().lower().startswith('security')
-def sanitize_project_name(product, component):
- """ translate bz product/component into valid project
- :param product: str
- :param component: str
+#def sanitize_project_name(product, component):
+# """ translate bz product/component into valid project
+# :param product: str
+# :param component: str
+# """
+# component_separator = '-'
+# product = re.sub('\s', '-', product)
+# product = product.replace('_', '-')
+# component = re.sub('\s', '-', component)
+# component = component.replace('_', '-')
+# component = component.replace('/', '-or-')
+# return "%s%s%s" % (product,
+# component_separator,
+# component)
+
+def sanitize_project_name(name):
+ """ translate bz product/component name into valid project
"""
- component_separator = '-'
- product = re.sub('\s', '-', product)
- product = product.replace('_', '-')
- component = re.sub('\s', '-', component)
- component = component.replace('_', '-')
- component = component.replace('/', '-or-')
- return "%s%s%s" % (product,
- component_separator,
- component)
+ name = re.sub('\s', '-', name)
+ name = name.replace('_', '-')
+ name = name.replace('/', '-or-')
+ return name
def build_comment(c, secstate):
""" takes a native bz comment dict and outputs
@@ -36,11 +45,14 @@ def build_comment(c, secstate):
# these indicate textual metadata history and should be
# preserved as literal
clean_c = {}
- clean_c['author'] = c['author'].split('@')[0]
+ #kspoon: another WM customization? We call it 'creator' for comment
+ #clean_c['author'] = c['author'].split('@')[0]
+ clean_c['creator'] = c['creator'].split('@')[0]
clean_c['creation_time'] = str(c['creation_time'])
clean_c['creation_time'] = int(float(c['creation_time']))
- if c['author'] != c['creator']:
- clean_c['creator'] = c['creator'].split('@')[0]
+ #kspoon: see above
+ #if c['author'] != c['creator']:
+ # clean_c['creator'] = c['creator'].split('@')[0]
clean_c['count'] = c['count']
if c['count'] == 0:
@@ -113,14 +125,19 @@ def status_convert(bz_status, bz_resolution):
declined we have decided not too -- even though we could
"""
- statuses = {'new': 'open',
+ statuses = {'unconfirmed': 'open',
+ 'confirmed': 'open',
+ 'in_progress': 'open',
'resolved': 'resolved',
- 'reopened': 'open',
- 'closed': 'resolved',
- 'verified': 'resolved',
- 'assigned': 'open',
- 'unconfirmed': 'open',
- 'patch_to_review': 'open'}
+ 'verified': 'resolved'}
+ #statuses = {'new': 'open',
+ # 'resolved': 'resolved',
+ # 'reopened': 'open',
+ # 'closed': 'resolved',
+ # 'verified': 'resolved',
+ # 'assigned': 'open',
+ # 'unconfirmed': 'open',
+ # 'patch_to_review': 'open'}
if bz_resolution.lower() in ['wontfix', 'later', 'worksforme']:
return 'declined'
@@ -147,7 +164,10 @@ def priority_convert(bz_priority):
'normal': 50,
'low': 25,
'lowest': 10}
- return priorities[bz_priority.lower()]
+ if bz_priority.lower() in priorities.keys():
+ return priorities[bz_priority.lower()]
+ else:
+ return priorities['unprioritized']
def see_also_transform():
"""convert see also listing to T123 refs in phab
diff --git a/wmfphablib/config.py b/wmfphablib/config.py
index 74c74e6..bbfee21 100755
--- a/wmfphablib/config.py
+++ b/wmfphablib/config.py
@@ -10,7 +10,8 @@ import ConfigParser
parser = ConfigParser.SafeConfigParser()
parser.read(cfile)
dbhost = parser.get('general', 'dbhost')
-dbslave = parser.get('general', 'dbslave')
+#dbslave = parser.get('general', 'dbslave')
+dbslave = None
file_upload_timeout = int(parser.get('general', 'file_upload_timeout'))
parser_mode = 'phmanifest'
phmanifest_user = parser.get(parser_mode, 'user')
diff --git a/wmfphablib/phabapi.py b/wmfphablib/phabapi.py
index 9f2dbe7..e1d753d 100755
--- a/wmfphablib/phabapi.py
+++ b/wmfphablib/phabapi.py
@@ -84,7 +84,16 @@ class phabapi:
auxiliary={"std:maniphest:external_reference":"%s" % (reference,),
"std:maniphest:security_topic": security})
+ def get_project_phid(self, name):
+ proj = self.con.project.query(names=[name])
+ if len(proj['data']) > 0:
+ phid = proj['data'][proj['data'].keys()[0]]['phid']
+ return phid
+ else:
+ return None
+
def ensure_project(self, project_name,
+ parent_phid=None,
pmembers=[],
view='public',
edit='public'):
@@ -93,28 +102,35 @@ class phabapi:
:param pmembers: list
:param view: str
:param edit str"""
- existing_proj = phabdb.get_project_phid(project_name)
+ existing_proj = self.con.project.query(names=[project_name])
+ log(str(existing_proj))
+ #existing_proj = phabdb.get_project_phid(project_name)
#print "EXISTING PROJ: ", existing_proj
#print "EXISTING PROJ TYPE: ", type(existing_proj)
#existing_proj = self.con.project.query(names=[project_name])
- if not existing_proj:
+ if len(existing_proj['data']) < 1:
log('need to create project(s) ' + project_name)
- try:
- new_proj = self.con.project.create(name=project_name, members=pmembers)
- #XXX: Bug where we have to specify a members array!
- except phabricator.APIError:
- pass
- phid = phabdb.get_project_phid(project_name)
- if not phid:
- raise Exception("Project %s does not exist still." % (project_name,))
- #existing_proj = self.con.project.query(names=[project_name])
- #log(str(existing_proj))
- #phid = existing_proj['data'][existing_proj['data'].keys()[0]]['phid']
- phabdb.set_project_policy(phid, view, edit)
+ #try:
+ print "name = %s" % project_name
+ print "members = %s" % pmembers
+ # obsoleted API call
+ #new_proj = self.con.project.create(name=project_name, members=pmembers)
+ tlist = [
+ {"type":"name", "value":project_name},
+ {"type":"view", "value":view},
+ {"type":"edit", "value":edit},
+ ]
+
+ if len(pmembers) > 0:
+ tlist.append( {"type":"members.set", "value":pmembers} )
+ if parent_phid != None:
+ tlist.append( {"type":"parent", "value":parent_phid} )
+
+ existing_proj = self.con.project.edit( transactions = tlist )
+ phid = existing_proj['object']['phid']
else:
- phid = existing_proj
- #phid = existing_proj['data'][existing_proj['data'].keys()[0]]['phid']
- log(project_name + ' exists')
+ print existing_proj
+ phid = existing_proj['data'].keys()[0]
return phid
def upload_file(self, name, data, viewPolicy, dump=False):
diff --git a/wmfphablib/rtlib.py b/wmfphablib/rtlib.py
index 53fdb32..67ffab0 100755
--- a/wmfphablib/rtlib.py
+++ b/wmfphablib/rtlib.py
@@ -1,11 +1,12 @@
enabled = ['codfw', 'ulsfo', 'pmtpa', 'ops-requests', 'network', 'esams', 'eqiad', 'core-ops',]
import util
-try:
- from rtppl import ppl as users
-except:
- util.notice("rtppl not found!")
- users = {}
+#kspoon: linaro doesn't use RT
+#try:
+# from rtppl import ppl as users
+#except:
+# util.notice("rtppl not found!")
+users = {}
import re
from datetime import datetime
diff --git a/wmfphablib/util.py b/wmfphablib/util.py
index 0100650..cf5daba 100644
--- a/wmfphablib/util.py
+++ b/wmfphablib/util.py
@@ -11,6 +11,7 @@ import syslog
import phabdb
import bzlib
+PHAB_PATH="/srv/phabricator"
def tflatten(t_of_tuples):
return [element for tupl in t_of_tuples for element in tupl]
@@ -78,7 +79,7 @@ def log(msg):
def notice(msg):
msg = unicode(msg)
- print "NOTICE: ", msg
+ #print "NOTICE: ", msg
log(msg)
def vlog(msg):
@@ -126,10 +127,10 @@ def get_index(seq, attr, value):
return next(index for (index, d) in enumerate(seq) if d[attr] == value)
def purge_cache():
- return runBash('/srv/phab/phabricator/bin/cache purge --purge-remarkup')
+ return runBash('%s/bin/cache purge --purge-remarkup' % PHAB_PATH)
def destroy_issue(id):
- return runBash('/srv/phab/phabricator/bin/remove destroy T%s --no-ansi --force' % (id,))
+ return runBash('%s/bin/remove destroy T%s --no-ansi --force' % (PHAB_PATH,id,))
def remove_issue_by_bugid(bugid, ref):
log("Removing issue by reference %s%s" % (ref, bugid))
@@ -159,7 +160,7 @@ def return_bug_list(dbcon=None, priority=None, table='bugzilla_meta'):
bugs = phabdb.get_issues_by_priority(dbcon,
priority,
table=table)
- elif '-' in bugs[0]:
+ elif len(bugs) > 0 and '-' in bugs[0]:
start, stop = bugs[0].split('-')
bugrange = range(int(start), int(stop) + 1)