]> git.ipfire.org Git - pakfire.git/commitdiff
Step two of code cleanup.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 9 Apr 2011 15:16:44 +0000 (17:16 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 9 Apr 2011 15:16:44 +0000 (17:16 +0200)
Created api.py which is supposed to be imported by other applications.

pakfire/__init__.py
pakfire/api.py [new file with mode: 0644]
pakfire/base.py
pakfire/cli.py
po/pakfire.pot

index 117ea065f99af1056c03de00d3d7f01dad46fd5c..efb21e43af14d9719f0e56484d991b7f69ad94c6 100644 (file)
@@ -1,222 +1,7 @@
 #!/usr/bin/python
 
-import base
-import builder
-import depsolve
-import packages
-import transaction
+from base import Pakfire
 
-from errors import *
+from constants import *
 
-Builder = builder.Builder
-Pakfire = base.Pakfire
-
-def install(requires, **pakfire_args):
-       pakfire = Pakfire(**pakfire_args)
-
-       ds = depsolve.DependencySet(pakfire=pakfire)
-
-       for req in requires:
-               if isinstance(req, packages.BinaryPackage):
-                       ds.add_package(req)
-               else:
-                       ds.add_requires(req)
-
-       ds.resolve()
-       ds.dump()
-
-       ret = cli.ask_user(_("Is this okay?"))
-       if not ret:
-               return
-
-       ts = transaction.Transaction(pakfire, ds)
-       ts.run()
-
-def remove(**pakfire_args):
-       pass
-
-def update(pkgs, **pakfire_args):
-       pakfire = Pakfire(**pakfire_args)
-
-       ds = depsolve.DependencySet(pakfire=self)
-
-       for pkg in ds.packages:
-               # Skip unwanted packages (passed on command line)
-               if pkgs and not pkg.name in pkgs:
-                       continue
-
-               updates = pakfire.repos.get_by_name(pkg.name)
-               updates = packages.PackageListing(updates)
-
-               latest = updates.get_most_recent()
-
-               # If the current package is already the latest
-               # we skip it.
-               if latest == pkg:
-                       continue
-
-               # Otherwise we want to update the package.
-               ds.add_package(latest)
-
-       ds.resolve()
-       ds.dump()
-
-       ret = cli.ask_user(_("Is this okay?"))
-       if not ret:
-               return
-
-       ts = transaction.Transaction(pakfire, ds)
-       ts.run()
-
-def info(patterns, **pakfire_args):
-       # Create pakfire instance.
-       pakfire = Pakfire(**pakfire_args)
-
-       pkgs = []
-
-       for pattern in patterns:
-               pkgs += pakfire.repos.get_by_glob(pattern)
-
-       return packages.PackageListing(pkgs)
-
-def search(pattern, **pakfire_args):
-       # Create pakfire instance.
-       pakfire = Pakfire(**pakfire_args)
-
-       # Do the search.
-       pkgs = pakfire.repos.search(pattern)
-
-       # Return the output as a package listing.
-       return packages.PackageListing(pkgs)
-
-def groupinstall(group, **pakfire_args):
-       pakfire = Pakfire(**pakfire_args)
-
-       pkgs = grouplist(group, **pakfire_args)
-
-       install(pkgs, **pakfire_args)
-
-def grouplist(group, **pakfire_args):
-       pakfire = Pakfire(**pakfire_args)
-
-       pkgs = pakfire.repos.get_by_group(group)
-
-       pkgs = packages.PackageListing(pkgs)
-       pkgs.unique()
-
-       return [p.name for p in pkgs]
-
-def build(pkg, distro_config=None, build_id=None, resultdirs=None, **pakfire_args):
-       if not resultdirs:
-               resultdirs = []
-
-       b = Builder(pkg, distro_config, build_id=build_id, **pakfire_args)
-
-       # Make shortcut to pakfire instance.
-       p = b.pakfire
-
-       # Always include local repository.
-       resultdirs.append(p.repos.local_build.path)
-
-       try:
-               b.prepare()
-               b.extract()
-               b.build()
-               b.install_test()
-
-               # Copy-out all resultfiles
-               for resultdir in resultdirs:
-                       if not resultdir:
-                               continue
-
-                       b.copy_result(resultdir)
-
-       except BuildError:
-               b.shell()
-
-       finally:
-               b.destroy()
-
-def shell(pkg, distro_config=None, **pakfire_args):
-       b = builder.Builder(pkg, distro_config, **pakfire_args)
-
-       try:
-               b.prepare()
-               b.extract()
-               b.shell()
-       finally:
-               b.destroy()
-
-def dist(pkg, resultdirs=None, **pakfire_args):
-       b = builder.Builder(pkg, **pakfire_args)
-       p = b.pakfire
-
-       if not resultdirs:
-               resultdirs = []
-
-       # Always include local repository
-       resultdirs.append(p.repos.local_build.path)
-
-       try:
-               b.prepare()
-               b.extract(build_deps=False)
-
-               # Run the actual dist.
-               b.dist()
-
-               # Copy-out all resultfiles
-               for resultdir in resultdirs:
-                       if not resultdir:
-                               continue
-
-                       b.copy_result(resultdir)
-       finally:
-               b.destroy()
-
-def provides(patterns, **pakfire_args):
-       # Create pakfire instance.
-       pakfire = Pakfire(**pakfire_args)
-
-       pkgs = []
-       for pattern in patterns:
-               requires = depsolve.Requires(None, pattern)
-               pkgs += pakfire.repos.get_by_provides(requires)
-
-       pkgs = packages.PackageListing(pkgs)
-       #pkgs.unique()
-
-       return pkgs
-
-def requires(patterns, **pakfire_args):
-       # Create pakfire instance.
-       pakfire = Pakfire(**pakfire_args)
-
-       pkgs = []
-       for pattern in patterns:
-               requires = depsolve.Requires(None, pattern)
-               pkgs += pakfire.repos.get_by_requires(requires)
-
-       pkgs = packages.PackageListing(pkgs)
-       #pkgs.unique()
-
-       return pkgs
-
-def repo_create(path, input_paths, **pakfire_args):
-       pakfire = Pakfire(**pakfire_args)
-
-       repo = repository.LocalBinaryRepository(
-               pakfire,
-               name="new",
-               description="New repository.",
-               path=path,
-       )
-
-       for input_path in input_paths:
-               repo._collect_packages(input_path)
-
-       repo.save()
-
-def repo_list(**pakfire_args):
-       pakfire = Pakfire(**pakfire_args)
-
-       return pakfire.repos.all
+__version__ = PAKFIRE_VERSION
diff --git a/pakfire/api.py b/pakfire/api.py
new file mode 100644 (file)
index 0000000..ff6a070
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+
+import base
+
+from errors import *
+
+Pakfire = base.Pakfire
+
+def install(requires, **pakfire_args):
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.install(requires)
+
+def remove(**pakfire_args):
+       pass
+
+def update(pkgs, **pakfire_args):
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.update(pkgs)
+
+def info(patterns, **pakfire_args):
+       # Create pakfire instance.
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.info(patterns)
+
+def search(pattern, **pakfire_args):
+       # Create pakfire instance.
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.search(pattern)
+
+def groupinstall(group, **pakfire_args):
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.groupinstall(group)
+
+def grouplist(group, **pakfire_args):
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.grouplist(group)
+
+def build(pkg, **kwargs):
+       return Pakfire.build(pkg, **kwargs)
+
+def shell(pkg, **kwargs):
+       return Pakfire.shell(pkg, **kwargs)
+
+def dist(pkg, **kwargs):
+       return Pakfire.dist(pkg, **kwargs)
+
+def provides(patterns, **pakfire_args):
+       # Create pakfire instance.
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.provides(patterns)
+
+def requires(patterns, **pakfire_args):
+       # Create pakfire instance.
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.requires(requires)
+
+def repo_create(path, input_paths, **pakfire_args):
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.repo_create(path, input_paths)
+
+def repo_list(**pakfire_args):
+       pakfire = Pakfire(**pakfire_args)
+
+       return pakfire.repo_list()
index a5bffe4d840e804a021d9c0ddd2b075fe2b6f53e..963334d794957df04e21ff8541972cd64bc13c5a 100644 (file)
@@ -5,6 +5,7 @@ import os
 import random
 import string
 
+import builder
 import config
 import depsolve
 import distro
@@ -17,8 +18,6 @@ import util
 from constants import *
 from i18n import _
 
-__version__ = PAKFIRE_VERSION
-
 class Pakfire(object):
        def __init__(self, builder=False, configs=[], disable_repos=None,
                        distro_config=None):
@@ -49,10 +48,10 @@ class Pakfire(object):
                self.distro = distro.Distribution(self, distro_config)
                self.repos  = repository.Repositories(self)
 
-               # XXX Disable repositories if passed on command line
-               #if disable_repos:
-               #       for repo in disable_repos:
-               #               self.repos.disable_repo(repo)
+               # Disable repositories if passed on command line
+               if disable_repos:
+                       for repo in disable_repos:
+                               self.repos.disable_repo(repo)
 
                # Update all indexes of the repositories (not force) so that we will
                # always work with valid data.
@@ -82,7 +81,6 @@ class Pakfire(object):
                """
                        Check if we can build for arch.
                """
-
                # If no arch was given on the command line we build for our
                # own arch which should always work.
                if not arch:
@@ -92,3 +90,187 @@ class Pakfire(object):
                        raise BuildError, "Cannot build for the target architecture: %s" % arch
 
                raise BuildError, arch
+
+       def install(self, requires):
+               ds = depsolve.DependencySet(pakfire=self)
+
+               for req in requires:
+                       if isinstance(req, packages.BinaryPackage):
+                               ds.add_package(req)
+                       else:
+                               ds.add_requires(req)
+
+               ds.resolve()
+               ds.dump()
+
+               ret = cli.ask_user(_("Is this okay?"))
+               if not ret:
+                       return
+
+               ts = transaction.Transaction(self, ds)
+               ts.run()
+
+       def update(self, pkgs):
+               ds = depsolve.DependencySet(pakfire=self)
+
+               for pkg in ds.packages:
+                       # Skip unwanted packages (passed on command line)
+                       if pkgs and not pkg.name in pkgs:
+                               continue
+
+                       updates = self.repos.get_by_name(pkg.name)
+                       updates = packages.PackageListing(updates)
+
+                       latest = updates.get_most_recent()
+
+                       # If the current package is already the latest
+                       # we skip it.
+                       if latest == pkg:
+                               continue
+
+                       # Otherwise we want to update the package.
+                       ds.add_package(latest)
+
+               ds.resolve()
+               ds.dump()
+
+               ret = cli.ask_user(_("Is this okay?"))
+               if not ret:
+                       return
+
+               ts = transaction.Transaction(self, ds)
+               ts.run()
+
+       def info(self):
+               pkgs = []
+
+               for pattern in patterns:
+                       pkgs += self.repos.get_by_glob(pattern)
+
+               return packages.PackageListing(pkgs)
+
+       def search(self, pattern):
+               # Do the search.
+               pkgs = self.repos.search(pattern)
+
+               # Return the output as a package listing.
+               return packages.PackageListing(pkgs)
+
+       def groupinstall(self, group):
+               pkgs = self.grouplist(group)
+
+               self.install(pkgs)
+
+       def grouplist(self, group):
+               pkgs = self.repos.get_by_group(group)
+
+               pkgs = packages.PackageListing(pkgs)
+               pkgs.unique()
+
+               return [p.name for p in pkgs]
+
+       @staticmethod
+       def build(pkg, resultdirs=None, **kwargs):
+               if not resultdirs:
+                       resultdirs = []
+
+               b = builder.Builder(pkg, **kwargs)
+               p = b.pakfire
+
+               # Always include local repository.
+               resultdirs.append(p.repos.local_build.path)
+
+               try:
+                       b.prepare()
+                       b.extract()
+                       b.build()
+                       b.install_test()
+
+                       # Copy-out all resultfiles
+                       for resultdir in resultdirs:
+                               if not resultdir:
+                                       continue
+
+                               b.copy_result(resultdir)
+
+               except BuildError:
+                       b.shell()
+
+               finally:
+                       b.destroy()
+
+       @staticmethod
+       def shell(pkg, **kwargs):
+               b = builder.Builder(pkg, **kwargs)
+
+               try:
+                       b.prepare()
+                       b.extract()
+                       b.shell()
+               finally:
+                       b.destroy()
+
+       @staticmethod
+       def dist(pkg, resultdirs=None, **pakfire_args):
+               b = builder.Builder(pkg, **pakfire_args)
+               p = b.pakfire
+
+               if not resultdirs:
+                       resultdirs = []
+
+               # Always include local repository
+               resultdirs.append(p.repos.local_build.path)
+
+               try:
+                       b.prepare()
+                       b.extract(build_deps=False)
+
+                       # Run the actual dist.
+                       b.dist()
+
+                       # Copy-out all resultfiles
+                       for resultdir in resultdirs:
+                               if not resultdir:
+                                       continue
+
+                               b.copy_result(resultdir)
+               finally:
+                       b.destroy()
+
+       def provides(self, patterns):
+               pkgs = []
+               for pattern in patterns:
+                       requires = depsolve.Requires(None, pattern)
+                       pkgs += self.repos.get_by_provides(requires)
+
+               pkgs = packages.PackageListing(pkgs)
+               #pkgs.unique()
+
+               return pkgs
+
+       def requires(self, patterns):
+               pkgs = []
+               for pattern in patterns:
+                       requires = depsolve.Requires(None, pattern)
+                       pkgs += self.repos.get_by_requires(requires)
+
+               pkgs = packages.PackageListing(pkgs)
+               #pkgs.unique()
+
+               return pkgs
+
+       def repo_create(self, path, input_paths):
+               repo = repository.LocalBinaryRepository(
+                       self,
+                       name="new",
+                       description="New repository.",
+                       path=path,
+               )
+
+               for input_path in input_paths:
+                       repo._collect_packages(input_path)
+
+               repo.save()
+
+       def repo_list(self):
+               return self.repos.all
index c4eab21607ebc5608896fc44a7f6fbc9ef9da13e..35a1ef5273efda366c9ef879514fed85dee4d71e 100644 (file)
@@ -8,7 +8,7 @@ import repository
 import server
 import util
 
-import pakfire
+import pakfire.api as pakfire
 from constants import *
 from i18n import _
 
@@ -348,7 +348,7 @@ class CliBuilder(Cli):
                        "arch" : self.args.arch,
                }
 
-               pakfire.build(pkg, distro_config, resultdirs=[self.args.resultdir,],
+               pakfire.build(pkg, distro_config=distro_config, resultdirs=[self.args.resultdir,],
                        **self.pakfire_args)
 
        def handle_shell(self):
index dd3dbde389669148f62af0600ee4b5c0f0dad23b..9c78be8d0a64ae0ffc38526e704e8d899d53b1a6 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-04-09 14:55+0200\n"
+"POT-Creation-Date: 2011-04-09 17:16+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,6 +17,10 @@ msgstr ""
 "Content-Type: text/plain; charset=CHARSET\n"
 "Content-Transfer-Encoding: 8bit\n"
 
+#: ../pakfire/base.py:106 ../pakfire/base.py:137
+msgid "Is this okay?"
+msgstr ""
+
 #: ../pakfire/builder.py:188
 #, python-format
 msgid "Extracting: %s (source)"
@@ -281,10 +285,6 @@ msgstr ""
 msgid "Total download size: %s"
 msgstr ""
 
-#: ../pakfire/__init__.py:28 ../pakfire/__init__.py:64
-msgid "Is this okay?"
-msgstr ""
-
 #: ../pakfire/packages/base.py:71
 msgid "Name"
 msgstr ""