From a77defd1d63eef76393c9ee6ccebbf37b53825e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Sun, 14 Aug 2005 17:20:45 +0000 Subject: [PATCH] * a bit of refactoring * and make bug 368 explicit: relative thingie does not work yet --- pisi/build.py | 93 ++++++++++++++++++++++--------------------- pisi/cli/commands.py | 2 +- pisi/context.py | 4 +- pisi/dependency.py | 14 +++---- pisi/fetcher.py | 10 ++--- pisi/graph.py | 2 +- pisi/index.py | 4 +- pisi/install.py | 12 +++--- pisi/metadata.py | 2 +- pisi/operations.py | 2 +- pisi/package.py | 4 +- pisi/pgraph.py | 2 +- pisi/sourcearchive.py | 8 ++-- pisi/sourcefetcher.py | 4 +- pisi/specfile.py | 8 ++-- pisi/toplevel.py | 30 +++++++------- pisi/ui.py | 2 +- pisi/xmlext.py | 3 +- pisi/xmlfile.py | 4 +- 19 files changed, 107 insertions(+), 103 deletions(-) diff --git a/pisi/build.py b/pisi/build.py index c28f992a..7fb450b0 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -34,7 +34,7 @@ class PisiBuildError(pisi.Error): # Helper Functions -def getFileType(path, pinfoList): +def get_file_type(path, pinfoList): """Return the file type of a path according to the given PathInfo list""" # The usage of depth is somewhat confusing. It is used for finding @@ -53,7 +53,7 @@ def getFileType(path, pinfoList): ftype = pinfo.fileType return ftype -def checkPathCollision(package, pkgList): +def check_path_collision(package, pkgList): """This function will check for collision of paths in a package with the paths of packages in pkgList. The return value will be the list containing the paths that collide.""" @@ -81,7 +81,7 @@ class PisiBuild: self.spec = self.ctx.spec self.sourceArchive = SourceArchive(self.ctx) - self.setEnvorinmentVars() + self.set_environment_vars() self.actionLocals = None self.actionGlobals = None @@ -94,11 +94,11 @@ class PisiBuild: ui.error(e + '\n') raise PisiBuildError, "invalid PSPEC file %s" % self.ctx.pspecfile - def setState(self, state): + def set_state(self, state): stateFile = os.path.join(self.srcDir, "pisiBuildState") open(stateFile, "w").write(state) - def getState(self): + def get_state(self): stateFile = os.path.join(self.srcDir, "pisiBuildState") if not os.path.exists(stateFile): # no state return None @@ -110,25 +110,25 @@ class PisiBuild: ui.info("Building PISI source package: %s\n" % self.spec.source.name) util.xtermTitle("Building PISI source package: %s\n" % self.spec.source.name) - self.compileActionScript() + self.compile_action_script() - self.fetchSourceArchive() + self.fetch_source_archive() - self.unpackSourceArchive() + self.unpack_source_archive() - self.solveBuildDependencies() + self.solve_build_dependencies() # apply the patches and prepare a source directory for build. - self.applyPatches() + self.apply_patches() - self.runSetupAction() - self.runBuildAction() - self.runInstallAction() + self.run_setup_action() + self.run_build_action() + self.run_install_action() # after all, we are ready to build/prepare the packages - self.buildPackages() + self.build_packages() - def setEnvorinmentVars(self): + def set_environment_vars(self): """Sets the environment variables for actions API to use""" evn = { "PKG_DIR": self.ctx.pkg_dir(), @@ -140,30 +140,30 @@ class PisiBuild: } os.environ.update(evn) - def fetchSourceArchive(self): + def fetch_source_archive(self): ui.info("Fetching source from: %s\n" % self.spec.source.archiveUri) self.sourceArchive.fetch() ui.info("Source archive is stored: %s/%s\n" %(config.archives_dir(), self.spec.source.archiveName)) - def unpackSourceArchive(self): + def unpack_source_archive(self): ui.info("Unpacking archive...") self.sourceArchive.unpack() ui.info(" unpacked (%s)\n" % self.ctx.pkg_work_dir()) - self.setState("unpacked") + self.set_state("unpacked") - def runSetupAction(self): + def run_setup_action(self): # Run configure, build and install phase ui.action("Setting up source...\n") - self.runActionFunction(const.setup_func) - self.setState("setupaction") + self.run_action_function(const.setup_func) + self.set_state("setupaction") - def runBuildAction(self): + def run_build_action(self): ui.action("Building source...\n") - self.runActionFunction(const.build_func) - self.setState("buildaction") + self.run_action_function(const.build_func) + self.set_state("buildaction") - def runInstallAction(self): + def run_install_action(self): ui.action("Installing...\n") # Before install make sure install_dir is clean @@ -171,10 +171,10 @@ class PisiBuild: util.clean_dir(self.ctx.pkg_install_dir()) # install function is mandatory! - self.runActionFunction(const.install_func, True) - self.setState("installaction") + self.run_action_function(const.install_func, True) + self.set_state("installaction") - def compileActionScript(self): + def compile_action_script(self): """Compiles actions.py and sets the actionLocals and actionGlobals""" specdir = os.path.dirname(self.ctx.pspecfile) scriptfile = os.path.join(specdir, const.actions_file) @@ -191,9 +191,9 @@ class PisiBuild: self.actionLocals = localSymbols self.actionGlobals = globalSymbols - self.srcDir = self.pkgSrcDir() + self.srcDir = self.pkg_src_dir() - def pkgSrcDir(self): + def pkg_src_dir(self): """Returns the real path of WorkDir for an unpacked archive.""" try: workdir = self.actionGlobals['WorkDir'] @@ -202,7 +202,7 @@ class PisiBuild: return os.path.join(self.ctx.pkg_work_dir(), workdir) - def runActionFunction(self, func, mandatory=False): + def run_action_function(self, func, mandatory=False): """Calls the corresponding function in actions.py. If mandatory parameter is True, and function is not present in @@ -221,11 +221,12 @@ class PisiBuild: os.chdir(curDir) - def solveBuildDependencies(self): - """pre-alpha: fail if dependencies not satisfied""" + def solve_build_dependencies(self): + """fail if dependencies not satisfied""" + #TODO: we'll have to do better than plugging a fxn here pass - def applyPatches(self): + def apply_patches(self): files_dir = os.path.abspath(os.path.join(self.pspecDir, const.files_dir)) @@ -239,13 +240,13 @@ class PisiBuild: ui.action("* Applying patch: %s\n" % patch.filename) util.do_patch(self.srcDir, patchFile, level=patch.level, target=patch.target) - def genMetaDataXml(self, package): + def gen_metadata_xml(self, package): """Generate the metadata.xml file for build source. metadata.xml is composed of the information from specfile plus some additional information.""" metadata = MetaData() - metadata.fromSpec(self.spec.source, package) + metadata.from_spec(self.spec.source, package) # FIXME: MEREEEEEN :) metadata.package.build = 0 # BOGUS. WRONG. @@ -263,18 +264,18 @@ class PisiBuild: metadata.package.installedSize = str(size) metadata.write(os.path.join(self.ctx.pkg_dir(), const.metadata_xml)) - def genFilesXml(self, package): + 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.ctx.pkg_install_dir() - collisions = checkPathCollision(package, + collisions = check_path_collision(package, self.spec.packages) 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 = getFileType(frpath, package.paths) + ftype = get_file_type(frpath, package.paths) try: # broken links can cause problem fsize = str(os.path.getsize(fpath)) except OSError: @@ -283,7 +284,7 @@ class PisiBuild: files.write(os.path.join(self.ctx.pkg_dir(), const.files_xml)) - def buildPackages(self): + 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: @@ -294,7 +295,7 @@ class PisiBuild: pkg = Package(name, 'w') c = os.getcwd() - + # add comar files to package os.chdir(self.pspecDir) for pcomar in package.providesComar: @@ -310,24 +311,24 @@ class PisiBuild: util.copy_file(src, dest) 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) - self.genMetaDataXml(package) + self.gen_metadata_xml(package) ui.info(" done.\n") ui.action("Generating %s..." % const.files_xml) - self.genFilesXml(package) + self.gen_files_xml(package) ui.info(" done.\n") ui.action("Creating PISI package %s\n" % name) # add xmls and files os.chdir(self.ctx.pkg_dir()) - + pkg.add_to_package(const.metadata_xml) pkg.add_to_package(const.files_xml) @@ -340,5 +341,5 @@ class PisiBuild: pkg.close() os.chdir(c) - self.setState("buildpackages") + self.set_state("buildpackages") util.xtermTitleReset() diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 5c2f224b..f080b41d 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -471,7 +471,7 @@ Remove all repository information from the system. if len(self.args)>=1: self.init() for repo in self.args: - toplevel.remove_repo(repo) + pisi.toplevel.remove_repo(repo) self.finalize() else: self.help() diff --git a/pisi/context.py b/pisi/context.py index 25d40a35..36388aa1 100644 --- a/pisi/context.py +++ b/pisi/context.py @@ -24,9 +24,9 @@ class BuildContext(object): def __init__(self, pspecfile): super(BuildContext, self).__init__() - self.setSpecFile(pspecfile) + self.set_spec_file(pspecfile) - def setSpecFile(self, pspecfile): + def set_spec_file(self, pspecfile): self.pspecfile = pspecfile spec = SpecFile() spec.read(pspecfile) diff --git a/pisi/dependency.py b/pisi/dependency.py index beaa22a3..57339039 100644 --- a/pisi/dependency.py +++ b/pisi/dependency.py @@ -76,7 +76,7 @@ class DepInfo: s += 'rel <= ' + self.releaseTo return s -def dictSatisfiesDep(dict, depinfo): +def dict_satisfies_dep(dict, depinfo): """determine if a package in a dictionary satisfies given dependency spec""" pkg_name = depinfo.package if not dict.has_key(pkg_name): @@ -86,7 +86,7 @@ def dictSatisfiesDep(dict, depinfo): (version, release) = (pkg.version, pkg.release) return depinfo.satisfies(pkg_name, version, release) -def installedSatisfiesDep(depinfo): +def installed_satisfies_dep(depinfo): """determine if a package in *repository* satisfies given dependency spec""" pkg_name = depinfo.package @@ -97,7 +97,7 @@ dependency spec""" (version, release) = (pkg.version, pkg.release) return depinfo.satisfies(pkg_name, version, release) -def repoSatisfiesDep(depinfo): +def repo_satisfies_dep(depinfo): """determine if a package in *repository* satisfies given dependency spec""" pkg_name = depinfo.package @@ -108,7 +108,7 @@ dependency spec""" (version, release) = (pkg.version, pkg.release) return depinfo.satisfies(pkg_name, version, release) -def satisfiesDeps(pkg, deps, sat = installedSatisfiesDep): +def satisfies_dependencies(pkg, deps, sat = installed_satisfies_dep): for dep in deps: if not sat(dep): ui.error('Package %s does not satisfy dependency %s\n' % @@ -116,9 +116,9 @@ def satisfiesDeps(pkg, deps, sat = installedSatisfiesDep): return False return True -def satisfiesRuntimeDeps(pkg): +def satisfies_runtime_deps(pkg): deps = packagedb.get_package(pkg).runtimeDeps - return satisfiesDeps(pkg, deps) + return satisfies_dependencies(pkg, deps) def installable(pkg): """calculate if pkg is installable currently @@ -126,7 +126,7 @@ def installable(pkg): if not packagedb.has_package(pkg): ui.info("Package " + pkg + " is not present in the package database\n"); return False - elif satisfiesRuntimeDeps(pkg): + elif satisfies_runtime_deps(pkg): return True else: #ui.info("package " + pkg + " does not satisfy dependencies\n"); diff --git a/pisi/fetcher.py b/pisi/fetcher.py index 39ae98f7..0af800e5 100644 --- a/pisi/fetcher.py +++ b/pisi/fetcher.py @@ -32,7 +32,7 @@ class FetchError(pisi.Error): # helper functions -def fetchUrl(url, dest, progress=None): +def fetch_url(url, dest, progress=None): fetch = Fetcher(url, dest) fetch.progress = progress fetch.fetch() @@ -70,7 +70,7 @@ class Fetcher: return os.path.join(self.filedest, self.url.filename()) - def doGrab(self, fileURI, dest, totalsize): + def _do_grab(self, fileURI, dest, totalsize): symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s'] from time import time tt, oldsize = int(time()), 0 @@ -101,7 +101,7 @@ class Fetcher: 'percent' : self.percent, 'rate': self.rate, 'symbol': symbol} - ui.displayProgress(retval) + ui.display_progress(retval) dest.close() @@ -114,7 +114,7 @@ class Fetcher: dest = open(os.path.join(self.filedest, url.filename()) , "w") totalsize = os.path.getsize(url.path()) fileObj = open(url.path()) - self.doGrab(fileObj, dest, totalsize) + self._do_grab(fileObj, dest, totalsize) def fetchRemoteFile (self): from httplib import HTTPException @@ -138,7 +138,7 @@ class Fetcher: else: totalsize = int(headers['Content-Length']) dest = open(os.path.join(self.filedest, self.url.filename()) , "w") - self.doGrab(fileObj, dest, totalsize) + self._do_grab(fileObj, dest, totalsize) def formatRequest(self, request): authinfo = self.url.auth_info() diff --git a/pisi/graph.py b/pisi/graph.py index bb220872..dfba7809 100644 --- a/pisi/graph.py +++ b/pisi/graph.py @@ -23,7 +23,7 @@ import pisi class CycleException(pisi.Exception): pass -class digraph(object): +class Digraph(object): def __init__(self): self.__v = set() diff --git a/pisi/index.py b/pisi/index.py index a0f10238..6ccd1d2b 100644 --- a/pisi/index.py +++ b/pisi/index.py @@ -39,12 +39,12 @@ class Index(XmlFile): self.filepath = filename url = URI(filename) if url.is_remote_file(): - from fetcher import fetchUrl + from fetcher import fetch_url dest = os.path.join(config.index_dir(), repo) if not os.path.exists(dest): os.makedirs(dest) - fetchUrl(url, dest, ui.Progress) + fetch_url(url, dest, ui.Progress) self.filepath = os.path.join(dest, url.filename()) diff --git a/pisi/install.py b/pisi/install.py index 831e97ce..dc4e6ce3 100644 --- a/pisi/install.py +++ b/pisi/install.py @@ -54,9 +54,9 @@ class Installer: self.check_requirements() self.check_relations() self.reinstall() - self.extractInstall() - self.storePisiFiles() - self.registerCOMARScripts() + self.extract_install() + self.store_pisi_files() + self.register_comar_scripts() self.update_databases() def check_requirements(self): @@ -119,13 +119,13 @@ class Installer: # remove old package then operations.remove_single(pkg.name) - def extractInstall(self): + def extract_install(self): "unzip package in place" ui.info('Extracting files,\n') self.package.extract_dir_flat('install', config.destdir) - def storePisiFiles(self): + def store_pisi_files(self): """put files.xml, metadata.xml, actions.py and COMAR scripts somewhere in the file system. We'll need these in future...""" @@ -142,7 +142,7 @@ class Installer: ui.info('Storing %s\n' % fpath) self.package.extract_file(fpath, self.package.pkg_dir()) - def registerCOMARScripts(self): + def register_comar_scripts(self): "register COMAR scripts" for pcomar in self.metadata.package.providesComar: diff --git a/pisi/metadata.py b/pisi/metadata.py index b5302c20..6e8d0d90 100644 --- a/pisi/metadata.py +++ b/pisi/metadata.py @@ -95,7 +95,7 @@ class MetaData(XmlFile): def __init__(self): XmlFile.__init__(self, "PISI") - def fromSpec(self, src, pkg): + def from_spec(self, src, pkg): self.source = SourceInfo() self.source.name = src.name self.source.homepage = src.homepage diff --git a/pisi/operations.py b/pisi/operations.py index a6e1e6c3..a46699f7 100644 --- a/pisi/operations.py +++ b/pisi/operations.py @@ -77,7 +77,7 @@ def install_single_name(name, upgrade = False): pkg = packagedb.get_package(name) if repo.indexuri.is_local_file(): - pkg_path = pkg.packageURI + pkg_path = str(pkg.packageURI) else: # FIXME: determine if we have relative paths in the index # rather than doing this. Requires the index to know about diff --git a/pisi/package.py b/pisi/package.py index 6d5f7ba8..164cdae9 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -37,10 +37,10 @@ class Package: url = URI(packagefn) if url.is_remote_file(): - from fetcher import fetchUrl + from fetcher import fetch_url from ui import ui dest = config.packages_dir() - fetchUrl(url, dest, ui.Progress) + fetch_url(url, dest, ui.Progress) self.filepath = join(dest, url.filename()) self.impl = archive.ArchiveZip(self.filepath, 'zip', mode) diff --git a/pisi/pgraph.py b/pisi/pgraph.py index a436123b..efe8def2 100644 --- a/pisi/pgraph.py +++ b/pisi/pgraph.py @@ -14,7 +14,7 @@ from graph import * # Cache the results from packagedb queries in a graph -class PGraph(digraph): +class PGraph(Digraph): def __init__(self, packagedb): super(PGraph, self).__init__() diff --git a/pisi/sourcearchive.py b/pisi/sourcearchive.py index ccb94a76..37d2d223 100644 --- a/pisi/sourcearchive.py +++ b/pisi/sourcearchive.py @@ -25,7 +25,7 @@ from pisi.archive import Archive from pisi.uri import URI from pisi.ui import ui from pisi.config import config -from pisi.fetcher import fetchUrl +from pisi.fetcher import fetch_url import pisi.util as util class SourceArchiveError(pisi.Error): @@ -42,13 +42,13 @@ class SourceArchive: self.archiveSHA1 = self.ctx.spec.source.archiveSHA1 def fetch(self, interactive=True): - if not self.isCached(interactive): + if not self.is_cached(interactive): if interactive: progress = ui.Progress else: progress = None - fetchUrl(self.url, config.archives_dir(), progress) + fetch_url(self.url, config.archives_dir(), progress) - def isCached(self, interactive=True): + def is_cached(self, interactive=True): if not access(self.archiveFile, R_OK): return False diff --git a/pisi/sourcefetcher.py b/pisi/sourcefetcher.py index 1d92c1b5..f6e7e2da 100644 --- a/pisi/sourcefetcher.py +++ b/pisi/sourcefetcher.py @@ -74,9 +74,9 @@ class SourceFetcher(object): self.fetch(const.files_dir) def fetch(self, appendDest=""): - from fetcher import fetchUrl + from fetcher import fetch_url ui.info("Fetching %s\n" % self.url.uri) dest = join(self.dest, appendDest) - fetchUrl(self.url, dest) + fetch_url(self.url, dest) diff --git a/pisi/specfile.py b/pisi/specfile.py index 8fd296c5..92f20ad9 100644 --- a/pisi/specfile.py +++ b/pisi/specfile.py @@ -371,12 +371,12 @@ class SpecFile(XmlFile): packageElts = self.getAllNodes("Package") self.packages = [PackageInfo(p) for p in packageElts] - self.doMerges() - self.doOverrides() + self.merge_tags() + self.override_tags() self.unlink() - def doOverrides(self): + def override_tags(self): """Override tags from Source in Packages. Some tags in Packages overrides the tags from Source. There is a more detailed description in documents.""" @@ -395,7 +395,7 @@ class SpecFile(XmlFile): if not pkg.license: pkg.license = self.source.license - def doMerges(self): + def merge_tags(self): """Merge tags from Source in Packages. Some tags in Packages merged with the tags from Source. There is a more detailed description in documents.""" diff --git a/pisi/toplevel.py b/pisi/toplevel.py index 2806d3d8..d1f82319 100644 --- a/pisi/toplevel.py +++ b/pisi/toplevel.py @@ -82,8 +82,8 @@ def install_pkg_files(package_URIs): dfn[name] = x def satisfiesDep(dep): - return dependency.installedSatisfiesDep(dep) \ - or dependency.dictSatisfiesDep(d_t, dep) + return dependency.installed_satisfies_dep(dep) \ + or dependency.dict_satisfies_dep(d_t, dep) # for this case, we have to determine the dependencies # that aren't already satisfied and try to install them @@ -140,7 +140,7 @@ def install_pkg_files(package_URIs): print pkg for dep in pkg.runtimeDeps: print 'checking ', dep - if dependency.dictSatisfiesDep(d_t, dep): + if dependency.dict_satisfies_dep(d_t, dep): if not dep.package in G_f.vertices(): Bp.add(str(dep.package)) G_f.add_dep(x, dep) @@ -188,7 +188,7 @@ def install_pkg_names(A): for dep in pkg.runtimeDeps: print 'checking ', dep # we don't deal with already *satisfied* dependencies - if not dependency.installedSatisfiesDep(dep): + if not dependency.installed_satisfies_dep(dep): if not dep.package in G_f.vertices(): Bp.add(str(dep.package)) G_f.add_dep(x, dep) @@ -256,7 +256,7 @@ def upgrade_pkg_names(A): for dep in pkg.runtimeDeps: print 'checking ', dep # add packages that can be upgraded - if dependency.repoSatisfiesDep(dep): + if dependency.repo_satisfies_dep(dep): if installdb.is_installed(dep.package): #FIXME: use build no (v,r) = installdb.get_version(dep.package) @@ -314,7 +314,7 @@ def remove(A): for (rev_dep, depinfo) in rev_deps: print 'checking ', rev_dep # we don't deal with unsatisfied dependencies - if dependency.installedSatisfiesDep(depinfo): + if dependency.installed_satisfies_dep(depinfo): if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) @@ -406,39 +406,39 @@ order = {"none": 0, def __buildState_unpack(pb): # unpack is the first state to run. - pb.fetchSourceArchive() - pb.unpackSourceArchive() - pb.applyPatches() + pb.fetch_source_archive() + pb.unpack_source_archive() + pb.apply_patches() def __buildState_setupaction(pb, last): if order[last] < order["unpack"]: __buildState_unpack(pb) - pb.runSetupAction() + pb.run_setup_action() def __buildState_buildaction(pb, last): if order[last] < order["setupaction"]: __buildState_setupaction(pb, last) - pb.runBuildAction() + pb.run_build_action() def __buildState_installaction(pb, last): if order[last] < order["buildaction"]: __buildState_buildaction(pb, last) - pb.runInstallAction() + pb.run_install_action() def __buildState_buildpackages(pb, last): if order[last] < order["installaction"]: __buildState_installaction(pb, last) - pb.buildPackages() + pb.build_packages() def build_until(pspecfile, state, authInfo=None): pb = prepare_for_build(pspecfile, authInfo) - pb.compileActionScript() + pb.compile_action_script() - last = pb.getState() + last = pb.get_state() ui.info("Last state was %s\n"%last) if not last: last = "none" diff --git a/pisi/ui.py b/pisi/ui.py index 13c4a318..6ffe1729 100644 --- a/pisi/ui.py +++ b/pisi/ui.py @@ -81,7 +81,7 @@ class CLI: else: return 0 - def displayProgress(self, pd): + def display_progress(self, pd): out = '\r%-30.30s %3d%% %12.2f %s' % \ (pd['filename'], pd['percent'], pd['rate'], pd['symbol']) self.info(out) diff --git a/pisi/xmlext.py b/pisi/xmlext.py index 8a8ea3ba..647b769b 100644 --- a/pisi/xmlext.py +++ b/pisi/xmlext.py @@ -9,9 +9,10 @@ # # Please read the COPYING file. # - # some helper functions for using minidom # works well enough for now... :/ +# function names are mixedCase for compatibility with minidom, +# an old library # Authors: Eray Ozkural # Baris Metin # Baris Metin