import mimetypes
import os
import shutil
-import urllib.parse
import pakfire
+from pakfire.constants import (
+ PAKFIRE_DIGEST_SHA512,
+ PAKFIRE_DIGEST_SHA256,
+)
from . import base
from . import database
package.hexdigest_sha512,
)
- # XXX Import filelist
- for file in package.filelist:
- print(file)
-
- print(pkg)
+ # Import filelist
+ pkg._import_filelist(archive.filelist)
# Import package data
pkg._import_archive(archive)
# Copy the file
shutil.copyfile(archive.path, path)
+ # XXX use async copy here
+
# Store the path
self._set_attribute("path", path)
+ def _import_filelist(self, filelist):
+ log.debug("Importing filelist for %s" % self)
+
+ # XXX capabilities
+
+ self.db.executemany("""
+ INSERT INTO
+ filelists
+ (
+ pkg_id,
+ path,
+ size,
+ type,
+ mode,
+ "user",
+ "group",
+ ctime,
+ mtime,
+ digest_sha512,
+ digest_sha256
+ )
+ VALUES
+ (
+ %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s
+ )""",
+ ((
+ self.id,
+ file.path,
+ file.size,
+ file.type,
+ file.mode,
+ file.user,
+ file.group,
+ file.ctime,
+ file.mtime,
+ file.digest(PAKFIRE_DIGEST_SHA512),
+ file.digest(PAKFIRE_DIGEST_SHA256),
+ ) for file in filelist),
+ )
+
@lazy_property
def builds(self):
builds = self.backend.builds._get_builds("""
@lazy_property
def filelist(self):
res = self.db.query("SELECT * FROM filelists \
- WHERE pkg_id = %s ORDER BY name", self.id)
+ WHERE pkg_id = %s ORDER BY path", self.id)
ret = []
for row in res:
def get_file(self, filename):
res = self.db.get("SELECT * FROM filelists \
- WHERE pkg_id = %s AND name = %s", self.id, filename)
+ WHERE pkg_id = %s AND path = %s", self.id, filename)
if res:
return File(self.backend, self, res)
- def add_file(self, name, size, hash_sha512, type, config, mode, user, group, mtime, capabilities):
- # Convert mtime from seconds since epoch to datetime
- mtime = datetime.datetime.utcfromtimestamp(float(mtime))
-
- self.db.execute("INSERT INTO filelists(pkg_id, name, size, hash_sha512, type, config, mode, \
- \"user\", \"group\", mtime, capabilities) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
- self.id, name, size, hash_sha512, type, config, mode, user, group, mtime, capabilities)
-
async def open(self):
"""
Opens the package archive and returns a handle
@property
def name(self):
- return self.data.name
+ return self.data.path
@property
def size(self):
return self.data.size
- @property
- def hash_sha512(self):
- return self.data.hash_sha512
-
@property
def type(self):
return self.data.type
def group(self):
return self.data.group
+ @property
+ def ctime(self):
+ return self.data.ctime
+
@property
def mtime(self):
return self.data.mtime
def capabilities(self):
return self.data.capabilities
+ # Digest SHA512
+
+ @property
+ def digest_sha512(self):
+ return self.data.digest_sha512
+
+ # Digest SHA256
+
+ @property
+ def digest_sha256(self):
+ return self.data.digest_sha256
+
def is_downloadable(self):
"""
Returns True if this file is downloadable