From: Leonardo Sandoval <leonardo.sandoval.gonza...@linux.intel.com> This new command allows to fetch bundles (set of selected patches by the user) and print them into the stdout. For the moment, bundles must be public (otherwise these wont be found)
Command line example: openembedded-core$ git pw bundle newbundle --username lsandov1 Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonza...@linux.intel.com> --- git-pw/git-pw | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/git-pw/git-pw b/git-pw/git-pw index f5fbdcb..554dfae 100755 --- a/git-pw/git-pw +++ b/git-pw/git-pw @@ -126,6 +126,11 @@ class Command(object): 'need_project' : False, 'need_auth' : False, }, + 'bundle': { + 'need_git_repo': True, + 'need_project' : False, + 'need_auth' : False, + }, 'list': { 'need_git_repo': True, 'need_project' : True, @@ -295,13 +300,25 @@ class Patch(RestObject): def url(self, url='/'): return '/patches/' + str(self.id) + url +class Bundle(RestObject): + + def __init__(self, patchwork, bundle_name, user): + super(Bundle, self).__init__(patchwork) + self.bundle_name = str(bundle_name) + self.user = str(user) + + def url(self, url='/'): + return '/bundle/' + self.user + '/' + self.bundle_name + url + class Patchwork(object): + api_version= 'api/1.0' + def __init__(self, web_root, project_linkname, user): if not web_root.endswith('/'): web_root += '/' - self.api_base = web_root + 'api/1.0' + self.api_base = web_root + self.api_version self.web_root = web_root self.project = Project(self, project_linkname) self.user = user @@ -372,6 +389,9 @@ class Patchwork(object): def get_patch(self, patch_id): return Patch(self, patch_id) + def get_bundle(self, bundle_name, name): + return Bundle(self, bundle_name, name) + class Terminal(object): DEFAULT_WIDTH = 80 @@ -578,15 +598,13 @@ class GitPatchwork(object): # auth mechanism. In any case, using HTTPS is a must. username = None password = None - user = None try: username = config.get(section, 'user') password = config.get(section, 'password') - user = User(username, password) except: pass - if not user and self.cmd.need_auth: + if not password and self.cmd.need_auth: die('No authentication configured.\n\n' "Please set up credentials, e.g.:\n\n" " git config patchwork.%(config)s.user myusername\n" @@ -594,6 +612,8 @@ class GitPatchwork(object): 'config': self.cmd.config, }) + user = User(username, password) + self.pw = Patchwork(web_root, project, user) self.pw.setup() @@ -679,6 +699,20 @@ class GitPatchwork(object): raise die('No patch with id %d.' % self.cmd.patch_id) + def do_bundle(self): + user = self.cmd.username or self.pw.user.username + if not user: + die('Either define a patchwork user at .git/config or set it through --username') + + bundle = self.pw.get_bundle(self.cmd.bundle_name, user) + + try: + return self._print_mbox(bundle.absolute_url('/mbox/').replace(self.pw.api_version,'')) + except HttpError as e: + if e.status_code != 404: + raise + die('No user %s bundle with name %s.' % (self.cmd.user, self.cmd.bundle_name)) + def do_list(self): project = self.pw.get_project() params = { @@ -973,6 +1007,16 @@ if __name__ == '__main__': parser_add_mbox_options(mbox_patch_parser) + # bundle + bundle_parser = subparsers.add_parser('bundle', + help='retrieve a mbox file of a bundle and print it on stdout') + bundle_parser.add_argument('--username', '-u', metavar='username', + type=str, help='the patchwork\'s user that created the bundle, use git\'s configured if omitted') + bundle_parser.add_argument('bundle_name', metavar='bundle_name', + type=str, help='the bundle to retrieve') + + parser_add_mbox_options(bundle_parser) + # poll-events poll_events_parser = subparsers.add_parser('poll-events', help='list events since the last invocation') -- 2.1.4 -- _______________________________________________ yocto mailing list yocto@yoctoproject.org https://lists.yoctoproject.org/listinfo/yocto