[PATCH 1/2] Implement the build action in the copr-cli

Pierre-Yves Chibon pingou at pingoured.fr
Sat Feb 9 19:39:52 UTC 2013


The build action is used to build certain packages in a given copr.
---
 copr_cli/subcommands.py | 37 +++++++++++++++++++++++++++++++++++++
 coprcli-setup.py        |  1 +
 2 files changed, 38 insertions(+)

diff --git a/copr_cli/subcommands.py b/copr_cli/subcommands.py
index c1af50a..c0013db 100644
--- a/copr_cli/subcommands.py
+++ b/copr_cli/subcommands.py
@@ -109,3 +109,40 @@ class AddCopr(Command):
             print output['message']
         else:
             print 'Something went wrong:\n  {0}'.format(output['error'])
+
+
+class Build(Command):
+    """ Build a new package into a given copr. """
+
+    log = logging.getLogger(__name__)
+
+    def get_parser(self, prog_name):
+        parser = super(type(self), self).get_parser(prog_name)
+        parser.add_argument('copr')
+        parser.add_argument('pkgs', nargs='+', action='append')
+        parser.add_argument('--memory', dest='memory',
+                            help="")
+        parser.add_argument('--timeout', dest='timeout',
+                            help="")
+        return parser
+
+    def take_action(self, args):
+        user = set_user()
+        URL = '{0}/coprs/detail/{1}/{2}/new_build/'.format(
+            copr_api_url,
+            user['username'],
+            args.copr)
+
+        data = {'pkgs': ' '.join(args.pkgs[0]),
+                'memory': args.memory,
+                'timeout': args.timeout
+                }
+
+        req = requests.post(URL,
+                            auth=(user['username'], user['token']),
+                            data=data)
+        output = json.loads(req.text)
+        if req.status_code != 200:
+            print 'Something went wrong:\n  {0}'.format(output['error'])
+        else:
+            print output['message']
diff --git a/coprcli-setup.py b/coprcli-setup.py
index a7a40d3..0084494 100644
--- a/coprcli-setup.py
+++ b/coprcli-setup.py
@@ -30,6 +30,7 @@ requires = [
 subcommands = [
     'list = copr_cli.subcommands:List',
     'add-copr = copr_cli.subcommands:AddCopr',
+    'build-copr = copr_cli.subcommands:Build',
 ]
 
 __name__ = 'copr-cli'
-- 
1.8.1.2



More information about the copr-devel mailing list