From d862cc5458aba92f14c5440d0ca0608c742ffbcd Mon Sep 17 00:00:00 2001
From: Chenxiong Qi <cqi@redhat.com>
Date: Sep 29 2016 07:05:21 +0000
Subject: New fedpkg-stage for developers to use stage infra


Fix #41

Signed-off-by: Chenxiong Qi <cqi@redhat.com>

---

diff --git a/setup.cfg b/setup.cfg
index 01b1ace..fa78577 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -5,4 +5,7 @@ formats=bztar
 verbosity=2
 detailed-errors=1
 with-coverage=1
-cover-package=fedpkg
\ No newline at end of file
+cover-package=fedpkg
+
+[flake8]
+max-line-length = 100
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 9ad5f7f..248b702 100755
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,10 @@ setup(
     url="http://fedorahosted.org/fedpkg",
     package_dir={'': 'src'},
     packages=['fedpkg'],
-    scripts=['src/bin/fedpkg'],
+    scripts=[
+        'src/bin/fedpkg',
+        'src/bin/fedpkg-stage',
+    ],
     data_files=[(bash_completion_dir(), ['src/fedpkg.bash']),
                 ('/etc/rpkg', ['src/fedpkg.conf']),
                 ('/usr/share/zsh/site-functions', ['src/_fedpkg']),
diff --git a/src/bin/fedpkg-stage b/src/bin/fedpkg-stage
new file mode 100644
index 0000000..b7bdb34
--- /dev/null
+++ b/src/bin/fedpkg-stage
@@ -0,0 +1,16 @@
+#!/usr/bin/python
+# fedpkg-stage - a script to interact with the Fedora Packaging system
+#
+# Copyright (C) 2016 Red Hat Inc.
+# Author(s): Chenxiong Qi <cqi@redhat.com>
+#
+# This program 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; either version 2 of the License, or (at your
+# option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
+# the full text of the license.
+
+from fedpkg.__main__ import main
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file
diff --git a/src/fedpkg-stage.conf b/src/fedpkg-stage.conf
new file mode 100644
index 0000000..b1a488e
--- /dev/null
+++ b/src/fedpkg-stage.conf
@@ -0,0 +1,23 @@
+[fedpkg-stage]
+lookaside = http://pkgs.stg.fedoraproject.org/repo/pkgs
+lookasidehash = md5
+lookaside_cgi = https://pkgs.stg.fedoraproject.org/repo/pkgs/upload.cgi
+gitbaseurl = ssh://%(user)s@pkgs.stg.fedoraproject.org/%(module)s
+anongiturl = git://pkgs.stg.fedoraproject.org/%(module)s
+tracbaseurl = https://%(user)s:%(password)s@fedorahosted.org/rel-eng/login/xmlrpc
+branchre = f\d$|f\d\d$|el\d$|olpc\d$|master$
+kojiconfig = /etc/koji/stg-config
+build_client = koji
+clone_config =
+  bz.default-tracker partner-bugzilla.redhat.com
+  bz.default-product Fedora
+  bz.default-version rawhide
+  bz.default-component %(module)s
+  sendemail.to %(module)s-owner@fedoraproject.org
+distgit_namespaced = True
+
+[fedpkg-stage.bodhi]
+url = https://bodhi.stg.fedoraproject.org/
+
+[fedpkg-stage.pkgdb]
+url = https://admin.stg.fedoraproject.org/pkgdb/
\ No newline at end of file
diff --git a/src/fedpkg.conf b/src/fedpkg.conf
index 74e73ff..4cadaeb 100644
--- a/src/fedpkg.conf
+++ b/src/fedpkg.conf
@@ -15,3 +15,9 @@ clone_config =
   bz.default-component %(module)s
   sendemail.to %(module)s-owner@fedoraproject.org
 distgit_namespaced = True
+
+[fedpkg.bodhi]
+url = https://bodhi.fedoraproject.org/
+
+[fedpkg.pkgdb]
+url = https://admin.fedoraproject.org/pkgdb/
\ No newline at end of file
diff --git a/src/fedpkg/__init__.py b/src/fedpkg/__init__.py
index a0658c9..9d23638 100644
--- a/src/fedpkg/__init__.py
+++ b/src/fedpkg/__init__.py
@@ -302,18 +302,20 @@ class Commands(pyrpkg.Commands):
 
         self.commit(message=message)
 
-    def update(self, template='bodhi.template', bugs=[]):
+    def update(self, bodhi_config, template='bodhi.template', bugs=[]):
         """Submit an update to bodhi using the provided template."""
 
         # build up the bodhi arguments, based on which version of bodhi is
         # installed
         bodhi_major_version = _get_bodhi_version()[0]
         if bodhi_major_version < 2:
-            cmd = ['bodhi', '--new', '--release', self.branch_merge,
+            cmd = ['bodhi', '--bodhi-url', bodhi_config['url'],
+                   '--new', '--release', self.branch_merge,
                    '--file', 'bodhi.template', self.nvr, '--username',
                    self.user]
         elif bodhi_major_version == 2:
-            cmd = ['bodhi', 'updates', 'new', '--file', 'bodhi.template',
+            cmd = ['bodhi', '--bodhi-url', bodhi_config['url'],
+                   'updates', 'new', '--file', 'bodhi.template',
                    '--user', self.user, self.nvr]
         else:
             msg = 'This system has bodhi v{0}, which is unsupported.'
diff --git a/src/fedpkg/__main__.py b/src/fedpkg/__main__.py
index dd3045b..2624f21 100644
--- a/src/fedpkg/__main__.py
+++ b/src/fedpkg/__main__.py
@@ -26,11 +26,14 @@ import pyrpkg.utils
 import fedpkg
 
 
+cli_name = os.path.basename(sys.argv[0])
+
+
 def main():
     # Setup an argparser and parse the known commands to get the config file
     parser = argparse.ArgumentParser(add_help=False)
     parser.add_argument('-C', '--config', help='Specify a config file to use',
-                        default='/etc/rpkg/fedpkg.conf')
+                        default='/etc/rpkg/%s.conf' % cli_name)
 
     (args, other) = parser.parse_known_args()
 
@@ -44,7 +47,7 @@ def main():
     config = ConfigParser()
     config.read(args.config)
 
-    client = fedpkg.cli.fedpkgClient(config)
+    client = fedpkg.cli.fedpkgClient(config, name=cli_name)
     client.do_imports(site='fedpkg')
     client.parse_cmdline()
 
diff --git a/src/fedpkg/cli.py b/src/fedpkg/cli.py
index a97fe4f..936dcfa 100644
--- a/src/fedpkg/cli.py
+++ b/src/fedpkg/cli.py
@@ -73,9 +73,10 @@ class fedpkgClient(cliClient):
                 self.cmd.retire(self.args.reason)
             self.push()
 
+            pkgdb_config = dict(self.config.items('%s.pkgdb' % self.name))
             branch = self.cmd.branch_merge
-            pkgdb = pkgdb2client.PkgDB(
-                login_callback=pkgdb2client.ask_password)
+            pkgdb = pkgdb2client.PkgDB(url=pkgdb_config['url'],
+                                       login_callback=pkgdb2client.ask_password)
             pkgdb.retire_packages(module_name, branch, namespace=namespace)
         except Exception as e:
             self.log.error('Could not retire package: %s' % e)
@@ -164,7 +165,8 @@ suggest_reboot=False
         hash = self.cmd.lookasidecache.hash_file('bodhi.template', 'sha1')
         if hash != orig_hash:
             try:
-                self.cmd.update('bodhi.template')
+                bodhi_config = dict(self.config.items('%s.bodhi' % self.name))
+                self.cmd.update(bodhi_config, template='bodhi.template')
             except Exception as e:
                 self.log.error('Could not generate update request: %s' % e)
                 sys.exit(1)
diff --git a/test/fedpkg-test.conf b/test/fedpkg-test.conf
index 34d12bf..37507ec 100644
--- a/test/fedpkg-test.conf
+++ b/test/fedpkg-test.conf
@@ -8,3 +8,9 @@ anongiturl = git://pkgs.example.com/%(module)s
 branchre = f\d$|f\d\d$|el\d$|olpc\d$|master$
 kojiconfig = /etc/koji.conf
 build_client = koji
+
+[fedpkg.bodhi]
+url = https://bodhi.dummy.example.com/
+
+[fedpkg.pkgdb]
+url = https://admin.dummy.example.com/pkgdb/
\ No newline at end of file

