summaryrefslogtreecommitdiff
path: root/filter.py
diff options
context:
space:
mode:
Diffstat (limited to 'filter.py')
-rwxr-xr-x[-rw-r--r--]filter.py86
1 files changed, 58 insertions, 28 deletions
diff --git a/filter.py b/filter.py
index 668822b..1d70a63 100644..100755
--- a/filter.py
+++ b/filter.py
@@ -4,6 +4,18 @@ from glob import glob
from repm.config import *
from repm.pato2 import *
+def listado(filename,start=0,end=None):
+ """Obtiene una lista de paquetes de un archivo."""
+ fsock = open(filename,"r")
+ lista = fsock.read().split("\n")
+ fsock.close()
+ if end is not None:
+ return [pkg.split(":")[start:end].rstrip()
+ for pkg in lista if pkg]
+ else:
+ return [pkg.split(":")[start].rstrip()
+ for pkg in lista if pkg]
+
def pkginfo_from_filename(filename):
""" Generates a Package object with info from a filename,
filename can be relative or absolute
@@ -26,7 +38,7 @@ def pkginfo_from_filename(filename):
pkg["name"] = "-".join(fileattrs)
return pkg
-def pkginfo_from_desc(filename):
+def pkginfo_from_desc(info_from_desc, pkg=Package()):
""" Returns pkginfo from desc file.
Parameters:
@@ -36,14 +48,7 @@ def pkginfo_from_desc(filename):
Returns:
----------
pkg -> Package object"""
- if not os.path.isfile(filename):
- raise NonValidFile
- try:
- f=open(filename)
- info=f.read().rsplit()
- finally:
- f.close()
- pkg = Package()
+ info=info_from_desc.rsplit()
info_map={"name" :("%NAME%" , None),
"version" :("%VERSION%" , 0 ),
"release" :("%VERSION%" , 1 ),
@@ -116,10 +121,38 @@ def pkginfo_from_files_in_dir(directory):
return tuple(package_list)
def pkginfo_from_db(path_to_db):
- """ """
+ """ Get pkginfo from db.
+
+ Parameters:
+ ----------
+ path_to_db -> str Path to file
-def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names,
- exclude_file=rsync_blacklist, debug=verbose):
+ Output:
+ ----------
+ package_list -> tuple of Package objects"""
+ package_list=list()
+
+ if not os.path.isfile(path_to_db):
+ raise NonValidFile(path_to_db + " is not a file")
+
+ try:
+ dbsock = tarfile.open(path_to_db, 'r:gz')
+ desc_files=[desc for desc in db_open_tar.getnames()
+ if "/desc" in desc]
+ for name in desc_files:
+ desc=dbsock.extractfile(name)
+ package_list.append(pkginfo_from_desc(desc.read()))
+ except tarfile.ReadError:
+ raise NonValidFile("No valid db_file %s or not readable"
+ % path_to_db)
+ return(tuple())
+ finally:
+ db_open_tar.close()
+ return package_list
+
+def rsyncBlacklist_from_blacklist(packages_iterable,
+ blacklisted_names,
+ exclude_file=config["rsync_blacklist"]):
""" Generate an exclude list for rsync
Parameters:
@@ -132,26 +165,23 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names,
Output:
----------
None """
- a=list()
-
- for package in packages_iterable:
- if not isinstance(package, Package):
- raise ValueError(" %s is not a Package object " % package)
- if package["name"] in blacklisted_names:
- a.append(package["location"])
+ pkgs=[pkg["location"] for pkg in packages_iterable
+ if isinstance(pkg, Package)
+ and pkg["name"] in blacklisted_names]
- if debug:
- return a
try:
fsock = open(exclude_file,"w")
- try:
- fsock.write("\n".join(a))
- finally:
- fsock.close()
+ fsock.write("\n".join(pkgs) + "\n")
except IOError:
- printf("%s wasnt written" % blacklist_file)
+ printf("%s wasnt written" % exclude_file)
+ exit(1)
+ finally:
+ fsock.close()
+ return pkgs
+
if __name__ == "__main__":
- a=run_rsync(rsync_list_command)
+ cmd=generate_rsync_command(rsync_list_command)
+ a=run_rsync(cmd)
packages=pkginfo_from_rsync_output(a)
- generate_exclude_list_from_blacklist(packages,listado(blacklist))
+ rsyncBlaclist_from_blacklist(packages,listado(blacklist))