extras-buildsys/client client.py,1.30,1.31

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Thu Sep 1 20:36:14 UTC 2005


Author: dcbw

Update of /cvs/fedora/extras-buildsys/client
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv24808/client

Modified Files:
	client.py 
Log Message:
2005-09-01  Dan Williams <dcbw at redhat.com>

    * client/client.py
      server/Repo.py
      server/UserInterface.py
        - Implement package upload functionality using 'scp' as
            part of the 'build' command




Index: client.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/client/client.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- client.py	29 Aug 2005 19:28:45 -0000	1.30
+++ client.py	1 Sep 2005 20:36:12 -0000	1.31
@@ -46,6 +46,8 @@
         self.add_section("Server")
         self.set_option("Server", "use_ssl", "yes")
         self.set_option("Server", "address", "https://127.0.0.1:8887")
+        self.set_option("Server", "allow_uploads", "no")
+        self.set_option("Server", "upload_user", "me")
 
         self.add_section("User")
         self.set_option("User", "email", "foo at it.com")
@@ -142,19 +144,69 @@
         return cfg_email
 
     def _cmd_build(self, args):
-        if len(args) != 3:
+        if len(args) != 2 and len(args) != 3:
             raise CommandException("Invalid command.  The 'build' command takes 3 arguments.")
-        package = args[0]
-        source = args[1]
-        target_alias = args[2]
+
+        # Be smart about local SRPMs getting enqueued
+        if args[0].find('/') != -1 and os.path.exists(args[0]):
+            # We were given an RPM, find the package name
+            import rpmUtils
+            ts = rpmUtils.transaction.initReadOnlyTransaction()
+            hdr = rpmUtils.miscutils.hdrFromPackage(ts, args[0])
+            package = hdr['name']
+            source = args[0]
+            target_alias = args[1]
+            del hdr
+            del ts
+        else:
+            package = args[0]
+            source = args[1]
+            target_alias = args[2]
+
         is_srpm = False
         if source.endswith(".src.rpm"):
             if not os.path.exists(source):
                 raise CommandException("The SRPM %s does not exist." % source)
-        self._enqueue(package, source, target_alias)
-
-    def _enqueue(self, package, source, target_alias):
-        """ Enqueue a package on the server by CVS tag """
+            is_srpm = True
+            source = os.path.abspath(os.path.expanduser(source))
+        self._enqueue(is_srpm, package, source, target_alias)
+
+    def _upload_srpm(self, host, source, target_alias):
+        # Get the package upload directory from the server
+        (err, path) = self._server.srpm_upload_dir(target_alias)
+        if err != 0:
+            print "Error: Could not upload package %s.  " \
+                    "reason: couldn't get upload dir for %s" % (source, target_alias)
+            return (-1, source)
+
+        upload_file = os.path.join(path, os.path.basename(source))
+        user = None
+        if self._cfg.has_option("Server", "upload_user"):
+            user = self._cfg.get_str("Server", "upload_user")
+        else:
+            import pwd
+            user = pwd.getpwuid(os.getuid())[0]
+        cmd = "/usr/bin/scp %s %s@%s:%s" % (source, user, host, upload_file)
+        print "Executing: %s" % cmd
+        os.system(cmd)
+        return (0, upload_file)
+
+    def _enqueue(self, is_srpm, package, source, target_alias):
+        """ Enqueue a package on the server """
+
+        if self._cfg.get_bool("Server", "allow_uploads"):
+            import urllib
+            addr = self._cfg.get_str("Server", "address")
+            if addr.startswith("http") or addr.startswith("https"):
+                idx = addr.find('//')
+                addr = addr[idx:]
+            host_port, path = urllib.splithost(addr)
+            host, port = urllib.splitport(host_port)
+            # Don't upload if we're going to scp to the same machine we're on
+            if is_srpm and socket.gethostname() != host:
+                (err, source) = self._upload_srpm(host, source, target_alias)
+                if err == -1:
+                    sys.exit(1)
 
         use_ssl = self._cfg.get_bool("Server", "use_ssl")
         if use_ssl:




More information about the fedora-extras-commits mailing list