From bf8fe6793e27d4c3c26b4d8512ee7f7a4671dc9d Mon Sep 17 00:00:00 2001 From: "A. Murat Eren" Date: Wed, 27 Jul 2005 16:12:28 +0000 Subject: [PATCH] hmm.. AdditionalFiles ile ilgili bir sorun cikti.. Cozumu icin ya fileas diye bir attribute eklemek gerekiyordu, ya da util icerisindeki copy_file kodunun degistirilmesi gerekiyordu. Cunku aksi taktirde AF icerisindeki target ile gosterilen dosya adinda bir dizin yaratiyordu kod. Kendi isminden farkli bir isimle kopyalanmak istenen dosyalar icin target'ta dosya ismi belirtmek zorunlulugunu 'fileas' isimli attribute'te dosya ismini belirterek cozmek uygun gorundu. Aksi taktirde su anda bir suru yerde kullanilan ve o yerler icin duzgun calisan copy_file kodunu degistirmek gerekecekti. Simdi commit edecegim, sonra uzerinden bir daha gecip bu kodu refactor edecegiz. Ayrica filex.xml icerisinde additional file'lar yanlis sekilde ekleniyordu, Caglar onu fix etti.. Bu commit'te ikisi birden mevcut.. Afiyet olsun :( --- pisi/build.py | 53 ++++++++++++++++++++++++------------------------ pisi/specfile.py | 3 +++ pisi/util.py | 7 +++++-- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/pisi/build.py b/pisi/build.py index f6551efa..a0099261 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -227,21 +227,38 @@ class PisiBuild: fsize = "0" files.append(FileInfo(frpath, ftype, fsize, fhash)) - # append AdditionalFiles to files.xml - for afile in package.additionalFiles: - fpath = install_dir + afile.target - ftype = "AdditionalFile" - fhash = util.sha1_file(fpath) - fsize = str(os.path.getsize(fpath)) - frpath = util.removepathprefix(install_dir, fpath) # relative path - files.append(FileInfo(frpath, ftype, fsize, fhash)) - files.write(os.path.join(self.ctx.pkg_dir(), const.files_xml)) def buildPackages(self): """Build each package defined in PSPEC file. After this process there will be .pisi files hanging around, AS INTENDED ;)""" for package in self.spec.packages: + + c = os.getcwd() + + # add comar files to package + os.chdir(self.pspecDir) + for pcomar in package.providesComar: + fname = os.path.join(const.comar_dir, + pcomar.script) + pkg.add_to_package(fname) + + # store additional files + install_dir = self.ctx.pkg_dir() + const.install_dir_suffix + for afile in package.additionalFiles: + src = os.path.join(const.files_dir, afile.filename) + dest = os.path.join(install_dir + afile.target) + if not afile.fileas: + util.copy_file(src, dest, fileas=afile.filename) + dest += afile.filename + else: + util.copy_file(src, dest, fileas=afile.fileas) + dest += afile.fileas + if afile.permission: + os.chmod(dest, int(afile.permission) | 0777) + + os.chdir(c) + ui.action("** Building package %s\n" % package.name); ui.action("Generating %s..." % const.metadata_xml) @@ -259,26 +276,10 @@ class PisiBuild: ui.action("Creating PISI package %s\n" % name) pkg = Package(name, 'w') - c = os.getcwd() - - # add comar files to package - os.chdir(self.pspecDir) - for pcomar in package.providesComar: - fname = os.path.join(const.comar_dir, - pcomar.script) - pkg.add_to_package(fname) - - # store additional files - install_dir = self.ctx.pkg_dir() + const.install_dir_suffix - for afile in package.additionalFiles: - src = os.path.join(const.files_dir, afile.filename) - dest = os.path.join(install_dir + afile.target, afile.filename) - util.copy_file(src, dest) - if afile.permission: - os.chmod(dest, afile.permission) # add xmls and files os.chdir(self.ctx.pkg_dir()) + pkg.add_to_package(const.metadata_xml) pkg.add_to_package(const.files_xml) diff --git a/pisi/specfile.py b/pisi/specfile.py index 13fb99de..befbd3d0 100644 --- a/pisi/specfile.py +++ b/pisi/specfile.py @@ -37,6 +37,7 @@ class AdditionalFileInfo: self.target = getNodeAttribute(node, "target") self.permission = getNodeAttribute(node, "permission") self.owner = getNodeAttribute(node, "owner") + self.fileas = getNodeAttribute(node, "fileas") def elt(self, xml): node = xml.newNode("AdditionalFile") @@ -46,6 +47,8 @@ class AdditionalFileInfo: node.setAttribute("permission", self.permission) if self.owner: node.setAttribute("owner", self.owner) + if self.owner: + node.setAttribute("fileas", self.fileas) def verify(self): if not self.filename: return False diff --git a/pisi/util.py b/pisi/util.py index e21a2df0..9fde9d57 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -166,11 +166,14 @@ def dir_size(dir): yield sum([getsize(join(root, name)) for name in files if not islink(join(root,name))]) return sum( sizes() ) -def copy_file(src,dest): +def copy_file(src, dest, fileas=''): """copy source file to destination file""" check_file(src) check_dir(os.path.dirname(dest)) - shutil.copyfile(src, dest) + if not fileas: + shutil.copyfile(src, dest) + else: + shutil.copyfile(src, dest + '/' + fileas) def get_file_hashes(top, excludePrefixes=None, removePrefix=None): """Generator function iterates over a toplevel path and returns the