|
# This file is part of Buildbot. Buildbot is free software: you can # redistribute it and/or modify it under the terms of the GNU General Public # License as published by the Free Software Foundation, version 2. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # Copyright Buildbot Team Members
"""I represent a single change to the source tree. This may involve several files, but they are all changed by the same person, and there is a change comment for the group as a whole."""
def fromChdict(cls, master, chdict): """ Class method to create a L{Change} from a dictionary as returned by L{ChangesConnectorComponent.getChange}.
@param master: build master instance @param ssdict: change dictionary
@returns: L{Change} via Deferred """
def _make_ch(cls, changeid, master, chdict):
change.properties.setProperty(n, v, s)
revision=None, when=None, branch=None, category=None, revlink='', properties={}, repository='', codebase='', project='', _fromChdict=False): # skip all this madness if we're being built from the database
# this happens when the committing system has an incorrect clock, for example. # handle it gracefully log.msg("received a Change with when > now; assuming the change happened now") self.when = now else:
# keep a sorted list of the files, for easier display
# Older Changes won't have a 'properties' attribute in them
u"when=%r, category=%r, project=%r, repository=%r, " + u"codebase=%r)") % ( self.revision, self.who, self.branch, self.comments, self.when, self.category, self.project, self.repository, self.codebase)
'''returns a dictonary with suitable info for html/mail rendering'''
# Constant
return "?" time.localtime(self.when))
if self.isdir: data += "Directory: %s\n" % self.files[0] else: data += "File: %s\n" % self.files[0] else:
class ChangeMaster: # pragma: no cover # this is a stub, retained to allow the "buildbot upgrade-master" tool to # read old changes.pck pickle files and convert their contents into the # new database format. This is only instantiated by that tool, or by # test_db.py which tests that tool. The functionality that previously # lived here has been moved into buildbot.changes.manager.ChangeManager
def __init__(self): self.changes = [] # self.basedir must be filled in by the parent self.nextNumber = 1
def saveYourself(self): filename = os.path.join(self.basedir, "changes.pck") tmpfilename = filename + ".tmp" try: with open(tmpfilename, "wb") as f: dump(self, f) if runtime.platformType == 'win32': # windows cannot rename a file on top of an existing one if os.path.exists(filename): os.unlink(filename) os.rename(tmpfilename, filename) except Exception: log.msg("unable to save changes") log.err()
# This method is used by contrib/fix_changes_pickle_encoding.py to recode all # bytestrings in an old changes.pck into unicode strings def recode_changes(self, old_encoding, quiet=False): """Processes the list of changes, with the change attributes re-encoded unicode objects""" nconvert = 0 for c in self.changes: # give revision special handling, in case it is an integer if isinstance(c.revision, int): c.revision = unicode(c.revision)
for attr in ("who", "comments", "revlink", "category", "branch", "revision"): a = getattr(c, attr) if isinstance(a, str): try: setattr(c, attr, a.decode(old_encoding)) nconvert += 1 except UnicodeDecodeError: raise UnicodeError("Error decoding %s of change #%s as %s:\n%r" % (attr, c.number, old_encoding, a))
# filenames are a special case, but in general they'll have the same encoding # as everything else on a system. If not, well, hack this script to do your # import! newfiles = [] for filename in util.flatten(c.files): if isinstance(filename, str): try: filename = filename.decode(old_encoding) nconvert += 1 except UnicodeDecodeError: raise UnicodeError("Error decoding filename '%s' of change #%s as %s:\n%r" % (filename.decode('ascii', 'replace'), c.number, old_encoding, a)) newfiles.append(filename) c.files = newfiles if not quiet: print "converted %d strings" % nconvert
class OldChangeMaster(ChangeMaster): # pragma: no cover # this is a reminder that the ChangeMaster class is old pass # vim: set ts=4 sts=4 sw=4 et: |