def build_packages(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: # store additional files c = os.getcwd() os.chdir(self.pspecDir) install_dir = self.bctx.pkg_dir() + ctx.const.install_dir_suffix for afile in package.additionalFiles: src = os.path.join(ctx.const.files_dir, afile.filename) dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target)) util.copy_file(src, dest) if afile.permission: os.chmod(dest, int(afile.permission) | 0777) os.chdir(c) name = util.package_name(package.name, self.spec.source.version, self.spec.source.release) ctx.ui.action(_("** Building package %s") % package.name); ctx.ui.action(_("Generating %s...") % ctx.const.files_xml) self.gen_files_xml(package) ctx.ui.info(_(" done.")) ctx.ui.action(_("Generating %s...") % ctx.const.metadata_xml) self.gen_metadata_xml(package) ctx.ui.info(_(" done.")) ctx.ui.action(_("Creating PISI package %s") % name) pkg = Package(name, 'w') # add comar files to package os.chdir(self.pspecDir) for pcomar in package.providesComar: fname = os.path.join(ctx.const.comar_dir, pcomar.script) pkg.add_to_package(fname) # add xmls and files os.chdir(self.bctx.pkg_dir()) pkg.add_to_package(ctx.const.metadata_xml) pkg.add_to_package(ctx.const.files_xml) # Now it is time to add files to the packages using newly # created files.xml files = Files() files.read(ctx.const.files_xml) for finfo in files.list: pkg.add_to_package("install/" + finfo.path) pkg.close() os.chdir(c) self.set_state("buildpackages") util.xterm_title_reset()
def resurrect_package(package_fn): """Resurrect the package in the PiSi databases""" metadata_xml = util.join_path(ctx.config.lib_dir(), package_fn, ctx.const.metadata_xml) if not exists(metadata_xml): return metadata = MetaData() metadata.read(metadata_xml) errs = metadata.has_errors() if errs: util.Checks.print_errors(errs) raise Error, _("MetaData format wrong") files_xml = util.join_path(ctx.config.lib_dir(), package_fn, ctx.const.files_xml) if not exists(files_xml): return files = Files() files.read(files_xml) if files.has_errors(): raise Error, _("Invalid %s") % ctx.const.files_xml virtual_install(metadata, files)
def resurrect_package(package_fn): """Resurrect the package in the PiSi databases""" from os.path import exists metadata_xml = util.join_path(ctx.config.lib_dir(), package_fn, ctx.const.metadata_xml) if not exists(metadata_xml): raise Error, _("Metadata XML '%s' cannot be found") % metadata_xml metadata = MetaData() metadata.read(metadata_xml) errs = metadata.errors() if errs: util.Checks.print_errors(errs) raise Error, _("MetaData format wrong (%s)") % package_fn ctx.ui.info(_('* Adding \'%s\' to db... ') % (metadata.package.name), noln=True) files_xml = util.join_path(ctx.config.lib_dir(), package_fn, ctx.const.files_xml) if not exists(files_xml): raise Error, _("Files XML '%s' cannot be found") % files_xml files = Files() files.read(files_xml) if files.errors(): raise Error, _("Invalid %s") % ctx.const.files_xml import pisi.atomicoperations pisi.atomicoperations.virtual_install(metadata, files) ctx.ui.info(_('OK.'))
def gen_files_xml(self, package): """Generetes files.xml using the path definitions in specfile and generated files by the build system.""" files = Files() install_dir = self.bctx.pkg_install_dir() collisions = check_path_collision(package, self.spec.packages) if collisions: raise Error(_('Path collisions detected')) d = {} for pinfo in package.paths: path = install_dir + pinfo.pathname for fpath, fhash in util.get_file_hashes(path, collisions, install_dir): frpath = util.removepathprefix(install_dir, fpath) # relative path ftype = get_file_type(frpath, package.paths) try: # broken links can cause problem fsize = str(os.path.getsize(fpath)) except OSError: fsize = "0" d[frpath] = FileInfo(frpath, ftype, fsize, fhash) for (p, fileinfo) in d.iteritems(): files.append(fileinfo) files_xml_path = os.path.join(self.bctx.pkg_dir(), ctx.const.files_xml) files.write(files_xml_path) self.files = files
def gen_files_xml(self, package): """Generates files.xml using the path definitions in specfile and the files produced by the build system.""" files = Files() if package.debug_package: install_dir = self.pkg_debug_dir() else: install_dir = self.pkg_install_dir() # FIXME: We need to expand globs before trying to calculate hashes # Not on the fly like now. # we'll exclude collisions in get_file_hashes. Having a # collisions list is not wrong, we must just handle it :). collisions = check_path_collision(package, self.spec.packages) # FIXME: material collisions after expanding globs could be # reported as errors d = {} def add_path(path): # add the files under material path for fpath, fhash in util.get_file_hashes(path, collisions, install_dir): if ctx.get_option('create_static') \ and fpath.endswith(ctx.const.ar_file_suffix) \ and not package.name.endswith(ctx.const.static_name_suffix) \ and util.is_ar_file(fpath): # if this is an ar file, and this package is not a static package, # don't include this file into the package. continue frpath = util.removepathprefix(install_dir, fpath) # relative path ftype, permanent = get_file_type(frpath, package.files, install_dir) fsize = util.dir_size(fpath) if not os.path.islink(fpath): st = os.stat(fpath) else: st = os.lstat(fpath) d[frpath] = FileInfo(path=frpath, type=ftype, permanent=permanent, size=fsize, hash=fhash, uid=str(st.st_uid), gid=str(st.st_gid), mode=oct(S_IMODE(st.st_mode))) for pinfo in package.files: wildcard_path = util.join_path(install_dir, pinfo.path) for path in glob.glob(wildcard_path): add_path(path) for (p, fileinfo) in d.iteritems(): files.append(fileinfo) files_xml_path = util.join_path(self.pkg_dir(), ctx.const.files_xml) files.write(files_xml_path) self.files = files
def resurrect_package(package_fn): """Resurrect the package in the PiSi databases""" from os.path import exists metadata_xml = util.join_path(ctx.config.lib_dir(), 'package', package_fn, ctx.const.metadata_xml) if not exists(metadata_xml): raise Error, _("Metadata XML '%s' cannot be found") % metadata_xml metadata = MetaData() metadata.read(metadata_xml) errs = metadata.errors() if errs: util.Checks.print_errors(errs) raise Error, _("MetaData format wrong (%s)") % package_fn # FIXME: there won't be any previous versions of the same package under /var/lib/pisi # therefore there won't be any need for this check and __is_virtual_upgrade function # this is just for backward compatibility for sometime # yes, this is an ugly hack passed = False if ctx.installdb.is_installed(metadata.package.name): passed = True if not passed: ctx.ui.info(_('* Adding \'%s\' to db... ') % (metadata.package.name), noln=True) files_xml = util.join_path(ctx.config.lib_dir(), 'package', package_fn, ctx.const.files_xml) if not exists(files_xml): raise Error, _("Files XML '%s' cannot be found") % files_xml files = Files() files.read(files_xml) if files.errors(): raise Error, _("Invalid %s") % ctx.const.files_xml import pisi.atomicoperations def f(txn): pisi.atomicoperations.virtual_install(metadata, files, txn) ctx.txn_proc(f) if not passed: ctx.ui.info(_('OK.'))
def gen_files_xml(self, package): """Generates files.xml using the path definitions in specfile and the files produced by the build system.""" files = Files() install_dir = self.bctx.pkg_install_dir() # FIXME: We need to expand globs before trying to calculate hashes # Not on the fly like now. # we'll exclude collisions in get_file_hashes. Having a # collisions list is not wrong, we must just handle it :). # sure -- exa collisions = check_path_collision(package, self.spec.packages) # FIXME: material collisions after expanding globs must be # reported as errors, and an exception must be raised d = {} def add_path(path): # add the files under material path for fpath, fhash in util.get_file_hashes(path, collisions, install_dir): frpath = util.removepathprefix(install_dir, fpath) # relative path ftype = get_file_type(frpath, package.files) try: # broken links and empty dirs can cause problem fsize = os.path.getsize(fpath) except OSError: fsize = None d[frpath] = FileInfo(path=frpath, type=ftype, size=fsize, hash=fhash) for pinfo in package.files: wildcard_path = util.join_path(install_dir, pinfo.path) for path in glob.glob(wildcard_path): add_path(path) for (p, fileinfo) in d.iteritems(): files.append(fileinfo) files_xml_path = util.join_path(self.bctx.pkg_dir(), ctx.const.files_xml) files.write(files_xml_path) self.files = files
def read(self, outdir = None): if not outdir: outdir = ctx.config.tmp_dir() # extract control files self.extract_PISI_files(outdir) self.metadata = MetaData() self.metadata.read( join(outdir, ctx.const.metadata_xml) ) if self.metadata.has_errors(): raise Error, _("MetaData format wrong") self.files = Files() self.files.read( join(outdir, ctx.const.files_xml) ) if self.files.has_errors(): raise Error, _("Invalid %s") % ctx.const.files_xml
def gen_files_xml(self, package): """Generates files.xml using the path definitions in specfile and the files produced by the build system.""" files = Files() if package.debug_package: install_dir = self.pkg_debug_dir() else: install_dir = self.pkg_install_dir() # FIXME: We need to expand globs before trying to calculate hashes # Not on the fly like now. # we'll exclude collisions in get_file_hashes. Having a # collisions list is not wrong, we must just handle it :). collisions = check_path_collision(package, self.spec.packages) # FIXME: material collisions after expanding globs could be # reported as errors d = {} def add_path(path): # add the files under material path for fpath, fhash in util.get_file_hashes(path, collisions, install_dir): if ctx.get_option('create_static') \ and fpath.endswith(ctx.const.ar_file_suffix) \ and not package.name.endswith(ctx.const.static_name_suffix) \ and util.is_ar_file(fpath): # if this is an ar file, and this package is not a static package, # don't include this file into the package. continue frpath = util.removepathprefix(install_dir, fpath) # relative path ftype, permanent = get_file_type(frpath, package.files, install_dir) fsize = long(util.dir_size(fpath)) d[frpath] = FileInfo(path=frpath, type=ftype, permanent=permanent, size=fsize, hash=fhash) for pinfo in package.files: wildcard_path = util.join_path(install_dir, pinfo.path) for path in glob.glob(wildcard_path): add_path(path) for (p, fileinfo) in d.iteritems(): files.append(fileinfo) files_xml_path = util.join_path(self.pkg_dir(), ctx.const.files_xml) files.write(files_xml_path) self.files = files
def read(self, outdir = None): if not outdir: outdir = ctx.config.tmp_dir() # extract control files self.extract_pisi_files(outdir) self.metadata = MetaData() self.metadata.read( join(outdir, ctx.const.metadata_xml) ) errs = self.metadata.errors() if errs: util.print_errors(errs) raise Error, _("MetaData format wrong") self.files = Files() self.files.read( join(outdir, ctx.const.files_xml) ) if self.files.errors(): raise Error, _("Invalid %s") % ctx.const.files_xml
def build_packages(self): """Build each package defined in PSPEC file. After this process there will be .pisi files hanging around, AS INTENDED ;)""" self.fetch_component() # bug 856 # Strip install directory before building .pisi packages. self.strip_install_dir() if ctx.get_option('create_static'): obj = self.generate_static_package_object() if obj: self.spec.packages.append(obj) if ctx.config.values.build.generatedebug: obj = self.generate_debug_package_object() if obj: self.spec.packages.append(obj) self.new_packages = [] self.old_packages = [] for package in self.spec.packages: old_package_name = None # store additional files c = os.getcwd() os.chdir(self.specdir) install_dir = self.pkg_dir() + ctx.const.install_dir_suffix for afile in package.additionalFiles: src = os.path.join(ctx.const.files_dir, afile.filename) dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target)) util.copy_file(src, dest) if afile.permission: # mode is octal! os.chmod(dest, int(afile.permission, 8)) os.chdir(c) ctx.ui.action(_("** Building package %s") % package.name); ctx.ui.info(_("Generating %s,") % ctx.const.files_xml) self.gen_files_xml(package) ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml) self.gen_metadata_xml(package) # build number if ctx.config.options.ignore_build_no or not ctx.config.values.build.buildno: build_no = old_build_no = None ctx.ui.warning(_('Build number is not available. For repo builds you must enable buildno in pisi.conf.')) else: build_no, old_build_no = self.calc_build_no(package.name) self.metadata.package.build = build_no self.metadata.write(util.join_path(self.pkg_dir(), ctx.const.metadata_xml)) # Calculate new and oldpackage names for buildfarm name = util.package_name(package.name, self.spec.source.version, self.spec.source.release, self.metadata.package.build) outdir = ctx.get_option('output_dir') if outdir: name = pisi.util.join_path(outdir, name) self.new_packages.append(name) ctx.ui.info(_("Creating PISI package %s.") % name) pkg = Package(name, 'w') # add comar files to package os.chdir(self.specdir) for pcomar in package.providesComar: fname = util.join_path(ctx.const.comar_dir, pcomar.script) pkg.add_to_package(fname) # add xmls and files os.chdir(self.pkg_dir()) pkg.add_to_package(ctx.const.metadata_xml) pkg.add_to_package(ctx.const.files_xml) # Now it is time to add files to the packages using newly # created files.xml files = Files() files.read(ctx.const.files_xml) if ctx.get_option('package_format') == "1.0": for finfo in files.list: orgname = arcname = join("install", finfo.path) if package.debug_package: orgname = join("debug", finfo.path) pkg.add_to_package(orgname, arcname) pkg.close() else: # default package format is 1.1, so make it fallback. ctx.build_leftover = join(self.pkg_dir(), ctx.const.install_tar_lzma) tar = archive.ArchiveTar(ctx.const.install_tar_lzma, "tarlzma") for finfo in files.list: orgname = arcname = join("install", finfo.path) if package.debug_package: orgname = join("debug", finfo.path) tar.add_to_archive(orgname, arcname.lstrip("install")) tar.close() pkg.add_to_package(ctx.const.install_tar_lzma) pkg.close() os.unlink(ctx.const.install_tar_lzma) ctx.build_leftover = None os.chdir(c) self.set_state("buildpackages") ctx.ui.info(_("Done.")) #show the files those are not collected from the install dir if ctx.get_option('show_abandoned_files') or ctx.get_option('debug'): abandoned_files = self.get_abandoned_files() if abandoned_files: ctx.ui.warning(_('Abandoned files under the install dir (%s):') % (install_dir)) for f in abandoned_files: ctx.ui.info(' - %s' % (f)) else: ctx.ui.warning(_('All of the files under the install dir (%s) has been collected by package(s)') % (install_dir)) if ctx.config.values.general.autoclean is True: ctx.ui.info(_("Cleaning Build Directory...")) util.clean_dir(self.pkg_dir()) else: ctx.ui.info(_("Keeping Build Directory")) # reset environment variables after build. this one is for # buildfarm actually. buildfarm re-inits pisi for each build # and left environment variables go directly into initial dict # making actionsapi.variables.exportFlags() useless... os.environ = {} os.environ = deepcopy(ctx.config.environ) return self.new_packages, self.old_packages
def build_packages(self): """Build each package defined in PSPEC file. After this process there will be .pisi files hanging around, AS INTENDED ;)""" # Strip install directory before building .pisi packages. self.strip_install_dir() for package in self.spec.packages: # store additional files c = os.getcwd() os.chdir(self.pspecDir) install_dir = self.bctx.pkg_dir() + ctx.const.install_dir_suffix for afile in package.additionalFiles: destdir = util.join_path(install_dir, os.path.dirname(afile.target)) for src in glob.glob(util.join_path(ctx.const.files_dir, afile.filename)): destfile = os.path.basename(afile.target) if not destfile: destfile = os.path.basename(src) ctx.ui.debug(_("Copying additional file: '%s' to '%s' as '%s'") % (src, destdir, destfile)) util.copy_file(src, util.join_path(destdir, destfile)) if afile.permission: # mode is octal! os.chmod(util.join_path(destdir, destfile), int(afile.permission, 8)) os.chdir(c) ctx.ui.action(_("** Building package %s") % package.name) ctx.ui.info(_("Generating %s,") % ctx.const.files_xml) self.gen_files_xml(package) ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml) self.gen_metadata_xml(package) ctx.ui.info(_("Creating PISI package %s.") % package.name) name = util.package_name( package.name, self.spec.source.version, self.spec.source.release, self.metadata.package.build ) pkg = Package(name, "w") # add comar files to package os.chdir(self.pspecDir) for pcomar in package.providesComar: fname = util.join_path(ctx.const.comar_dir, pcomar.script) pkg.add_to_package(fname) # add xmls and files os.chdir(self.bctx.pkg_dir()) pkg.add_to_package(ctx.const.metadata_xml) pkg.add_to_package(ctx.const.files_xml) # Now it is time to add files to the packages using newly # created files.xml files = Files() files.read(ctx.const.files_xml) for finfo in files.list: pkg.add_to_package("install/" + finfo.path) pkg.close() os.chdir(c) self.set_state("buildpackages") util.xterm_title_reset() ctx.ui.info(_("Done.")) if ctx.config.values.general.autoclean is True: ctx.ui.info(_("Cleaning Build Directory...")) util.clean_dir(self.bctx.pkg_dir()) else: ctx.ui.info(_("Keeping Build Directory"))
class Package: """PISI Package Class provides access to a pisi package (.pisi file).""" def __init__(self, packagefn, mode='r'): self.filepath = packagefn url = URI(packagefn) if url.is_remote_file(): from fetcher import fetch_url dest = ctx.config.packages_dir() self.filepath = join(dest, url.filename()) # FIXME: exists is not enough, also sha1sum check needed \ # when implemented in pisi-index.xml if not exists(self.filepath): fetch_url(url, dest, ctx.ui.Progress) else: ctx.ui.info(_('%s [cached]') % url.filename()) self.impl = archive.ArchiveZip(self.filepath, 'zip', mode) def add_to_package(self, fn): """Add a file or directory to package""" self.impl.add_to_archive(fn) def close(self): """Close the package archive""" self.impl.close() def extract(self, outdir): """Extract entire package contents to directory""" self.extract_dir('', outdir) # means package root def extract_files(self, paths, outdir): """Extract paths to outdir""" self.impl.unpack_files(paths, outdir) def extract_file(self, path, outdir): """Extract file with path to outdir""" self.extract_files([path], outdir) def extract_dir(self, dir, outdir): """Extract directory recursively, this function copies the directory archiveroot/dir to outdir""" self.impl.unpack_dir(dir, outdir) def extract_dir_flat(self, dir, outdir): """Extract directory recursively, this function unpacks the *contents* of directory archiveroot/dir inside outdir this is the function used by the installer""" self.impl.unpack_dir_flat(dir, outdir) def extract_PISI_files(self, outdir): """Extract PISI control files: metadata.xml, files.xml, action scripts, etc.""" self.extract_files([ctx.const.metadata_xml, ctx.const.files_xml], outdir) self.extract_dir('config', outdir) def read(self, outdir = None): if not outdir: outdir = ctx.config.tmp_dir() # extract control files self.extract_PISI_files(outdir) self.metadata = MetaData() self.metadata.read( join(outdir, ctx.const.metadata_xml) ) if self.metadata.has_errors(): raise Error, _("MetaData format wrong") self.files = Files() self.files.read( join(outdir, ctx.const.files_xml) ) if self.files.has_errors(): raise Error, _("Invalid %s") % ctx.const.files_xml def pkg_dir(self): packageDir = self.metadata.package.name + '-' \ + self.metadata.package.version + '-' \ + self.metadata.package.release return join( ctx.config.lib_dir(), packageDir) def comar_dir(self): return self.pkg_dir() + ctx.const.comar_dir_suffix
def files(self, pkg): pkg = str(pkg) pkginfo = self.d[pkg] files = Files() files.read(self.files_name(pkg,pkginfo.version,pkginfo.release)) return files
def build_packages(self): """Build each package defined in PSPEC file. After this process there will be .pisi files hanging around, AS INTENDED ;)""" self.fetch_component() # bug 856 # Strip install directory before building .pisi packages. self.strip_install_dir() if ctx.get_option('create_static'): obj = self.generate_static_package_object() if obj: self.spec.packages.append(obj) if not ctx.get_option('no_debug'): obj = self.generate_debug_package_object() if obj: self.spec.packages.append(obj) package_names = [] old_package_names = [] for package in self.spec.packages: old_package_name = None # store additional files c = os.getcwd() os.chdir(self.specdir) install_dir = self.pkg_dir() + ctx.const.install_dir_suffix for afile in package.additionalFiles: src = os.path.join(ctx.const.files_dir, afile.filename) dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target)) util.copy_file(src, dest) if afile.permission: # mode is octal! os.chmod(dest, int(afile.permission, 8)) os.chdir(c) ctx.ui.action(_("** Building package %s") % package.name); ctx.ui.info(_("Generating %s,") % ctx.const.files_xml) self.gen_files_xml(package) ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml) build_number, old_build_number = self.gen_metadata_xml(package) name = util.package_name(package.name, self.spec.source.version, self.spec.source.release, self.metadata.package.build) outdir = ctx.get_option('output_dir') if outdir: name = pisi.util.join_path(outdir, name) ctx.ui.info(_("Creating PISI package %s.") % name) # somebody explain to me why this is done here -- exa if old_build_number: old_package_name = util.package_name(package.name, self.spec.source.version, self.spec.source.release, old_build_number) pkg = Package(name, 'w') package_names.append(name) old_package_names.append(old_package_name) # add comar files to package os.chdir(self.specdir) for pcomar in package.providesComar: fname = util.join_path(ctx.const.comar_dir, pcomar.script) pkg.add_to_package(fname) # add xmls and files os.chdir(self.pkg_dir()) pkg.add_to_package(ctx.const.metadata_xml) pkg.add_to_package(ctx.const.files_xml) # Now it is time to add files to the packages using newly # created files.xml files = Files() files.read(ctx.const.files_xml) if ctx.get_option('package_format') == "1.1": tar = archive.ArchiveTar("install.tar.lzma", "tarlzma") for finfo in files.list: orgname = arcname = join("install", finfo.path) if package.debug_package: orgname = join("debug", finfo.path) tar.add_to_archive(orgname, arcname.lstrip("install")) tar.close() pkg.add_to_package("install.tar.lzma") pkg.close() os.unlink("install.tar") os.unlink("install.tar.lzma") else: for finfo in files.list: orgname = arcname = join("install", finfo.path) if package.debug_package: orgname = join("debug", finfo.path) pkg.add_to_package(orgname, arcname) pkg.close() os.chdir(c) self.set_state("buildpackages") ctx.ui.info(_("Done.")) #show the files those are not collected from the install dir if ctx.get_option('show_abandoned_files') or ctx.get_option('debug'): abandoned_files = self.get_abandoned_files() if abandoned_files: ctx.ui.warning(_('Abandoned files under the install dir (%s):') % (install_dir)) for f in abandoned_files: ctx.ui.info(' - %s' % (f)) else: ctx.ui.warning(_('All of the files under the install dir (%s) has been collected by package(s)') % (install_dir)) if ctx.config.values.general.autoclean is True: ctx.ui.info(_("Cleaning Build Directory...")) util.clean_dir(self.pkg_dir()) else: ctx.ui.info(_("Keeping Build Directory")) return package_names, old_package_names
class Package: """PiSi Package Class provides access to a pisi package (.pisi file).""" def __init__(self, packagefn, mode='r'): self.filepath = packagefn url = URI(packagefn) if url.is_remote_file(): self.fetch_remote_file(url) self.impl = archive.ArchiveZip(self.filepath, 'zip', mode) def fetch_remote_file(self, url): from fetcher import fetch_url dest = ctx.config.packages_dir() self.filepath = join(dest, url.filename()) if not exists(self.filepath): try: fetch_url(url, dest, ctx.ui.Progress) except pisi.fetcher.FetchError: # Bug 3465 if ctx.get_option('reinstall'): raise Error(_("There was a problem while fetching '%s'.\nThe package " "may have been upgraded. Please try to upgrade the package.") % url); raise else: ctx.ui.info(_('%s [cached]') % url.filename()) def add_to_package(self, fn, an=None): """Add a file or directory to package""" self.impl.add_to_archive(fn, an) def close(self): """Close the package archive""" self.impl.close() def extract(self, outdir): """Extract entire package contents to directory""" self.extract_dir('', outdir) # means package root def extract_files(self, paths, outdir): """Extract paths to outdir""" self.impl.unpack_files(paths, outdir) def extract_file(self, path, outdir): """Extract file with path to outdir""" self.extract_files([path], outdir) def extract_dir(self, dir, outdir): """Extract directory recursively, this function copies the directory archiveroot/dir to outdir""" self.impl.unpack_dir(dir, outdir) def extract_install(self, outdir): if self.impl.has_file(ctx.const.install_tar_lzma): self.extract_file(ctx.const.install_tar_lzma, ctx.config.tmp_dir()) tar = archive.ArchiveTar(join(ctx.config.tmp_dir(), ctx.const.install_tar_lzma), 'tarlzma', False, False) tar.unpack_dir(outdir) else: self.extract_dir_flat('install', outdir) def extract_dir_flat(self, dir, outdir): """Extract directory recursively, this function unpacks the *contents* of directory archiveroot/dir inside outdir this is the function used by the installer""" self.impl.unpack_dir_flat(dir, outdir) def extract_pisi_files(self, outdir): """Extract PiSi control files: metadata.xml, files.xml, action scripts, etc.""" self.extract_files([ctx.const.metadata_xml, ctx.const.files_xml], outdir) self.extract_dir('config', outdir) def get_metadata(self): """reads metadata.xml from the PiSi package and returns MetaData object""" md = MetaData() md.parse(self.impl.read_file(ctx.const.metadata_xml)) return md def get_files(self): """reads files.xml from the PiSi package and returns Files object""" files = Files() files.parse(self.impl.read_file(ctx.const.files_xml)) return files def read(self, outdir = None): if not outdir: outdir = ctx.config.tmp_dir() # extract control files self.extract_pisi_files(outdir) self.metadata = MetaData() self.metadata.read( join(outdir, ctx.const.metadata_xml) ) errs = self.metadata.errors() if errs: util.print_errors(errs) raise Error, _("MetaData format wrong") self.files = Files() self.files.read( join(outdir, ctx.const.files_xml) ) if self.files.errors(): raise Error, _("Invalid %s") % ctx.const.files_xml def pkg_dir(self): packageDir = self.metadata.package.name + '-' \ + self.metadata.package.version + '-' \ + self.metadata.package.release return join( ctx.config.lib_dir(), 'package', packageDir) def comar_dir(self): return join(self.pkg_dir(), ctx.const.comar_dir)
def get_files(self): """reads files.xml from the PiSi package and returns Files object""" files = Files() files.parse(self.impl.read_file(ctx.const.files_xml)) return files
def build_packages(self): """Build each package defined in PSPEC file. After this process there will be .pisi files hanging around, AS INTENDED ;)""" self.fetch_component() # bug 856 # Strip install directory before building .pisi packages. self.strip_install_dir() package_names = [] for package in self.spec.packages: # store additional files c = os.getcwd() os.chdir(self.specdir) install_dir = self.pkg_dir() + ctx.const.install_dir_suffix for afile in package.additionalFiles: src = os.path.join(ctx.const.files_dir, afile.filename) dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target)) util.copy_file(src, dest) if afile.permission: # mode is octal! os.chmod(dest, int(afile.permission, 8)) os.chdir(c) ctx.ui.action(_("** Building package %s") % package.name); ctx.ui.info(_("Generating %s,") % ctx.const.files_xml) self.gen_files_xml(package) ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml) self.gen_metadata_xml(package) ctx.ui.info(_("Creating PISI package %s.") % package.name) name = util.package_name(package.name, self.spec.source.version, self.spec.source.release, self.metadata.package.build) pkg = Package(name, 'w') package_names.append(name) # add comar files to package os.chdir(self.specdir) for pcomar in package.providesComar: fname = util.join_path(ctx.const.comar_dir, pcomar.script) pkg.add_to_package(fname) # add xmls and files os.chdir(self.pkg_dir()) pkg.add_to_package(ctx.const.metadata_xml) pkg.add_to_package(ctx.const.files_xml) # Now it is time to add files to the packages using newly # created files.xml files = Files() files.read(ctx.const.files_xml) for finfo in files.list: pkg.add_to_package(join("install", finfo.path)) pkg.close() os.chdir(c) self.set_state("buildpackages") ctx.ui.info(_("Done.")) if ctx.config.values.general.autoclean is True: ctx.ui.info(_("Cleaning Build Directory...")) util.clean_dir(self.pkg_dir()) else: ctx.ui.info(_("Keeping Build Directory")) return package_names
def build_packages(self): """Build each package defined in PSPEC file. After this process there will be .pisi files hanging around, AS INTENDED ;)""" self.fetch_component() # bug 856 # Strip install directory before building .pisi packages. self.strip_install_dir() if ctx.get_option('create_static'): obj = self.generate_static_package_object() if obj: self.spec.packages.append(obj) if ctx.config.values.build.generatedebug: obj = self.generate_debug_package_object() if obj: self.spec.packages.append(obj) new_packages = [] old_package_names = [] for package in self.spec.packages: old_package_name = None # store additional files c = os.getcwd() os.chdir(self.specdir) install_dir = self.pkg_dir() + ctx.const.install_dir_suffix for afile in package.additionalFiles: src = os.path.join(ctx.const.files_dir, afile.filename) dest = os.path.join( install_dir + os.path.dirname(afile.target), os.path.basename(afile.target)) util.copy_file(src, dest) if afile.permission: # mode is octal! os.chmod(dest, int(afile.permission, 8)) os.chdir(c) ctx.ui.action(_("** Building package %s") % package.name) ctx.ui.info(_("Generating %s,") % ctx.const.files_xml) self.gen_files_xml(package) # build number if ctx.config.options.ignore_build_no or not ctx.config.values.build.buildno: build_no = old_build_no = None ctx.ui.warning( _('Build number is not available. For repo builds you must enable buildno in pisi.conf.' )) else: build_no, old_build_no = self.calc_build_no(package.name) ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml) self.gen_metadata_xml(package, build_no) # Calculate new and oldpackage names for buildfarm name = util.package_name(package.name, self.spec.source.version, self.spec.source.release, self.metadata.package.build) if old_build_no: old_package_name = util.package_name(package.name, self.spec.source.version, self.spec.source.release, old_build_no) old_package_names.append(old_package_name) outdir = ctx.get_option('output_dir') if outdir: name = pisi.util.join_path(outdir, name) new_packages.append(name) ctx.ui.info(_("Creating PISI package %s.") % name) pkg = Package(name, 'w') # add comar files to package os.chdir(self.specdir) for pcomar in package.providesComar: fname = util.join_path(ctx.const.comar_dir, pcomar.script) pkg.add_to_package(fname) # add xmls and files os.chdir(self.pkg_dir()) pkg.add_to_package(ctx.const.metadata_xml) pkg.add_to_package(ctx.const.files_xml) # Now it is time to add files to the packages using newly # created files.xml files = Files() files.read(ctx.const.files_xml) if ctx.get_option('package_format') == "1.0": for finfo in files.list: orgname = arcname = join("install", finfo.path) if package.debug_package: orgname = join("debug", finfo.path) pkg.add_to_package(orgname, arcname) pkg.close() else: # default package format is 1.1, so make it fallback. ctx.build_leftover = join(self.pkg_dir(), ctx.const.install_tar_lzma) tar = archive.ArchiveTar(ctx.const.install_tar_lzma, "tarlzma") for finfo in files.list: #print finfo.path orgname = arcname = join("install", finfo.path) if package.debug_package: orgname = join("debug", finfo.path) tar.add_to_archive(orgname, arcname.lstrip("install")) tar.close() pkg.add_to_package(ctx.const.install_tar_lzma) pkg.close() os.unlink(ctx.const.install_tar_lzma) ctx.build_leftover = None os.chdir(c) self.set_state("buildpackages") ctx.ui.info(_("Done.")) #show the files those are not collected from the install dir if ctx.get_option('show_abandoned_files') or ctx.get_option('debug'): abandoned_files = self.get_abandoned_files() if abandoned_files: ctx.ui.warning( _('Abandoned files under the install dir (%s):') % (install_dir)) for f in abandoned_files: ctx.ui.info(' - %s' % (f)) else: ctx.ui.warning( _('All of the files under the install dir (%s) has been collected by package(s)' ) % (install_dir)) if ctx.config.values.general.autoclean is True: ctx.ui.info(_("Cleaning Build Directory...")) util.clean_dir(self.pkg_dir()) else: ctx.ui.info(_("Keeping Build Directory")) # reset environment variables after build. this one is for # buildfarm actually. buildfarm re-inits pisi for each build # and left environment variables go directly into initial dict # making actionsapi.variables.exportFlags() useless... os.environ = {} os.environ = deepcopy(ctx.config.environ) return new_packages, old_package_names