]> git.ipfire.org Git - pakfire.git/blobdiff - python/pakfire/cli.py
Create an extra namespace for build environments and private network.
[pakfire.git] / python / pakfire / cli.py
index bfdc29ad5d8760d602956df2d17d290398b1e498..a80b397efbd987b29bc9555195282ccaa6a90e63 100644 (file)
@@ -29,6 +29,7 @@ import tempfile
 import base
 import client
 import config
+import daemon
 import logger
 import packages
 import repository
@@ -542,6 +543,8 @@ class CliBuilder(Cli):
                        help=_("Run a shell after a successful build."))
                sub_build.add_argument("--no-install-test", action="store_true",
                        help=_("Do not perform the install test."))
+               sub_build.add_argument("--private-network", action="store_true",
+                       help=_("Disable network in container."))
 
        def parse_command_shell(self):
                # Implement the "shell" command.
@@ -553,6 +556,8 @@ class CliBuilder(Cli):
 
                sub_shell.add_argument("-m", "--mode", nargs="?", default="development",
                        help=_("Mode to run in. Is either 'release' or 'development' (default)."))
+               sub_shell.add_argument("--private-network", action="store_true",
+                       help=_("Disable network in container."))
 
        def parse_command_dist(self):
                # Implement the "dist" command.
@@ -579,22 +584,25 @@ class CliBuilder(Cli):
                else:
                        raise FileNotFoundError, pkg
 
-               # Check whether to enable the install test.
-               install_test = not self.args.no_install_test
+               # Build argument list.
+               kwargs = {
+                       "after_shell"   : self.args.after_shell,
+                       # Check whether to enable the install test.
+                       "install_test"  : not self.args.no_install_test,
+                       "result_dir"    : [self.args.resultdir,],
+                       "shell"         : True,
+               }
 
                if self.args.mode == "release":
-                       release_build = True
+                       kwargs["release_build"] = True
                else:
-                       release_build = False
+                       kwargs["release_build"] = False
+
+               if self.args.private_network:
+                       kwargs["private_network"] = True
 
                p = self.create_pakfire()
-               p.build(pkg,
-                       install_test=install_test,
-                       resultdirs=[self.args.resultdir,],
-                       shell=True,
-                       after_shell=self.args.after_shell,
-                       release_build=release_build,
-               )
+               p.build(pkg, **kwargs)
 
        def handle_shell(self):
                pkg = None
@@ -616,7 +624,16 @@ class CliBuilder(Cli):
                        release_build = False
 
                p = self.create_pakfire()
-               p.shell(pkg, release_build=release_build)
+
+               kwargs = {
+                       "release_build" : release_build,
+               }
+
+               # Private network
+               if self.args.private_network:
+                       kwargs["private_network"] = True
+
+               p.shell(pkg, **kwargs)
 
        def handle_dist(self):
                # Get the packages from the command line options
@@ -665,7 +682,7 @@ class CliServer(Cli):
                # Finally parse all arguments from the command line and save them.
                self.args = self.parser.parse_args()
 
-               self.server = server.Server(**self.pakfire_args)
+               #self.server = server.Server(**self.pakfire_args)
 
                self.action2func = {
                        "build"      : self.handle_build,
@@ -879,15 +896,11 @@ class CliClient(Cli):
                        "test"        : self.handle_test,
                }
 
-               # Read configuration for the pakfire client.
+               # Read configuration.
                self.config = config.ConfigClient()
 
                # Create connection to pakfire hub.
-               self.client = client.PakfireUserClient(
-                       self.config.get("client", "server"),
-                       self.config.get("client", "username"),
-                       self.config.get("client", "password"),
-               )
+               self.client = client.PakfireClient(self.config)
 
        @property
        def pakfire_args(self):
@@ -989,21 +1002,23 @@ class CliClient(Cli):
 
                        # Format arches.
                        if self.args.arch:
-                               arches = self.args.arch.replace(",", " ")
+                               arches = self.args.arch.split(",")
                        else:
                                arches = None
 
                        # Create a new build on the server.
-                       build = self.client.build_create(package, arches=arches)
-
-                       # XXX Print the resulting build.
-                       print build
+                       build_id = self.client.build_create(package, build_type="scratch",
+                               arches=arches)
 
                finally:
                        # Cleanup the temporary directory and all files.
                        if os.path.exists(temp_dir):
                                shutil.rmtree(temp_dir, ignore_errors=True)
 
+               # Monitor the build.
+               if build_id:
+                       self.watch_build(build_id)
+
        def handle_info(self):
                ret = []
 
@@ -1183,6 +1198,11 @@ class CliClient(Cli):
                res = self.client.test_code(error_code)
                print _("Reponse from the server: %s") % res
 
+       def watch_build(self, build_id):
+               print self.client.build_get(build_id)
+               # XXX TODO
+               print build_id
+
 
 class CliDaemon(Cli):
        def __init__(self):
@@ -1200,10 +1220,11 @@ class CliDaemon(Cli):
                        Runs the pakfire daemon with provided settings.
                """
                # Read the configuration file for the daemon.
-               conf = config.ConfigDaemon()
+               self.config = config.ConfigDaemon()
+               logger.setup_logging(self.config)
 
                # Create daemon instance.
-               d = pakfire.client.PakfireDaemon()
+               d = daemon.PakfireDaemon(self.config)
                try:
                        d.run()