import logging
import os
import pakfire
+import tempfile
from . import aws
from . import bugtracker
return database.Connection(hostname, name, user=user, password=password)
+ def pakfire(self, config, offline=True, **kwargs):
+ """
+ Launches a new Pakfire instance with the given configuration
+ """
+ log.debug("Launching pakfire with configuration:\n%s" % config)
+
+ # Write configuration to file
+ t = self._write_tempfile(config)
+
+ # Launch a new Pakfire instance
+ try:
+ return pakfire.Pakfire(conf=t, logger=log.log, offline=offline, **kwargs)
+
+ finally:
+ # Delete the configuration file
+ os.unlink(t)
+
+ def _write_tempfile(self, content):
+ """
+ Writes the content to a temporary file and returns its path
+ """
+ t = tempfile.NamedTemporaryFile(delete=False)
+
+ # Write the content
+ t.write(content.encode())
+ t.close()
+
+ return t.name
+
async def open(self, path):
"""
Opens a package and returns the archive
#!/usr/bin/python
import logging
-import os
import pakfire
-import tempfile
from . import base
from . import packages
from . import sources
from .decorators import *
+log = logging.getLogger("pakfire.distros")
+
class Distributions(base.Object):
def _get_distribution(self, query, *args):
res = self.db.get(query, *args)
def __str__(self):
return self.name
- def pakfire(self, arch=None, **kwargs):
+ def pakfire(self, **kwargs):
"""
Returns a Pakfire instance for this distribution
"""
- # Fetch a logger
- logger = logging.getLogger("pakfire")
-
# Generate configuration
config = self.get_config(local=True)
- # Write configuration to file
- t = tempfile.NamedTemporaryFile(delete=False)
- t.write(config.encode())
- t.close()
-
- # Launch a new Pakfire instance
- try:
- return pakfire.Pakfire(arch=arch, conf=t.name, logger=logger.log, **kwargs)
-
- finally:
- # Delete the configuration file
- os.unlink(t.name)
+ return self.backend.pakfire(config=config, **kwargs)
def get_config(self, local=False):
try: