diff options
author | Joshua Ismael Haase Hernández <hahj87@gmail.com> | 2011-04-11 12:39:40 -0500 |
---|---|---|
committer | Joshua Ismael Haase Hernández <hahj87@gmail.com> | 2011-04-11 12:39:40 -0500 |
commit | 3e27d11f68571bce92138f6cbfcaecac75fa1644 (patch) | |
tree | 36647c3691da83e85a0e06ceff3a4b47adf9f49b | |
parent | 857ecbe794c714919612b533303e7a9ef781c75b (diff) |
Fixed some errors
-rwxr-xr-x | clean_repo.py | 6 | ||||
-rwxr-xr-x | config.py | 35 | ||||
-rwxr-xr-x | config.sh | 5 | ||||
-rwxr-xr-x | cptobin.sh | 2 | ||||
-rwxr-xr-x | filter.py | 32 | ||||
-rw-r--r-- | local_config.example | 10 | ||||
-rwxr-xr-x | main.sh | 3 | ||||
-rwxr-xr-x | mkpending.py | 35 | ||||
-rw-r--r-- | pato2.py | 10 |
9 files changed, 82 insertions, 56 deletions
diff --git a/clean_repo.py b/clean_repo.py index b0d306f..d4e06fc 100755 --- a/clean_repo.py +++ b/clean_repo.py @@ -6,7 +6,9 @@ import argparse def remove_from_blacklist(path_to_db, blacklisted_names, debug=config["debug"]): """ Check the blacklist and remove packages on the db""" - + if "~" in path_to_db: + path_to_db=(os.path.expanduser(path_to_db)) + pkgs=[pkg for pkg in pkginfo_from_db(path_to_db) if pkg["name"] in blacklisted_names] if pkgs: @@ -19,6 +21,8 @@ def remove_from_blacklist(path_to_db, blacklisted_names, return pkgs, cmd def cleanup_nonfree_in_dir(directory, blacklisted_names): + if "~" in directory: + directory=(os.path.expanduser(directory)) pkgs=pkginfo_from_files_in_dir(directory) for package in pkgs: if package["name"] in blacklisted_names: @@ -3,11 +3,15 @@ try: from subprocess import check_output except(ImportError): - from commands import getoutput as check_output + from commands import getoutput + def check_output(*popenargs,**kwargs): + cmd=" ".join(*popenargs) + return getoutput(cmd) import os -stringvars=("mirror", "mirrorpath", "logname", "tempdir", "archdb", "docs_dir", - "repodir", "blacklist", "whitelist", "pending", "rsync_blacklist") +stringvars=("mirror", "mirrorpath", "logname", "tempdir", "archdb", + "repodir", "blacklist", "whitelist", "pending", + "rsync_blacklist",) listvars=("repo_list", "dir_list", "arch_list", "other",) boolvars=("output", "debug",) @@ -37,10 +41,29 @@ for var in boolvars: # Rsync commands rsync_list_command="rsync -a --no-motd --list-only " +def printf(text,output=config["output"]): + """Guarda el texto en la variable log y puede imprimir en pantalla.""" + log_file = open(config["logname"], 'a') + log_file.write("\n" + str(text) + "\n") + log_file.close() + if output: + print (str(text) + "\n") + +del exit_if_none + # Classes and Exceptions -class NonValidFile(ValueError): pass -class NonValidDir(ValueError): pass -class NonValidCommand(ValueError): pass +class NonValidFile(ValueError): + def __init__(self): + ValueError.__init__(self) + printf(self.message) +class NonValidDir(ValueError): + def __init__(self): + ValueError.__init__(self) + printf(self.message) +class NonValidCommand(ValueError): + def __init__(self): + ValueError.__init__(self) + printf(self.message) class Package: """ An object that has information about a package. """ @@ -2,10 +2,6 @@ # -*- coding: utf-8 -*- source local_config -# Rsync commands -rsync_update_command="rsync -av --delay-updates --exclude='*.{abs|db}.tar.*' " -rsync_post_command="rsync -av --delete --exclude='*.abs.tar.*' " - function run_python_cmd { env \ mirror=${mirror} \ @@ -13,7 +9,6 @@ function run_python_cmd { logname=${logname} \ tempdir=${tempdir} \ archdb=${archdb} \ - docs_dir=${docs_dir} \ repodir=${repodir} \ blacklist=${blacklist} \ whitelist=${whitelist} \ @@ -1,2 +1,2 @@ #!/bin/bash -cp -f clean_repo.py config.py config.sh get_license.sh main.sh mkpending.py filter.py ~/usr/bin/
\ No newline at end of file +cp -f clean_repo.py config.py config.sh get_license.sh main.sh mkpending.py filter.py local_config ~/usr/bin/
\ No newline at end of file @@ -4,12 +4,17 @@ from glob import glob from repm.config import * from repm.pato2 import * -def listado(filename): +def listado(filename,start=0,end=None): """Obtiene una lista de paquetes de un archivo.""" - archivo = open(filename,"r") - lista = archivo.read().split("\n") - archivo.close() - return [pkg.split(":")[0].rstrip() for pkg in lista if pkg] + 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, @@ -135,29 +140,26 @@ def pkginfo_from_db(path_to_db): package_list=list() if not os.path.isfile(path_to_db): - raise NonValidFile(path_to_db + "is not a file") + raise NonValidFile(path_to_db + " is not a file") - check_output("mkdir -p " + config["archdb"]) + check_output(["mkdir", "-p", config["archdb"]]) try: db_open_tar = tarfile.open(path_to_db, 'r:gz') except tarfile.ReadError: - printf("No valid db_file %s or not readable" % path_to_db) - return(tuple()) - else: - printf("No db_file %s" % path_to_db) + raise NonValidFile("No valid db_file %s or not readable" % path_to_db) return(tuple()) for file in db_open_tar.getmembers(): - db_open_tar.extract(file, archdb) + db_open_tar.extract(file, config["archdb"]) db_open_tar.close() # Get info from file - for dir_ in glob(archdb + "/*"): + for dir_ in glob(config["archdb"] + "/*"): if isdir(dir_) and isfile(dir_ + "/desc"): package_list.append(pkginfo_from_desc( os.path.join(dir_,"desc"))) - check_output("rm -r %s/*" % archdb) - if verbose_: + check_output(["rm", "-r", config["archdb"]]) + if config["debug"]: printf(package_list) return package_list diff --git a/local_config.example b/local_config.example index 7edfde7..8015ee2 100644 --- a/local_config.example +++ b/local_config.example @@ -2,19 +2,19 @@ mirror="mirrors.eu.kernel.org" mirrorpath="::mirrors/archlinux" -# Directories +# Directories: they should end without / ## Optionals paraboladir=~/parabolagnulinux.org logtime=$(date -u +%Y%m%d-%H:%M) ## Must be defined -logname=${paraboladir}/${logtime}-repo-maintainer.log -tempdir=~/tmp/ +tempdir=~/tmp archdb=${tempdir}/db docs_dir=${paraboladir}/docs repodir=${paraboladir}/repo # End Directories # Files +logname=${paraboladir}/log/${logtime}-repo-maintainer.log blacklist=${docs_dir}/blacklist.txt whitelist=${docs_dir}/whitelist.txt pending=${docs_dir}/pending @@ -29,3 +29,7 @@ other="any" # Output options output="True" debug="False" + +# Rsync commands +rsync_update_command="rsync -av --delay-updates --exclude='*.{abs|db}.tar.*' " +rsync_post_command="rsync -av --delete --exclude='*.abs.tar.*' "
\ No newline at end of file @@ -20,7 +20,8 @@ mkrsexclude msg "Syncing repos without delete" # rsync_update_command does not sync db or abs ${rsync_update_command} --exclude-from=${rsync_blacklist} \ - ${mirror}${mirropath}/{$(echo ${repo_list} | tr ':' ',')} ${repodir} + ${mirror}${mirropath}/{$(echo ${repo_list} | tr ':' ','),\ + $(echo ${dir_list} | tr ':' ',')} ${repodir} msg "Syncing each repo and cleaning" msg2 "Remove pending files" diff --git a/mkpending.py b/mkpending.py index 2b255a8..6022206 100755 --- a/mkpending.py +++ b/mkpending.py @@ -1,9 +1,27 @@ #!/usr/bin/python # -*- coding: utf-8 -*- from repm.filter import * +import argparse -def make_pending(path_to_db): +def make_pending(path_to_db, repo, prefix=config["pending"]): """ Determine wich packages are pending for license auditing.""" + filename=prefix + "-" + repo + ".txt" + try: + fsock=open(filename, "rw") + if os.path.isfile(filename): + pkgs=[pkg for pkg in packages_iterable if pkg["name"] not in + listado(filename)] + fsock.write("\n".join([pkg["name"] + ":" + pkg["license"] + for pkg in pkgs]) + "\n") + except(IOError): + print("Can't read %s" % filename) + exit(1) + finally: + fsock.close() + + if "~" in path_to_db: + path_to_db=(os.path.expanduser(path_to_db)) + packages_iterable=pkginfo_from_db(path_to_db) search = tuple(listado(config["blacklist"]) + listado(config["whitelist"])) @@ -15,24 +33,11 @@ def make_pending(path_to_db): def write_pending(packages_iterable, repo, prefix=config["pending"]): """ Write a pending file with the info of the packages """ - filename=prefix + "-" + repo + ".txt" - try: - fsock=open(filename, "a") - except(IOError): - print("Can't read %s" % filename) - finally: - fsock.close() - if os.path.isfile(filename): - pkgs=[pkg for pkg in packages_iterable if pkg["name"] not in - listado(filename)] - fsock.write("\n".join([pkg["name"] + ":" + pkg["license"] - for pkg in pkgs]) + "\n") - fsock.close() if __name__ == "__main__": parser = argparse.ArgumentParser( description="Clean a repo db and packages") - parser.add_argument("-b", "--dababase", type=str, required=True, + parser.add_argument("-b", "--database", type=str, required=True, help="database to check") parser.add_argument("-r", "--repo", type=str, required=True, help="repo of database") @@ -29,14 +29,6 @@ from repm.filter import * import tarfile from os.path import isdir, isfile -def printf(text,output=config["output"]): - """Guarda el texto en la variable log y puede imprimir en pantalla.""" - log_file = open(config["logname"], 'a') - log_file.write("\n" + str(text) + "\n") - log_file.close() - if output_: - print (str(text) + "\n") - def generate_rsync_command(base_command, dir_list=(config["repo_list"] + config["dir_list"]), @@ -68,4 +60,4 @@ def run_rsync(command,debug=config["debug"]): """ Runs rsync and gets returns it's output """ if debug: printf("rsync_command: " + command) - return check_output(command) + return check_output(command.split()) |