From 8265243bf9eea3a87b57c9acf1798637357acc44 Mon Sep 17 00:00:00 2001
From: Slavek Kabrda <bkabrda@redhat.com>
Date: Aug 24 2015 10:59:29 +0000
Subject: [PATCH 1/2] Add a command and option to change container build setup


---

diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index 2d3d3db..a748d43 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -753,6 +753,10 @@ class Commands(object):
         return os.path.join(self.path, 'sources')
 
     @property
+    def osbs_config_filename(self):
+        return os.path.join(self.path, '.osbs-repo-config')
+
+    @property
     def cert_file(self):
         """A client-side certificate for SSL authentication
 
@@ -2431,3 +2435,23 @@ class Commands(object):
         finally:
             (self.build_client, self.kojiconfig) = koji_session_backup
             self.load_kojisession()
+
+    def container_build_setup(self, autorebuild=None):
+        if autorebuild is None:
+            self.log.info('No change to be done')
+            return
+
+        cfp = ConfigParser.SafeConfigParser()
+        if os.path.exists(self.osbs_config_filename):
+            cfp.read(self.osbs_config_filename)
+
+        if not cfp.has_section('autorebuild'):
+            cfp.add_section('autorebuild')
+
+        cfp.set('autorebuild', 'enabled', 'true' if autorebuild == 'on' else 'false')
+        with open(self.osbs_config_filename, 'w') as fp:
+            cfp.write(fp)
+
+        self.repo.index.add([self.osbs_config_filename])
+        self.log.info('Config value changed, don\'t forget to commit %s file',
+                      self.osbs_config_filename)
diff --git a/src/pyrpkg/cli.py b/src/pyrpkg/cli.py
index 8ecb30c..bdc877a 100755
--- a/src/pyrpkg/cli.py
+++ b/src/pyrpkg/cli.py
@@ -205,6 +205,7 @@ class cliClient(object):
         self.register_commit()
         self.register_compile()
         self.register_container_build()
+        self.register_container_build_setup()
         self.register_diff()
         self.register_gimmespec()
         self.register_gitbuildhash()
@@ -834,6 +835,19 @@ defined, packages will be built sequentially.""" % {'name': self.name})
 
         self.container_build_parser.set_defaults(command=self.container_build)
 
+    def register_container_build_setup(self):
+        self.container_build_setup_parser = \
+            self.subparsers.add_parser('container-build-setup',
+                                       help='set options for container-build')
+        self.container_build_setup_parser.add_argument(
+            '--autorebuild',
+            help='Turn autorebuilds on/off',
+            choices=['on', 'off'],
+            required=False,
+            default=None)
+        self.container_build_setup_parser.set_defaults(
+            command=self.container_build_setup)
+
     # All the command functions go here
     def usage(self):
         self.parser.print_help()
@@ -1054,6 +1068,8 @@ defined, packages will be built sequentially.""" % {'name': self.name})
             yum_repourls=self.args.repo_url
         )
 
+    def container_build_setup(self):
+        self.cmd.container_build_setup(autorebuild=self.args.autorebuild)
 
     def diff(self):
         self.cmd.diff(self.args.cached, self.args.files)

From 2c65d684f7564c577a1fdb7007212d22668ee319 Mon Sep 17 00:00:00 2001
From: Slavek Kabrda <bkabrda@redhat.com>
Date: Aug 26 2015 09:02:15 +0000
Subject: [PATCH 2/2] Implement getter for autorebuild value, use 'true' and 'false' for values


---

diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index a748d43..1373265 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -2436,22 +2436,27 @@ class Commands(object):
             (self.build_client, self.kojiconfig) = koji_session_backup
             self.load_kojisession()
 
-    def container_build_setup(self, autorebuild=None):
-        if autorebuild is None:
-            self.log.info('No change to be done')
-            return
-
+    def container_build_setup(self, get_autorebuild=None, set_autorebuild=None):
         cfp = ConfigParser.SafeConfigParser()
         if os.path.exists(self.osbs_config_filename):
             cfp.read(self.osbs_config_filename)
 
-        if not cfp.has_section('autorebuild'):
-            cfp.add_section('autorebuild')
-
-        cfp.set('autorebuild', 'enabled', 'true' if autorebuild == 'on' else 'false')
-        with open(self.osbs_config_filename, 'w') as fp:
-            cfp.write(fp)
-
-        self.repo.index.add([self.osbs_config_filename])
-        self.log.info('Config value changed, don\'t forget to commit %s file',
-                      self.osbs_config_filename)
+        if get_autorebuild is not None:
+            if not cfp.has_option('autorebuild', 'enabled'):
+                self.log.info('true')
+            else:
+                self.log.info('true' if cfp.getboolean('autorebuild', 'enabled')
+                              else 'false')
+        elif set_autorebuild is not None:
+            if not cfp.has_section('autorebuild'):
+                cfp.add_section('autorebuild')
+
+            cfp.set('autorebuild', 'enabled', set_autorebuild)
+            with open(self.osbs_config_filename, 'w') as fp:
+                cfp.write(fp)
+
+            self.repo.index.add([self.osbs_config_filename])
+            self.log.info('Config value changed, don\'t forget to commit'
+                          ' %s file', self.osbs_config_filename)
+        else:
+            self.log.info('Nothing to be done')
diff --git a/src/pyrpkg/cli.py b/src/pyrpkg/cli.py
index bdc877a..daa6daf 100755
--- a/src/pyrpkg/cli.py
+++ b/src/pyrpkg/cli.py
@@ -839,11 +839,16 @@ defined, packages will be built sequentially.""" % {'name': self.name})
         self.container_build_setup_parser = \
             self.subparsers.add_parser('container-build-setup',
                                        help='set options for container-build')
-        self.container_build_setup_parser.add_argument(
-            '--autorebuild',
+        group = self.container_build_setup_parser.add_mutually_exclusive_group(required=True)
+        group.add_argument(
+            '--get-autorebuild',
+            help='Get autorebuild value',
+            action='store_true',
+            default=None)
+        group.add_argument(
+            '--set-autorebuild',
             help='Turn autorebuilds on/off',
-            choices=['on', 'off'],
-            required=False,
+            choices=('true', 'false'),
             default=None)
         self.container_build_setup_parser.set_defaults(
             command=self.container_build_setup)
@@ -1069,7 +1074,8 @@ defined, packages will be built sequentially.""" % {'name': self.name})
         )
 
     def container_build_setup(self):
-        self.cmd.container_build_setup(autorebuild=self.args.autorebuild)
+        self.cmd.container_build_setup(get_autorebuild=self.args.get_autorebuild,
+                                       set_autorebuild=self.args.set_autorebuild)
 
     def diff(self):
         self.cmd.diff(self.args.cached, self.args.files)

