diff options
author | 2011-08-02 00:39:30 +0000 | |
---|---|---|
committer | 2011-08-02 00:39:30 +0000 | |
commit | eee0d5751702515c4f9ce665644000c8d5aeaa25 (patch) | |
tree | 7cb9cedfeeb4962fbe0684d0196c2cfe3277c46d | |
parent | documentation changes (diff) | |
download | autodep-eee0d5751702515c4f9ce665644000c8d5aeaa25.tar.gz autodep-eee0d5751702515c4f9ce665644000c8d5aeaa25.tar.bz2 autodep-eee0d5751702515c4f9ce665644000c8d5aeaa25.zip |
auto access blocking
-rw-r--r-- | docs/source/intro.rst | 3 | ||||
-rw-r--r--[-rwxr-xr-x] | src/autodep/autodep (renamed from src/autodep/showfsevents.py) | 0 | ||||
-rw-r--r-- | src/autodep/helpers/events_analysis.py | 30 | ||||
-rw-r--r-- | src/autodep/package_utils/portage_misc_functions.py | 94 | ||||
-rw-r--r-- | src/autodep/package_utils/portage_utils.py | 21 |
5 files changed, 139 insertions, 9 deletions
diff --git a/docs/source/intro.rst b/docs/source/intro.rst index 5ee0dd5..3914bbc 100644 --- a/docs/source/intro.rst +++ b/docs/source/intro.rst @@ -5,7 +5,8 @@ Introduction Overview =================================== Auto dependency builder is a tool for analysis files accessed during -building a package. It also can be used for runtime dependencies analysis. +building a package. It also can be used for buildtime and runtime dependency +analysis. The tool can block an access to files of defined packages. diff --git a/src/autodep/showfsevents.py b/src/autodep/autodep index 518eed8..518eed8 100755..100644 --- a/src/autodep/showfsevents.py +++ b/src/autodep/autodep diff --git a/src/autodep/helpers/events_analysis.py b/src/autodep/helpers/events_analysis.py index 2928aad..ed5792b 100644 --- a/src/autodep/helpers/events_analysis.py +++ b/src/autodep/helpers/events_analysis.py @@ -1,15 +1,41 @@ #!/usr/bin/env python +excluded_paths=set( +['/etc/sandbox.d/'] +) + +excluded_packages=set( +# autodep shows these two packages every time +['net-zope/zope-fixers', 'net-zope/zope-interface'] +) + +def is_file_excluded(f): + for path in excluded_paths: + if f.startswith(path): # if path is excluded + return True + return False + +def is_pkg_excluded(p): + for pkg in excluded_packages: + if p.startswith(pkg): # if package is excluded + return True + return False ## some heuristics here to cut few packets def is_package_useful(pkg,stages,files): - # test 1: package is not useful if all files are *.desktop or *.xml or *.m4 + if is_pkg_excluded(pkg): + return False + for f in files: + if is_file_excluded(f): + continue + + # test 1: package is not useful if all files are *.desktop or *.xml or *.m4 if not (f.endswith(".desktop") or f.endswith(".xml") or f.endswith(".m4")): break else: - return False + return False # we get here if cycle ends not with break return True diff --git a/src/autodep/package_utils/portage_misc_functions.py b/src/autodep/package_utils/portage_misc_functions.py index c090d89..ca6d890 100644 --- a/src/autodep/package_utils/portage_misc_functions.py +++ b/src/autodep/package_utils/portage_misc_functions.py @@ -8,6 +8,13 @@ from portage.dbapi._expand_new_virt import expand_new_virt # parse_opts function will always be there from _emerge.main import parse_opts +# TODO: check if actions always here +try: + from _emerge import actions + from _emerge.create_depgraph_params import create_depgraph_params + from _emerge.depgraph import backtrack_depgraph, depgraph +except ImportError, Err: # non-critical, just print warning(TODO: strerr) + print "Error while loading modules: %s" % Err.message class portage_api: """ class for accessing the portage api """ @@ -20,10 +27,87 @@ class portage_api: self.metadata_keys = [k for k in portage.auxdbkeys if not k.startswith("UNUSED_")] self.use=self.settings["USE"] + def get_best_visible_pkg(self,pkg): + """ + Gets best candidate on installing. Returns empty string if no found + + """ + try: + return self.portdb.xmatch("bestmatch-visible", pkg) + except: + return '' + + def get_merge_list(self,emergeargs): + """ + Gets list of packages that emerge with emergeargs-arguments will merge + This function uses very internal functions of portage so + it may be unreliable in various portage versions + + """ + + try: + settings,trees,mtimedb=actions.load_emerge_config() + action, opts, files = parse_opts(emergeargs, silent=True) + params=create_depgraph_params(opts,action) + + success, mydepgraph, favorites = backtrack_depgraph( + settings, trees, opts, params, action, files, None) + if not success: + return [] + + ret=[] + for pkg in mydepgraph.altlist(): + ret.append(pkg.cpv) + return ret + + except: + return [] + + # non-recursive dependency getter + def get_dep(self,pkg,dep_type=["RDEPEND","DEPEND"]): + """ + Gets current dependencies of a package. Looks in portage db + + :param pkg: name of package + :param dep_type: type of dependencies to recurse. Can be ["DEPEND"] or + ["RDEPEND", "DEPEND"] + :returns: **set** of packages names + """ + + ret=set() + + pkg = self.get_best_visible_pkg(pkg) + if not pkg: + return ret + + # we found the best visible match in common tree + + metadata = dict(zip(self.metadata_keys, + self.portdb.aux_get(pkg, self.metadata_keys))) + dep_str = " ".join(metadata[k] for k in dep_type) + + success, atoms = portage.dep_check(dep_str, None, self.settings, + myuse=self.use.split(), trees=portage.db, myroot=self.settings["ROOT"]) + if not success: + return ret + + for atom in atoms: + atomname = self.vartree.dep_bestmatch(atom) + + if not atomname: + continue + + for unvirt_pkg in expand_new_virt(self.vartree.dbapi,'='+atomname): + for pkg in self.vartree.dep_match(unvirt_pkg): + ret.add(pkg) + + return ret + # recursive dependency getter def get_deps(self,pkg,dep_type=["RDEPEND","DEPEND"]): """ Gets current dependencies of a package on any depth + All dependencies **must** be installed :param pkg: name of package :param dep_type: type of dependencies to recurse. Can be ["DEPEND"] or @@ -36,14 +120,15 @@ class portage_api: ret=set() + # get porttree dependencies on the first package + pkg = self.portdb.xmatch("bestmatch-visible", pkg) if not pkg: return ret - #print pkg - known_packages=set() - unknown_packages={pkg} + unknown_packages=self.get_dep(pkg,dep_type) + ret=ret.union(unknown_packages) while unknown_packages: p=unknown_packages.pop() @@ -52,16 +137,13 @@ class portage_api: continue known_packages.add(p) - #print self.metadata_keys, p,self.portdb.aux_get(p, self.metadata_keys) metadata = dict(zip(self.metadata_keys, self.vardb.aux_get(p, self.metadata_keys))) - #print "proceeding2 "+p dep_str = " ".join(metadata[k] for k in dep_type) success, atoms = portage.dep_check(dep_str, None, self.settings, myuse=self.use.split(), trees=portage.db, myroot=self.settings["ROOT"]) - #print atoms if not success: continue diff --git a/src/autodep/package_utils/portage_utils.py b/src/autodep/package_utils/portage_utils.py index 5401d99..d33ada6 100644 --- a/src/autodep/package_utils/portage_utils.py +++ b/src/autodep/package_utils/portage_utils.py @@ -69,5 +69,26 @@ def getfilesbypackage(packagename): return ret +def get_all_packages_files(): + """ + Memory-hungry operation + + :returns: **set** of all files that belongs to package + """ + ret=[] + try: + proc=subprocess.Popen(['qlist']+['--all',"--obj"], + stdout=subprocess.PIPE,stderr=subprocess.PIPE, + bufsize=4096) + + out,err=proc.communicate() + if err!=None and len(err)!=0 : + print "Noncritical error while launch qlist: %s" % err; + + ret=out.split("\n") + except OSError,e: + print "Error while launching qfile: %s" % e + + return set(ret)
\ No newline at end of file |