Mercurial > p > roundup > code
changeset 5332:d0689aaa83db
Applied patch 0038 from issue2550960 to upgrade code examples in
documentation to be compatible with both python 2 and 3. Patch
supplied by Joseph Myers.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 12 Jun 2018 20:27:04 -0400 |
| parents | 57caeefb2f81 |
| children | a196891cf786 |
| files | CHANGES.txt doc/customizing.txt doc/design.txt doc/developers.txt doc/upgrading.txt doc/xmlrpc.txt |
| diffstat | 6 files changed, 48 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Thu Jun 07 12:39:31 2018 +0200 +++ b/CHANGES.txt Tue Jun 12 20:27:04 2018 -0400 @@ -233,6 +233,8 @@ through the python logger module (using roundup.http). This allows automatic log rotation. Without it, log file rotation requires restarting the server. (John Rouillard) +- Part of issue2550960. Applied patch 0038 to upgrade documentation + code examples to support both python 2 and 3. (Joseph Myers) Fixed:
--- a/doc/customizing.txt Thu Jun 07 12:39:31 2018 +0200 +++ b/doc/customizing.txt Tue Jun 12 20:27:04 2018 -0400 @@ -4374,12 +4374,12 @@ def reject_html(db, cl, nodeid, newvalues): if newvalues['type'] == 'text/html': - raise Reject, 'not allowed' + raise Reject('not allowed') def reject_manylinks(db, cl, nodeid, newvalues): content = newvalues['content'] if content.count('http://') > 2: - raise Reject, 'not allowed' + raise Reject('not allowed') def init(db): db.file.audit('create', reject_html) @@ -4389,7 +4389,7 @@ need that ability:: if newvalues['type'].startswith('image/'): - raise Reject, 'not allowed' + raise Reject('not allowed') Stop "nosy" messages going to people on vacation @@ -4453,7 +4453,7 @@ if users.get(nosyid, 'username') == 'anonymous': continue # make sure they haven't seen the message already - if not seen_message.has_key(nosyid): + if nosyid not in seen_message: # send it to them sendto.append(nosyid) recipients.append(nosyid) @@ -4520,7 +4520,7 @@ ''' Check that the desired transition is valid for the "status" property. ''' - if not newvalues.has_key('status'): + if 'status' not in newvalues: return current = cl.get(nodeid, 'status') new = newvalues['status'] @@ -4528,8 +4528,8 @@ return ok = db.status.get(current, 'transitions') if new not in ok: - raise ValueError, 'Status not allowed to move from "%s" to "%s"'%( - db.status.get(current, 'name'), db.status.get(new, 'name')) + raise ValueError('Status not allowed to move from "%s" to "%s"'%( + db.status.get(current, 'name'), db.status.get(new, 'name'))) def init(db): db.issue.audit('set', checktransition) @@ -4623,7 +4623,7 @@ # don't do anything if there's no blockers or the status hasn't # changed - if not blockers or not newvalues.has_key('status'): + if not blockers or 'status' not in newvalues: return # get the resolved state ID @@ -4640,7 +4640,7 @@ # ok, see if we're trying to resolve if newvalues['status'] == resolved_id: - raise ValueError, "This issue can't be resolved until %s resolved."%s + raise ValueError("This issue can't be resolved until %s resolved."%s) def resolveblockers(db, cl, nodeid, oldvalues): @@ -4826,23 +4826,23 @@ ok = ('yes',) # old node, get the current values from the node if they haven't # changed - if not newvalues.has_key('nosy'): + if 'nosy' not in newvalues: nosy = cl.get(nodeid, 'nosy') for value in nosy: - if not current.has_key(value): + if value not in current: current[value] = 1 # if the nosy list changed in this transaction, init from the new value - if newvalues.has_key('nosy'): + if 'nosy' in newvalues: nosy = newvalues.get('nosy', []) for value in nosy: if not db.hasnode('user', value): continue - if not current.has_key(value): + if value not in current: current[value] = 1 # add users with keyword in nosy_keywords to the nosy list - if newvalues.has_key('keyword') and newvalues['keyword'] is not None: + if 'keyword' in newvalues and newvalues['keyword'] is not None: keyword_ids = newvalues['keyword'] for keyword in keyword_ids: # loop over all users, @@ -4857,7 +4857,7 @@ current[user_id] = 1 # that's it, save off the new nosy list - newvalues['nosy'] = current.keys() + newvalues['nosy'] = list(current.keys()) These two function are the only ones needed in the file. @@ -4919,7 +4919,7 @@ def restrict_nosy_changes(db, cl, nodeid, newvalues): '''Do not permit changes to nosy via email.''' - if not (newvalues.has_key('nosy')): + if 'nosy' not in newvalues: # the nosy field has not changed so no need to check. return @@ -4999,14 +4999,14 @@ ''' Ensure the assignedto value in newvalues is used with the Fixer Permission ''' - if not newvalues.has_key('assignedto'): + if 'assignedto' not in newvalues: # don't care return # get the userid userid = newvalues['assignedto'] if not db.security.hasPermission('Fixer', userid, cl.classname): - raise ValueError, 'You do not have permission to edit %s'%cl.classname + raise ValueError('You do not have permission to edit %s'%cl.classname) def init(db): db.issue.audit('set', assignedtoMustBeFixer)
--- a/doc/design.txt Thu Jun 07 12:39:31 2018 +0200 +++ b/doc/design.txt Tue Jun 12 20:27:04 2018 -0400 @@ -980,27 +980,27 @@ # Permit users only to add themselves to the "approvals" list. def check_approvals(db, cl, id, newdata): - if newdata.has_key("approvals"): + if "approvals" in newdata: if cl.get(id, "status") == db.status.lookup("approved"): - raise Reject, "You can't modify the approvals list " \ - "for a project that has already been approved." + raise Reject("You can't modify the approvals list " + "for a project that has already been approved.") old = cl.get(id, "approvals") new = newdata["approvals"] for uid in old: if uid not in new and uid != db.getuid(): - raise Reject, "You can't remove other users from " \ - "the approvals list; you can only remove " \ - "yourself." + raise Reject("You can't remove other users from " + "the approvals list; you can only remove " + "yourself.") for uid in new: if uid not in old and uid != db.getuid(): - raise Reject, "You can't add other users to the " \ - "approvals list; you can only add yourself." + raise Reject("You can't add other users to the " + "approvals list; you can only add yourself.") # When three people have approved a project, change its status from # "pending" to "approved". def approve_project(db, cl, id, olddata): - if (olddata.has_key("approvals") and + if ("approvals" in olddata and len(cl.get(id, "approvals")) == 3): if cl.get(id, "status") == db.status.lookup("pending"): cl.set(id, status=db.status.lookup("approved")) @@ -1021,12 +1021,12 @@ def check_new_patch(db, cl, id, newdata): if not newdata["files"]: - raise Reject, "You can't submit a new patch without " \ - "attaching a patch file." + raise Reject("You can't submit a new patch without " + "attaching a patch file.") for fileid in newdata["files"]: if db.file.get(fileid, "type") != "text/plain": - raise Reject, "Submitted patch files must be " \ - "text/plain." + raise Reject("Submitted patch files must be " + "text/plain.") # When the status is changed from "approved" to "applied", apply the # patch.
--- a/doc/developers.txt Thu Jun 07 12:39:31 2018 +0200 +++ b/doc/developers.txt Tue Jun 12 20:27:04 2018 -0400 @@ -213,12 +213,12 @@ Simple translations are automatically marked by calls to builtin message translation function ``_()``:: - print _("This message is translated") + print(_("This message is translated")) Translations for messages whose grammatical depends on a number must be done by ``ngettext()`` function:: - print ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked) + print(ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked)) Deferred Translations ~~~~~~~~~~~~~~~~~~~~~ @@ -228,7 +228,7 @@ Example:: for meal in ("spam", "egg", "beacon"): - print _(meal) + print(_(meal)) In such cases, strings must be marked for translation without actual call to the translating function. To mark these strings, we use Python
--- a/doc/upgrading.txt Thu Jun 07 12:39:31 2018 +0200 +++ b/doc/upgrading.txt Tue Jun 12 20:27:04 2018 -0400 @@ -872,7 +872,7 @@ if op == '-': affected [i] = 1 break - print ', '.join(sorted(affected.iterkeys())) + print(', '.join(sorted(affected.keys()))) To find out which files where attached before you can look in the history of the affected issue. For fixing issues you can re-attach the @@ -923,6 +923,7 @@ search for this property:: #!/usr/bin/python + from __future__ import print_function import os from roundup import instance @@ -930,14 +931,14 @@ db = tracker.open('admin') for cl in sorted(db.getclasses()): - print "Class:", cl + print("Class:", cl) for p in sorted(db.getclass(cl).getprops(protected=True).keys()): - print " Property:", p + print(" Property:", p) roles = [] - for role in sorted(db.security.role.iterkeys()): + for role in sorted(db.security.role.keys()): if db.security.roleHasSearchPermission(cl,p,role): roles.append(role) - print " roles may search:", ', '.join(roles) + print(" roles may search:", ', '.join(roles)) Migrating from 1.4.x to 1.4.12
--- a/doc/xmlrpc.txt Thu Jun 07 12:39:31 2018 +0200 +++ b/doc/xmlrpc.txt Tue Jun 12 20:27:04 2018 -0400 @@ -169,13 +169,13 @@ verbose=False, allow_none=True) - print roundup_server.schema() - print roundup_server.display('user2', 'username') - print roundup_server.display('issue1', 'status') - print roundup_server.filter('user',['1','2','3'],{'username':'demo'}) + print(roundup_server.schema()) + print(roundup_server.display('user2', 'username')) + print(roundup_server.display('issue1', 'status')) + print(roundup_server.filter('user',['1','2','3'],{'username':'demo'})) # this will fail with a fault try: - print roundup_server.filter('usr',['0','2','3'],{'username':'demo'}) + print(roundup_server.filter('usr',['0','2','3'],{'username':'demo'})) except Exception as msg: - print msg + print(msg)
