def test_send_unicode_utf8(self): s = sendchange.Sender('localhost:1234') d = s.send(u'\N{DEGREE SIGN}'.encode('utf8'), u'\U0001f49e'.encode('utf8'), u'\N{POSTAL MARK FACE}'.encode('utf8'), [u'\U0001F4C1'.encode('utf8')], project=u'\N{SKULL AND CROSSBONES}'.encode('utf8'), repository=u'\N{SNOWMAN}'.encode('utf8'), who=u'\N{THAI CHARACTER KHOMUT}'.encode('utf8'), category=u'\U0001F640'.encode('utf8'), when=1234, properties={ u'\N{LATIN SMALL LETTER A WITH MACRON}'.encode('utf8'): 'b' }, revlink=u'\U0001F517'.encode('utf8')) def check(_): self.assertProcess( 'localhost', 1234, 'change', 'changepw', [ dict( project=u'\N{SKULL AND CROSSBONES}', repository=u'\N{SNOWMAN}', who=u'\N{THAI CHARACTER KHOMUT}', files=[u'\U0001F4C1'], # FILE FOLDER comments=u'\N{POSTAL MARK FACE}', branch=u'\N{DEGREE SIGN}', revision=u'\U0001f49e', # REVOLVING HEARTS category=u'\U0001F640', # WEARY CAT FACE when=1234, ## NOTE: not decoded! properties={'\xc4\x81': 'b'}, revlink=u'\U0001F517', # LINK SYMBOL src=None) ]) d.addCallback(check) return d
def test_send_codebase(self): s = sendchange.Sender('localhost:1234') yield s.send('branch', 'rev', 'comm', ['a'], codebase='mycb') self.assertProcess('localhost', 1234, b'change', b'changepw', [ dict(project='', repository='', who=None, files=['a'], comments='comm', branch='branch', revision='rev', category=None, when=None, properties={}, revlink='', src=None, codebase='mycb') ])
def test_send_files_tuple(self): # 'buildbot sendchange' sends files as a tuple, rather than a list.. s = sendchange.Sender('localhost:1234') yield s.send('branch', 'rev', 'comm', ('a', 'b')) self.assertProcess('localhost', 1234, b'change', b'changepw', [ dict(project='', repository='', who=None, files=['a', 'b'], comments='comm', branch='branch', revision='rev', category=None, when=None, properties={}, revlink='', src=None) ])
def sendChanges(master): changes = findNewChanges() s = sendchange.Sender(master, None) d = defer.Deferred() reactor.callLater(0, d.callback, None) if not changes: print "darcs_buildbot.py: weird, no changes to send" return elif len(changes) == 1: print "sending 1 change to buildmaster:" else: print "sending %d changes to buildmaster:" % len(changes) # the Darcs Source class expects revision to be a context, not a # hash of a patch (which is what we have in c['revision']). For # the moment, we send None for everything but the most recent, because getting # contexts is Hard. # get the context for the most recent change latestcontext = commands.getoutput("darcs changes --context") changes[-1]['context'] = latestcontext def _send(res, c): branch = None print " %s" % c['revision'] return s.send(branch, c.get('context'), c['comments'], c['files'], c['username']) for c in changes: d.addCallback(_send, c) d.addCallbacks(s.printSuccess, s.printFailure) d.addBoth(s.stop) s.run() if changes: lastchange = changes[-1]['revision'] f = open(LASTCHANGEFILE, "w") f.write(lastchange) f.close()
def test_send_unicode_latin1(self): # hand send() a bunch of latin1 strings, and expect them recoded # to unicode s = sendchange.Sender('localhost:1234', encoding='latin1') d = s.send(u'\N{YEN SIGN}'.encode('latin1'), u'\N{POUND SIGN}'.encode('latin1'), u'\N{BROKEN BAR}'.encode('latin1'), [u'\N{NOT SIGN}'.encode('latin1')], project=u'\N{DEGREE SIGN}'.encode('latin1'), repository=u'\N{SECTION SIGN}'.encode('latin1'), who=u'\N{MACRON}'.encode('latin1'), category=u'\N{PILCROW SIGN}'.encode('latin1'), when=1234, properties={u'\N{SUPERSCRIPT ONE}'.encode('latin1'): 'b'}, revlink=u'\N{INVERTED QUESTION MARK}'.encode('latin1')) def check(_): self.assertProcess( 'localhost', 1234, 'change', 'changepw', [ dict( project=u'\N{DEGREE SIGN}', repository=u'\N{SECTION SIGN}', who=u'\N{MACRON}', files=[u'\N{NOT SIGN}'], comments=u'\N{BROKEN BAR}', branch=u'\N{YEN SIGN}', revision=u'\N{POUND SIGN}', category=u'\N{PILCROW SIGN}', when=1234, # NOTE: not decoded! properties={'\xb9': 'b'}, revlink=u'\N{INVERTED QUESTION MARK}', src=None) ]) d.addCallback(check) return d
def test_send_auth(self): s = sendchange.Sender('localhost:1234', auth=('me', 'sekrit')) d = s.send('branch', 'rev', 'comm', ['a']) def check(_): self.assertProcess('localhost', 1234, 'me', 'sekrit', [ dict(project='', repository='', who=None, files=['a'], comments='comm', branch='branch', revision='rev', category=None, when=None, properties={}, revlink='') ]) d.addCallback(check) return d
def sendchange(config): encoding = config.get('encoding', 'utf8') who = config.get('who') auth = config.get('auth') master = config.get('master') branch = config.get('branch') category = config.get('category') revision = config.get('revision') properties = config.get('properties', {}) repository = config.get('repository', '') vc = config.get('vc', None) project = config.get('project', '') revlink = config.get('revlink', '') when = config.get('when') comments = config.get('comments') files = config.get('files', ()) codebase = config.get('codebase', None) s = sendchange_client.Sender(master, auth, encoding=encoding) try: yield s.send(branch, revision, comments, files, who=who, category=category, when=when, properties=properties, repository=repository, vc=vc, project=project, revlink=revlink, codebase=codebase) except Exception: print("change not sent:") traceback.print_exc(file=sys.stdout) defer.returnValue(1) else: print("change sent successfully") defer.returnValue(0)
def sendchange(config, runReactor=False): """Send a single change to the buildmaster's PBChangeSource. The connection will be drpoped as soon as the Change has been sent.""" from buildbot.clients import sendchange encoding = config.get('encoding', 'utf8') who = config.get('who') if not who and config.get('username'): print "NOTE: --username/-u is deprecated: use --who/-W'" who = config.get('username') auth = config.get('auth') master = config.get('master') branch = config.get('branch') category = config.get('category') revision = config.get('revision') properties = config.get('properties', {}) repository = config.get('repository', '') project = config.get('project', '') revlink = config.get('revlink', '') if config.get('when'): when = float(config.get('when')) else: when = None if config.get("revision_file"): revision = open(config["revision_file"],"r").read() comments = config.get('comments') if not comments and config.get('logfile'): if config['logfile'] == "-": f = sys.stdin else: f = open(config['logfile'], "rt") comments = f.read() if comments is None: comments = "" files = config.get('files', ()) # fix up the auth with a password if none was given if not auth: auth = 'change:changepw' if ':' not in auth: import getpass pw = getpass.getpass("Enter password for '%s': " % auth) auth = "%s:%s" % (auth, pw) auth = auth.split(':', 1) assert who, "you must provide a committer (--who)" assert master, "you must provide the master location" s = sendchange.Sender(master, auth, encoding=encoding) d = s.send(branch, revision, comments, files, who=who, category=category, when=when, properties=properties, repository=repository, project=project, revlink=revlink) if runReactor: status = [True] def printSuccess(_): print "change sent successfully" def failed(f): status[0] = False print "change NOT sent - something went wrong: " + str(f) d.addCallbacks(printSuccess, failed) d.addBoth(lambda _ : reactor.stop()) reactor.run() return status[0] return d
def hook(ui, repo, hooktype, node=None, source=None, **kwargs): # read config parameters baseurl = ui.config('hgbuildbot', 'baseurl', ui.config('web', 'baseurl', '')) masters = ui.configlist('hgbuildbot', 'master') if masters: branchtype = ui.config('hgbuildbot', 'branchtype', 'inrepo') branch = ui.config('hgbuildbot', 'branch') fork = ui.configbool('hgbuildbot', 'fork', False) # notify also has this setting stripcount = int(ui.config('notify', 'strip') or ui.config('hgbuildbot', 'strip', 3)) category = ui.config('hgbuildbot', 'category', None) project = ui.config('hgbuildbot', 'project', '') auth = ui.config('hgbuildbot', 'auth', None) else: ui.write("* You must add a [hgbuildbot] section to .hg/hgrc in " "order to use buildbot hook\n") return if hooktype != "changegroup": ui.status("hgbuildbot: hooktype %s not supported.\n" % hooktype) return if fork: child_pid = os.fork() if child_pid == 0: # child pass else: # parent ui.status("Notifying buildbot...\n") return # only import inside the fork if forked from buildbot.clients import sendchange from twisted.internet import defer, reactor if branch is None: if branchtype == 'dirname': branch = os.path.basename(repo.root) if not auth: auth = 'change:changepw' auth = auth.split(':', 1) # process changesets def _send(res, s, c): if not fork: ui.status("rev %s sent\n" % c['revision']) return s.send(c['branch'], c['revision'], c['comments'], c['files'], c['username'], category=category, repository=repository, project=project, vc='hg', properties=c['properties']) try: # first try Mercurial 1.1+ api start = repo[node].rev() end = len(repo) except TypeError: # else fall back to old api start = repo.changelog.rev(bin(node)) end = repo.changelog.count() repository = strip(repo.root, stripcount) repository = baseurl + repository for master in masters: s = sendchange.Sender(master, auth=auth) d = defer.Deferred() reactor.callLater(0, d.callback, None) for rev in xrange(start, end): # send changeset node = repo.changelog.node(rev) manifest, user, (time, timezone), files, desc, extra = repo.changelog.read(node) parents = filter(lambda p: not p == nullid, repo.changelog.parents(node)) if branchtype == 'inrepo': branch = extra['branch'] is_merge = len(parents) > 1 # merges don't always contain files, but at least one file is required by buildbot if is_merge and not files: files = ["merge"] properties = {'is_merge': is_merge} if branch: branch = fromlocal(branch) change = { 'master': master, 'username': fromlocal(user), 'revision': hex(node), 'comments': fromlocal(desc), 'files': files, 'branch': branch, 'properties': properties } d.addCallback(_send, s, change) def _printSuccess(res): ui.status(s.getSuccessString(res) + '\n') def _printFailure(why): ui.warn(s.getFailureString(why) + '\n') d.addCallbacks(_printSuccess, _printFailure) d.addBoth(lambda _: reactor.stop()) reactor.run() if fork: os._exit(os.EX_OK) else: return
def hook(ui, repo, hooktype, node=None, source=None, **kwargs): # read config parameters master = ui.config('hgbuildbot', 'master') if master: branchtype = ui.config('hgbuildbot', 'branchtype') branch = ui.config('hgbuildbot', 'branch') fork = ui.configbool('hgbuildbot', 'fork', False) # notify also has this setting stripcount = int( ui.config('notify', 'strip') or ui.config('hgbuildbot', 'strip', 3)) category = ui.config('hgbuildbot', 'category', None) project = ui.config('hgbuildbot', 'project', '') else: ui.write("* You must add a [hgbuildbot] section to .hg/hgrc in " "order to use buildbot hook\n") return if hooktype != "changegroup": ui.status("hgbuildbot: hooktype %s not supported.\n" % hooktype) return if fork: child_pid = os.fork() if child_pid == 0: #child pass else: #parent ui.status("Notifying buildbot...\n") return # only import inside the fork if forked from buildbot.clients import sendchange from twisted.internet import defer, reactor if branch is None: if branchtype is not None: if branchtype == 'dirname': branch = os.path.basename(repo.root) if branchtype == 'inrepo': branch = workingctx(repo).branch() s = sendchange.Sender(master, None) d = defer.Deferred() reactor.callLater(0, d.callback, None) # process changesets def _send(res, c): if not fork: ui.status("rev %s sent\n" % c['revision']) return s.send(c['branch'], c['revision'], c['comments'], c['files'], c['username'], category=category, repository=repository, project=project) try: # first try Mercurial 1.1+ api start = repo[node].rev() end = len(repo) except TypeError: # else fall back to old api start = repo.changelog.rev(bin(node)) end = repo.changelog.count() repository = strip(repo.root, stripcount) for rev in xrange(start, end): # send changeset node = repo.changelog.node(rev) manifest, user, ( time, timezone), files, desc, extra = repo.changelog.read(node) parents = filter(lambda p: not p == nullid, repo.changelog.parents(node)) if branchtype == 'inrepo': branch = extra['branch'] # merges don't always contain files, but at least one file is required by buildbot if len(parents) > 1 and not files: files = ["merge"] change = { 'master': master, 'username': user, 'revision': hex(node), 'comments': desc, 'files': files, 'branch': branch } d.addCallback(_send, change) d.addCallbacks(s.printSuccess, s.printFailure) d.addBoth(s.stop) s.run() if fork: os._exit(os.EX_OK) else: return
def hook(ui, repo, hooktype, node=None, source=None, **kwargs): # read config parameters master = ui.config('hgbuildbot', 'master') if master: branchtype = ui.config('hgbuildbot', 'branchtype') branch = ui.config('hgbuildbot', 'branch') else: ui.write("* You must add a [hgbuildbot] section to .hg/hgrc in " "order to use buildbot hook\n") return if branch is None: if branchtype is not None: if branchtype == 'dirname': branch = os.path.basename(os.getcwd()) if branchtype == 'inrepo': branch = workingctx(repo).branch() if hooktype == 'changegroup': s = sendchange.Sender(master, None) d = defer.Deferred() reactor.callLater(0, d.callback, None) # process changesets def _send(res, c): ui.status("rev %s sent\n" % c['revision']) return s.send(c['branch'], c['revision'], c['comments'], c['files'], c['username']) try: # first try Mercurial 1.1+ api start = repo[node].rev() end = len(repo) except TypeError: # else fall back to old api start = repo.changelog.rev(bin(node)) end = repo.changelog.count() for rev in xrange(start, end): # send changeset node = repo.changelog.node(rev) manifest, user, ( time, timezone), files, desc, extra = repo.changelog.read(node) parents = filter(lambda p: not p == nullid, repo.changelog.parents(node)) if branchtype == 'inrepo': branch = extra['branch'] # merges don't always contain files, but at least one file is required by buildbot if len(parents) > 1 and not files: files = ["merge"] change = { 'master': master, 'username': user, 'revision': hex(node), 'comments': desc, 'files': files, 'branch': branch } d.addCallback(_send, change) d.addCallbacks(s.printSuccess, s.printFailure) d.addBoth(s.stop) s.run() else: ui.status(_('hgbuildbot: hook %s not supported\n') % hooktype) return
def hook(ui, repo, hooktype, node=None, source=None, **kwargs): if hooktype != 'changegroup': ui.status('hgbuildbot: hooktype %s not supported.\n' % hooktype) return # Read config parameters masters = ui.configlist('hgbuildbot', 'master') if not masters: ui.write('* You must add a [hgbuildbot] section to .hg/hgrc in ' 'order to use the Buildbot hook\n') return # - virtualenv venv = ui.config('hgbuildbot', 'venv', None) if venv is not None: if not os.path.isdir(venv): ui.write('* Virtualenv "%s" does not exist.\n' % venv) sys.path.insert(0, venv) # - auth username = ui.config('hgbuildbot', 'user', 'change') password = ui.config('hgbuildbot', 'passwd', 'changepw') # - branch branchtype = ui.config('hgbuildbot', 'branchtype', 'inrepo') branch = ui.config('hgbuildbot', 'branch', None) # - repo URL baseurl = ui.config('hgbuildbot', 'baseurl', ui.config('web', 'baseurl', '')) stripcount = int( ui.config('hgbuildbot', 'strip', ui.config('notify', 'strip', 0))) # - category, project and codebase category = ui.config('hgbuildbot', 'category', None) project = ui.config('hgbuildbot', 'project', '') codebase = ui.config('hgbuildbot', 'codebase', '') # Only import this after the (optional) venv has been added to sys.path: from buildbot.clients import sendchange from twisted.internet import defer, reactor # Process changesets if branch is None and branchtype == 'dirname': branch = os.path.basename(repo.root) # If branchtype == 'inrepo', update "branch" for each commit later. repository = strip(repo.root, stripcount) repository = baseurl + repository start = repo[node].rev() end = len(repo) for master in masters: s = sendchange.Sender(master, auth=(username, password)) d = defer.Deferred() reactor.callLater(0, d.callback, None) for rev in range(start, end): # send changeset node = repo.changelog.node(rev) log = repo.changelog.read(node) manifest, user, (time, timezone), files, desc, extra = log parents = [p for p in repo.changelog.parents(node) if p != nullid] if branchtype == 'inrepo': branch = extra['branch'] if branch: branch = fromlocal(branch) is_merge = len(parents) > 1 # merges don't always contain files, but at least one file is # required by buildbot if is_merge and not files: files = ["merge"] properties = {'is_merge': is_merge} change = { # 'master': master, 'branch': branch, 'revision': hex(node), 'comments': fromlocal(desc), 'files': files, 'username': fromlocal(user), 'category': category, 'time': time, 'properties': properties, 'repository': repository, 'project': project, 'codebase': codebase, } d.addCallback(send_cs, s, change) def _printSuccess(res): ui.status(s.getSuccessString(res) + '\n') def _printFailure(why): ui.warn(s.getFailureString(why) + '\n') d.addCallbacks(_printSuccess, _printFailure) d.addBoth(lambda _: reactor.stop()) reactor.run()