From 2321a53d35a9736b8c5c715ca40a9af69b1bf64e Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 01:14:47 -0600 Subject: Rearranged functions --- config.py | 5 +++++ filter.py | 43 ------------------------------------------- pato2.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/config.py b/config.py index bd8ef1b..4854e0d 100644 --- a/config.py +++ b/config.py @@ -40,6 +40,11 @@ whitelist = docs + "/whitelist.txt" pending = docs + "/pending" rsync_blacklist = docs + "/rsyncBlacklist" +# Rsync commands + +rsync_list_command="rsync -a --no-motd --list-only " + + # Classes and Exceptions class NonValidFile(ValueError): pass class NonValidDir(ValueError): pass diff --git a/filter.py b/filter.py index ffc0965..b51dba8 100644 --- a/filter.py +++ b/filter.py @@ -6,49 +6,6 @@ import re from repm.config import * from repm.pato2 import * -rsync_list_command="rsync -a --no-motd --list-only " - -def generate_rsync_command(base_command, dir_list, destdir=repodir, mirror_name=mirror, - mirror_path=mirrorpath, blacklist_file=False): - """ Generates an rsync command for executing it by combining all parameters. - - Parameters: - ---------- - base_command -> str - mirror_name -> str - mirror_path -> str - dir_list -> list or tuple - destdir -> str Path to dir, dir must exist. - blacklist_file -> False or str Path to file, file must exist. - - Return: - ---------- - rsync_command -> str """ - from os.path import isfile, isdir - - if blacklist_file and not isfile(blacklist_file): - print(blacklist_file + " is not a file") - raise NonValidFile - - if not os.path.isdir(destdir): - print(destdir + " is not a directory") - raise NonValidDir - - dir_list="{" + ",".join(dir_list) + "}" - - if blacklist_file: - return " ".join((base_command, "--exclude-from-file="+blacklist_file, - mirror_name + mirror_path + dir_list, destdir)) - return " ".join((base_command, mirror_name + mirror_path + dir_list, destdir)) - -def run_rsync(base_for_rsync=rsync_list_command, dir_list_for_rsync=(repo_list + dir_list), - debug=verbose): - """ Runs rsync and gets returns it's output """ - cmd = str(generate_rsync_command(rsync_list_command, (repo_list + dir_list))) - if debug: - printf("rsync_command" + cmd) - return commands.getoutput(cmd) - def get_file_list_from_rsync_output(rsync_output): """ Generates a list of packages and versions from an rsync output using --list-only --no-motd. diff --git a/pato2.py b/pato2.py index cfdd859..125ae8c 100644 --- a/pato2.py +++ b/pato2.py @@ -166,6 +166,46 @@ def get_licenses(verbose_=verbose): a=commands.getoutput(cmd_) if verbose_: printf(a) +def generate_rsync_command(base_command, dir_list, destdir=repodir, + source=mirror+mirrorpath, blacklist_file=False): + """ Generates an rsync command for executing it by combining all parameters. + + Parameters: + ---------- + base_command -> str + dir_list -> list or tuple + destdir -> str Path to dir, dir must exist. + source -> str The source for rsync + blacklist_file -> False or str Path to file, file must exist. + + Return: + ---------- + rsync_command -> str """ + from os.path import isfile, isdir + + if blacklist_file and not isfile(blacklist_file): + print(blacklist_file + " is not a file") + raise NonValidFile + + if not os.path.isdir(destdir): + print(destdir + " is not a directory") + raise NonValidDir + + dir_list="{" + ",".join(dir_list) + "}" + + if blacklist_file: + return " ".join((base_command, "--exclude-from-file="+blacklist_file, + mirror_name + mirror_path + dir_list, destdir)) + return " ".join((base_command, mirror_name + mirror_path + dir_list, destdir)) + +def run_rsync(base_for_rsync=rsync_list_command, dir_list_for_rsync=(repo_list + dir_list), + debug=verbose): + """ Runs rsync and gets returns it's output """ + cmd = str(generate_rsync_command(rsync_list_command, (repo_list + dir_list))) + if debug: + printf("rsync_command" + cmd) + return commands.getoutput(cmd) + if __name__ == "__main__": from time import time start_time = time() -- cgit v1.2.3-54-g00ecf From 6203dc2fc926781db694ca2383b1e44e2c5469c7 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 01:29:33 -0600 Subject: - filter.py: * Makes a blacklist for rsync - pato2.py: * Has more functions --- filter.py | 6 +++++- pato2.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/filter.py b/filter.py index b51dba8..14ae31e 100644 --- a/filter.py +++ b/filter.py @@ -1,4 +1,4 @@ -#! /usr/bin/python + #! /usr/bin/python #-*- encoding: utf-8 -*- import commands import os @@ -79,3 +79,7 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, except IOError: printf("%s wasnt written" % blacklist_file) +if name == "__main__": + a=run_rsync(rsync_list_command) + packages=get_file_list_from_rsync_output(a) + generate_exclude_list_from_blacklist(packages,listado(blacklist)) diff --git a/pato2.py b/pato2.py index 125ae8c..97eec9d 100644 --- a/pato2.py +++ b/pato2.py @@ -198,7 +198,7 @@ def generate_rsync_command(base_command, dir_list, destdir=repodir, mirror_name + mirror_path + dir_list, destdir)) return " ".join((base_command, mirror_name + mirror_path + dir_list, destdir)) -def run_rsync(base_for_rsync=rsync_list_command, dir_list_for_rsync=(repo_list + dir_list), +def run_rsync(base_for_rsync, dir_list_for_rsync=(repo_list + dir_list), debug=verbose): """ Runs rsync and gets returns it's output """ cmd = str(generate_rsync_command(rsync_list_command, (repo_list + dir_list))) -- cgit v1.2.3-54-g00ecf From b27cbc08447fe5605bf877ee0991888d5ecf6382 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 01:32:48 -0600 Subject: Corrected filter.py to run --- filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filter.py b/filter.py index 14ae31e..c789cd5 100644 --- a/filter.py +++ b/filter.py @@ -79,7 +79,7 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, except IOError: printf("%s wasnt written" % blacklist_file) -if name == "__main__": +if __name__ == "__main__": a=run_rsync(rsync_list_command) packages=get_file_list_from_rsync_output(a) generate_exclude_list_from_blacklist(packages,listado(blacklist)) -- cgit v1.2.3-54-g00ecf From 931daf34033714e64fb4f98a101dd804e4e6363e Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 01:34:35 -0600 Subject: Added os module to config file --- config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/config.py b/config.py index 4854e0d..bd46688 100644 --- a/config.py +++ b/config.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from user import home import commands +import os time__ = commands.getoutput("date +%Y%m%d-%H:%M") -- cgit v1.2.3-54-g00ecf From 7f40b89e8cd0e9b2cfd92a8b74c4063d8b9aa3e3 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 01:38:59 -0600 Subject: Corrected funcions --- pato2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pato2.py b/pato2.py index 97eec9d..55e63e7 100644 --- a/pato2.py +++ b/pato2.py @@ -195,13 +195,13 @@ def generate_rsync_command(base_command, dir_list, destdir=repodir, if blacklist_file: return " ".join((base_command, "--exclude-from-file="+blacklist_file, - mirror_name + mirror_path + dir_list, destdir)) - return " ".join((base_command, mirror_name + mirror_path + dir_list, destdir)) + source + dir_list, destdir)) + return " ".join((base_command, source + dir_list, destdir)) def run_rsync(base_for_rsync, dir_list_for_rsync=(repo_list + dir_list), debug=verbose): """ Runs rsync and gets returns it's output """ - cmd = str(generate_rsync_command(rsync_list_command, (repo_list + dir_list))) + cmd = str(generate_rsync_command(base_for_rsync, (repo_list + dir_list))) if debug: printf("rsync_command" + cmd) return commands.getoutput(cmd) -- cgit v1.2.3-54-g00ecf From cbe877f2ba25b398ad32b92d22dc6f5a108ef59f Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 02:28:01 -0600 Subject: * Changed get_file_list_ for pkginfo in function names * Added pkginfo_from_... funcions --- filter.py | 57 ++++++++++++++++++++++++++++++++++++++------------------- test/test1.py | 8 ++++---- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/filter.py b/filter.py index c789cd5..232319f 100644 --- a/filter.py +++ b/filter.py @@ -1,13 +1,34 @@ #! /usr/bin/python #-*- encoding: utf-8 -*- import commands -import os import re from repm.config import * from repm.pato2 import * -def get_file_list_from_rsync_output(rsync_output): - """ Generates a list of packages and versions from an rsync output using --list-only --no-motd. +def pkginfo_from_filename(filename): + """ Generates a Package object with info from a filename, + filename can be relative or absolute + + Parameters: + ---------- + filename -> str + + Returns: + ---------- + pkg -> Package object""" + pkg = Package() + pkg["location"] = filename + fileattrs = os.path.basename(filename).split("-") + pkg["arch"] = fileattrs.pop(-1).split(".")[0] + pkg["release"] = fileattrs.pop(-1) + pkg["version"] = fileattrs.pop(-1) + pkg["name"] = "-".join(fileattrs) + return pkg + + +def pkginfo_from_rsync_output(rsync_output): + """ Generates a list of packages and versions from an rsync output + wich uses --list-only and --no-motd options. Parameters: ---------- @@ -18,33 +39,30 @@ def get_file_list_from_rsync_output(rsync_output): package_list -> tuple Contains Package objects. """ a=list() - def directory(line): - pass - def package_or_link(line): """ Take info out of filename """ location_field = 4 - pkg = Package() - pkg["location"] = line.rsplit()[location_field] - fileattrs = pkg["location"].split("/")[-1].split("-") - pkg["arch"] = fileattrs.pop(-1).split(".")[0] - pkg["release"] = fileattrs.pop(-1) - pkg["version"] = fileattrs.pop(-1) - pkg["name"] = "-".join(fileattrs) - return pkg - + pkginfo_from_filename(line.rsplit()[location_field]) + + def directory(line): + pass + options = { "d": directory, "l": package_or_link, "-": package_or_link} for line in rsync_output.split("\n"): if ".pkg.tar" in line: - pkginfo=options[line[0]](line) - if pkginfo: - a.append(pkginfo) + pkginfo_=options[line[0]](line) + if pkginfo_: + a.append(pkginfo_) return tuple(a) +def pkginfo_from_files_in_dir(directory): + """ Returns pkginfo from filenames of packages in dir + wich has .pkg.tar.{xz,gz} on them """ + def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, exclude_file=rsync_blacklist, debug=verbose): """ Generate an exclude list for rsync @@ -78,8 +96,9 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, fsock.close() except IOError: printf("%s wasnt written" % blacklist_file) + if __name__ == "__main__": a=run_rsync(rsync_list_command) - packages=get_file_list_from_rsync_output(a) + packages=pkginfo_from_rsync_output(a) generate_exclude_list_from_blacklist(packages,listado(blacklist)) diff --git a/test/test1.py b/test/test1.py index 13b5660..9e94352 100644 --- a/test/test1.py +++ b/test/test1.py @@ -29,12 +29,12 @@ class KnownValues(unittest.TestCase): def generate_results(self, example_tuple, attr): rsync_out, name, version, arch, release, location = example_tuple - return get_file_list_from_rsync_output(rsync_out)[0][attr], locals()[attr] + return pkginfo_from_rsync_output(rsync_out)[0][attr], locals()[attr] def testDirectoryOutput(self): - """get_file_list_from_rsync_output should ignore directories""" + """pkginfo_from_rsync_output should ignore directories""" rsync_out="\n".join(self.directory_list) - result=get_file_list_from_rsync_output(rsync_out) + result=pkginfo_from_rsync_output(rsync_out) self.assertEqual(tuple(), result) def testNames(self): @@ -62,5 +62,5 @@ class KnownValues(unittest.TestCase): k,v = self.generate_results(example_tuple=i,attr="location") self.assertEqual(k, v) -if __name__ == "__main__": +if __name__ == "__mpain__": unittest.main() -- cgit v1.2.3-54-g00ecf From 4e7508d9a61c3653b46da8fa513513756bb3b6f1 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 16:46:33 -0600 Subject: * pkginfo functions --- filter.py | 44 +++++++++++++++++++++++++++++++------------- test/test1.py | 2 +- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/filter.py b/filter.py index 232319f..ad3b33d 100644 --- a/filter.py +++ b/filter.py @@ -1,7 +1,6 @@ #! /usr/bin/python #-*- encoding: utf-8 -*- -import commands -import re +import glob from repm.config import * from repm.pato2 import * @@ -11,11 +10,13 @@ def pkginfo_from_filename(filename): Parameters: ---------- - filename -> str + filename -> str Must contain .pkg.tar. Returns: ---------- pkg -> Package object""" + if ".pkg.tar." not in filename: + raise NonValidFile pkg = Package() pkg["location"] = filename fileattrs = os.path.basename(filename).split("-") @@ -37,31 +38,49 @@ def pkginfo_from_rsync_output(rsync_output): Returns: ---------- package_list -> tuple Contains Package objects. """ - a=list() + package_list=list() def package_or_link(line): """ Take info out of filename """ location_field = 4 pkginfo_from_filename(line.rsplit()[location_field]) - def directory(line): + def do_nothing(): pass - - options = { "d": directory, + + options = { "d": do_nothing, "l": package_or_link, - "-": package_or_link} + "-": package_or_link, + " ": do_nothing} for line in rsync_output.split("\n"): if ".pkg.tar" in line: - pkginfo_=options[line[0]](line) + pkginfo=options[line[0]](line) if pkginfo_: - a.append(pkginfo_) + package_list.append(pkginfo) - return tuple(a) + return tuple(package_list) def pkginfo_from_files_in_dir(directory): """ Returns pkginfo from filenames of packages in dir - wich has .pkg.tar.{xz,gz} on them """ + wich has .pkg.tar. on them + + Parameters: + ---------- + directory -> str Directory must exist + + Returns: + ---------- + package_list -> tuple Contains Package objects """ + package_list=list() + + if not os.path.isdir(directory): + raise NonValidDir + + for filename in glob(os.path.join(directory,"*")): + if ".pkg.tar." in filename: + package_list.append(pkginfo_from_filename(filename)) + return tuple(package_list) def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, exclude_file=rsync_blacklist, debug=verbose): @@ -97,7 +116,6 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, except IOError: printf("%s wasnt written" % blacklist_file) - if __name__ == "__main__": a=run_rsync(rsync_list_command) packages=pkginfo_from_rsync_output(a) diff --git a/test/test1.py b/test/test1.py index 9e94352..b810e9a 100644 --- a/test/test1.py +++ b/test/test1.py @@ -62,5 +62,5 @@ class KnownValues(unittest.TestCase): k,v = self.generate_results(example_tuple=i,attr="location") self.assertEqual(k, v) -if __name__ == "__mpain__": +if __name__ == "__main__": unittest.main() -- cgit v1.2.3-54-g00ecf From 1db8ccbc9221be6c30884172c00caefa217f66a5 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 16:47:03 -0600 Subject: Added test for pkginfo_from_file --- test/test_pkginfo_from_file.py | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 test/test_pkginfo_from_file.py diff --git a/test/test_pkginfo_from_file.py b/test/test_pkginfo_from_file.py new file mode 100644 index 0000000..0d7ede6 --- /dev/null +++ b/test/test_pkginfo_from_file.py @@ -0,0 +1,76 @@ +#! /usr/bin/python +# -*- encoding: utf-8 -*- +""" """ + +__author__ = "Joshua Ismael Haase Hernández " +__version__ = "$Revision: 1.1 $" +__date__ = "$Date: 2011/02/08 $" +__copyright__ = "Copyright (c) 2011 Joshua Ismael Haase Hernández" +__license__ = "GPL3+" + +from repm.config import * +from repm.filter import * +import unittest + +class KnownValues(unittest.TestCase): + # (filename, name, version, release, arch) + # filename is location + known=( + ("community-testing/os/i686/inputattach-1.24-3-i686.pkg.tar.xz","inputattach","1.24","3","i686"), + ("community-testing/os/i686/ngspice-22-1-i686.pkg.tar.xz","ngspice","22","1","i686"), + ("community-testing/os/i686/tmux-1.4-2-i686.pkg.tar.xz","tmux","1.4","2","i686"), + ("community-testing/os/i686/tor-0.2.1.29-2-i686.pkg.tar.xz","tor","0.2.1.29","2","i686"), + ("../../../pool/community/tor-0.2.1.29-2-i686.pkg.tar.xz","tor","0.2.1.29","2","i686"), + ("community-testing/os/x86_64/inputattach-1.24-3-x86_64.pkg.tar.xz","inputattach","1.24","3","x86_64"), + ("../../../pool/community/inputattach-1.24-3-x86_64.pkg.tar.xz","inputattach","1.24","3","x86_64"), + ("tor-0.2.1.29-2-x86_64.pkg.tar.xz","tor","0.2.1.29","2","x86_64"), + ) + + def generate_results(self, example_tuple, attr): + location, name, version, release, arch = example_tuple + return pkginfo_from_filename(location)[attr], locals()[attr] + + def testReturnPackageObject(self): + for i in self.known: + location, name, version, release, arch = i + self.assertIsInstance(pkginfo_from_filename(location),Package) + + def testNames(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="name") + self.assertEqual(k, v) + + def testVersions(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="version") + self.assertEqual(k, v) + + def testArchs(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="arch") + self.assertEqual(k, v) + + def testReleases(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="release") + self.assertEqual(k, v) + + def testLocations(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="location") + self.assertEqual(k, v) + +class BadInput(unittest.TestCase): + bad=("community-testing/os/i686/community-testing.db", + "community-testing/os/i686/community-testing.db.tar.gz", + "community-testing/os/i686/community-testing.db.tar.gz.old", + "community-testing/os/i686/community-testing.files", + "community-testing/os/i686/community-testing.files.tar.gz", + "community-testing/os/x86_64") + + def testBadInput(self): + for i in self.bad: + self.assertRaises(NonValidFile,pkginfo_from_filename,i) + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3-54-g00ecf From b525eeca86d3c5a25f971a12ceeae44fadd6fa94 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 16:59:28 -0600 Subject: renamed test1 to be informative --- test/test_pkginfo_from_rsync_output.py | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/test_pkginfo_from_rsync_output.py diff --git a/test/test_pkginfo_from_rsync_output.py b/test/test_pkginfo_from_rsync_output.py new file mode 100644 index 0000000..b810e9a --- /dev/null +++ b/test/test_pkginfo_from_rsync_output.py @@ -0,0 +1,66 @@ +# -*- encoding: utf-8 -*- +""" """ + +__author__ = "Joshua Ismael Haase Hernández " +__version__ = "$Revision: 1.1 $" +__date__ = "$Date: 2011/02/08 $" +__copyright__ = "Copyright (c) 2011 Joshua Ismael Haase Hernández" +__license__ = "GPL3+" + +from repm.config import * +from repm.filter import * +import unittest + +class KnownValues(unittest.TestCase): + directory_list=("drwxrwxr-x 15 2010/09/11 11:28:50 community-staging", + "drwxrwxr-x 30 2010/09/11 11:28:50 community-staging/os", + 'dr-xr-sr-x 4096 2010/09/11 11:37:10 .') + # (rsync_out, name, version, arch, release, location) + examples=( + ("lrwxrwxrwx 53 2011/01/31 01:52:06 community-testing/os/i686/apvlv-0.1.0-2-i686.pkg.tar.xz -> ../../../pool/community/apvlv-0.1.0-2-i686.pkg.tar.xz", "apvlv","0.1.0","i686", "2", "community-testing/os/i686/apvlv-0.1.0-2-i686.pkg.tar.xz"), + ("lrwxrwxrwx 56 2011/02/04 14:34:08 community-testing/os/i686/calibre-0.7.44-2-i686.pkg.tar.xz -> ../../../pool/community/calibre-0.7.44-2-i686.pkg.tar.xz","calibre","0.7.44","i686", "2", "community-testing/os/i686/calibre-0.7.44-2-i686.pkg.tar.xz"), + ("-rw-rw-r-- 5846249 2010/11/13 10:54:25 pool/community/abuse-0.7.1-1-x86_64.pkg.tar.gz", + "abuse","0.7.1","x86_64","1","pool/community/abuse-0.7.1-1-x86_64.pkg.tar.gz"), + ("-rw-rw-r-- 982768 2011/02/05 14:38:17 pool/community/acetoneiso2-2.3-2-i686.pkg.tar.xz", + "acetoneiso2","2.3","i686", "2", "pool/community/acetoneiso2-2.3-2-i686.pkg.tar.xz"), + ("-rw-rw-r-- 982764 2011/02/05 14:38:40 pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz", + "acetoneiso2","2.3","x86_64","2","pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz") + ) + + def generate_results(self, example_tuple, attr): + rsync_out, name, version, arch, release, location = example_tuple + return pkginfo_from_rsync_output(rsync_out)[0][attr], locals()[attr] + + def testDirectoryOutput(self): + """pkginfo_from_rsync_output should ignore directories""" + rsync_out="\n".join(self.directory_list) + result=pkginfo_from_rsync_output(rsync_out) + self.assertEqual(tuple(), result) + + def testNames(self): + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="name") + self.assertEqual(k, v) + + def testVersions(self): + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="version") + self.assertEqual(k, v) + + def testArchs(self): + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="arch") + self.assertEqual(k, v) + + def testReleases(self): + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="release") + self.assertEqual(k, v) + + def testLocations(self): + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="location") + self.assertEqual(k, v) + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3-54-g00ecf From a20a7fc689fd0e8680cbc13adfa6fdc2849e4397 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 17:00:13 -0600 Subject: idem --- test/test1.py | 66 ----------------------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 test/test1.py diff --git a/test/test1.py b/test/test1.py deleted file mode 100644 index b810e9a..0000000 --- a/test/test1.py +++ /dev/null @@ -1,66 +0,0 @@ -# -*- encoding: utf-8 -*- -""" """ - -__author__ = "Joshua Ismael Haase Hernández " -__version__ = "$Revision: 1.1 $" -__date__ = "$Date: 2011/02/08 $" -__copyright__ = "Copyright (c) 2011 Joshua Ismael Haase Hernández" -__license__ = "GPL3+" - -from repm.config import * -from repm.filter import * -import unittest - -class KnownValues(unittest.TestCase): - directory_list=("drwxrwxr-x 15 2010/09/11 11:28:50 community-staging", - "drwxrwxr-x 30 2010/09/11 11:28:50 community-staging/os", - 'dr-xr-sr-x 4096 2010/09/11 11:37:10 .') - # (rsync_out, name, version, arch, release, location) - examples=( - ("lrwxrwxrwx 53 2011/01/31 01:52:06 community-testing/os/i686/apvlv-0.1.0-2-i686.pkg.tar.xz -> ../../../pool/community/apvlv-0.1.0-2-i686.pkg.tar.xz", "apvlv","0.1.0","i686", "2", "community-testing/os/i686/apvlv-0.1.0-2-i686.pkg.tar.xz"), - ("lrwxrwxrwx 56 2011/02/04 14:34:08 community-testing/os/i686/calibre-0.7.44-2-i686.pkg.tar.xz -> ../../../pool/community/calibre-0.7.44-2-i686.pkg.tar.xz","calibre","0.7.44","i686", "2", "community-testing/os/i686/calibre-0.7.44-2-i686.pkg.tar.xz"), - ("-rw-rw-r-- 5846249 2010/11/13 10:54:25 pool/community/abuse-0.7.1-1-x86_64.pkg.tar.gz", - "abuse","0.7.1","x86_64","1","pool/community/abuse-0.7.1-1-x86_64.pkg.tar.gz"), - ("-rw-rw-r-- 982768 2011/02/05 14:38:17 pool/community/acetoneiso2-2.3-2-i686.pkg.tar.xz", - "acetoneiso2","2.3","i686", "2", "pool/community/acetoneiso2-2.3-2-i686.pkg.tar.xz"), - ("-rw-rw-r-- 982764 2011/02/05 14:38:40 pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz", - "acetoneiso2","2.3","x86_64","2","pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz") - ) - - def generate_results(self, example_tuple, attr): - rsync_out, name, version, arch, release, location = example_tuple - return pkginfo_from_rsync_output(rsync_out)[0][attr], locals()[attr] - - def testDirectoryOutput(self): - """pkginfo_from_rsync_output should ignore directories""" - rsync_out="\n".join(self.directory_list) - result=pkginfo_from_rsync_output(rsync_out) - self.assertEqual(tuple(), result) - - def testNames(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="name") - self.assertEqual(k, v) - - def testVersions(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="version") - self.assertEqual(k, v) - - def testArchs(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="arch") - self.assertEqual(k, v) - - def testReleases(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="release") - self.assertEqual(k, v) - - def testLocations(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="location") - self.assertEqual(k, v) - -if __name__ == "__main__": - unittest.main() -- cgit v1.2.3-54-g00ecf From 9fecb003deaae2364e0d9d41055ca33a7d1a2131 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 17:09:16 -0600 Subject: * Changed format of run_rsync debug output. --- pato2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pato2.py b/pato2.py index 55e63e7..13242f7 100644 --- a/pato2.py +++ b/pato2.py @@ -203,7 +203,7 @@ def run_rsync(base_for_rsync, dir_list_for_rsync=(repo_list + dir_list), """ Runs rsync and gets returns it's output """ cmd = str(generate_rsync_command(base_for_rsync, (repo_list + dir_list))) if debug: - printf("rsync_command" + cmd) + printf("rsync_command: " + cmd) return commands.getoutput(cmd) if __name__ == "__main__": -- cgit v1.2.3-54-g00ecf From e4ffbeff4bbdeb3f57c39c6f6dac3ce902db9b4c Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 17:14:37 -0600 Subject: * Fixed generate_rsync_command --- pato2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pato2.py b/pato2.py index 13242f7..74d18be 100644 --- a/pato2.py +++ b/pato2.py @@ -195,8 +195,8 @@ def generate_rsync_command(base_command, dir_list, destdir=repodir, if blacklist_file: return " ".join((base_command, "--exclude-from-file="+blacklist_file, - source + dir_list, destdir)) - return " ".join((base_command, source + dir_list, destdir)) + os.join(source, dir_list), destdir)) + return " ".join((base_command, os.join(source, dir_list), destdir)) def run_rsync(base_for_rsync, dir_list_for_rsync=(repo_list + dir_list), debug=verbose): -- cgit v1.2.3-54-g00ecf From e5b869eade3fbf47cf9ac1b7c6be34dfee14b2c1 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 17:17:31 -0600 Subject: * Fixed generate_rsync_command --- pato2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pato2.py b/pato2.py index 74d18be..e32a4dd 100644 --- a/pato2.py +++ b/pato2.py @@ -195,8 +195,8 @@ def generate_rsync_command(base_command, dir_list, destdir=repodir, if blacklist_file: return " ".join((base_command, "--exclude-from-file="+blacklist_file, - os.join(source, dir_list), destdir)) - return " ".join((base_command, os.join(source, dir_list), destdir)) + os.path.join(source, dir_list), destdir)) + return " ".join((base_command, os.path.join(source, dir_list), destdir)) def run_rsync(base_for_rsync, dir_list_for_rsync=(repo_list + dir_list), debug=verbose): -- cgit v1.2.3-54-g00ecf From f923ab304017a71136642ed7b9780441edcaf441 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 19:36:26 -0600 Subject: * TestCase for pkginfo_from_rsync_output * Corrected __eq__ method in Package class * Corrected pkginfo_from_rsync_output --- config.py | 2 +- filter.py | 18 ++++---- test/rsync_output_sample | 14 +++++++ test/test_pkginfo_from_rsync_output.py | 76 ++++++++++++---------------------- 4 files changed, 52 insertions(+), 58 deletions(-) create mode 100644 test/rsync_output_sample diff --git a/config.py b/config.py index bd46688..465a8a8 100644 --- a/config.py +++ b/config.py @@ -82,7 +82,7 @@ class Package: if not isinstance(x, Package): return False for key in self.package_info.keys(): - if x[key] != self[key]: + if x[key] != self.package_info[key]: return False else: return True diff --git a/filter.py b/filter.py index ad3b33d..55ab94a 100644 --- a/filter.py +++ b/filter.py @@ -38,26 +38,28 @@ def pkginfo_from_rsync_output(rsync_output): Returns: ---------- package_list -> tuple Contains Package objects. """ - package_list=list() def package_or_link(line): """ Take info out of filename """ location_field = 4 - pkginfo_from_filename(line.rsplit()[location_field]) + return pkginfo_from_filename(line.rsplit()[location_field]) def do_nothing(): - pass + """""" options = { "d": do_nothing, "l": package_or_link, "-": package_or_link, " ": do_nothing} + + package_list=list() - for line in rsync_output.split("\n"): - if ".pkg.tar" in line: - pkginfo=options[line[0]](line) - if pkginfo_: - package_list.append(pkginfo) + lines=[x for x in rsync_output.split("\n") if ".pkg.tar" in x] + + for line in lines: + pkginfo=options[line[0]](line) + if pkginfo: + package_list.append(pkginfo) return tuple(package_list) diff --git a/test/rsync_output_sample b/test/rsync_output_sample new file mode 100644 index 0000000..72d9cd0 --- /dev/null +++ b/test/rsync_output_sample @@ -0,0 +1,14 @@ +dr-xr-sr-x 4096 2010/09/11 11:37:10 . +-rw-r--r-- 11 2011/02/08 00:00:01 lastsync +drwxrwxr-x 15 2010/09/11 11:28:50 community-staging +drwxrwxr-x 30 2010/09/11 11:28:50 community-staging/os +drwxrwxr-x 8192 2011/02/07 17:00:01 community-staging/os/i686 +lrwxrwxrwx 52 2010/12/23 16:51:01 community-staging/os/i686/alex-2.3.4-1-i686.pkg.tar.xz -> ../../../pool/community/alex-2.3.4-1-i686.pkg.tar.xz +lrwxrwxrwx 27 2011/02/07 14:02:54 community-staging/os/i686/community-staging.db -> community-staging.db.tar.gz +-rw-rw-r-- 2237 2011/02/07 14:02:54 community-staging/os/i686/community-staging.db.tar.gz +-rw-rw-r-- 3209 2011/02/07 14:00:13 community-staging/os/i686/community-staging.db.tar.gz.old +drwxrwxr-x 15 2009/07/22 15:07:56 community +drwxrwxr-x 40 2009/08/04 15:57:42 community/os +drwxrwsr-x 36864 2011/02/03 05:00:01 community/os/any +-rw-rw-r-- 303336 2010/07/16 10:06:28 community/os/any/any2dvd-0.34-4-any.pkg.tar.xz +-rw-rw-r-- 221664 2010/03/28 15:55:48 community/os/x86_64/gmime22-2.2.26-1-x86_64.pkg.tar.xz diff --git a/test/test_pkginfo_from_rsync_output.py b/test/test_pkginfo_from_rsync_output.py index b810e9a..81f14d9 100644 --- a/test/test_pkginfo_from_rsync_output.py +++ b/test/test_pkginfo_from_rsync_output.py @@ -12,55 +12,33 @@ from repm.filter import * import unittest class KnownValues(unittest.TestCase): - directory_list=("drwxrwxr-x 15 2010/09/11 11:28:50 community-staging", - "drwxrwxr-x 30 2010/09/11 11:28:50 community-staging/os", - 'dr-xr-sr-x 4096 2010/09/11 11:37:10 .') - # (rsync_out, name, version, arch, release, location) - examples=( - ("lrwxrwxrwx 53 2011/01/31 01:52:06 community-testing/os/i686/apvlv-0.1.0-2-i686.pkg.tar.xz -> ../../../pool/community/apvlv-0.1.0-2-i686.pkg.tar.xz", "apvlv","0.1.0","i686", "2", "community-testing/os/i686/apvlv-0.1.0-2-i686.pkg.tar.xz"), - ("lrwxrwxrwx 56 2011/02/04 14:34:08 community-testing/os/i686/calibre-0.7.44-2-i686.pkg.tar.xz -> ../../../pool/community/calibre-0.7.44-2-i686.pkg.tar.xz","calibre","0.7.44","i686", "2", "community-testing/os/i686/calibre-0.7.44-2-i686.pkg.tar.xz"), - ("-rw-rw-r-- 5846249 2010/11/13 10:54:25 pool/community/abuse-0.7.1-1-x86_64.pkg.tar.gz", - "abuse","0.7.1","x86_64","1","pool/community/abuse-0.7.1-1-x86_64.pkg.tar.gz"), - ("-rw-rw-r-- 982768 2011/02/05 14:38:17 pool/community/acetoneiso2-2.3-2-i686.pkg.tar.xz", - "acetoneiso2","2.3","i686", "2", "pool/community/acetoneiso2-2.3-2-i686.pkg.tar.xz"), - ("-rw-rw-r-- 982764 2011/02/05 14:38:40 pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz", - "acetoneiso2","2.3","x86_64","2","pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz") - ) - - def generate_results(self, example_tuple, attr): - rsync_out, name, version, arch, release, location = example_tuple - return pkginfo_from_rsync_output(rsync_out)[0][attr], locals()[attr] - - def testDirectoryOutput(self): - """pkginfo_from_rsync_output should ignore directories""" - rsync_out="\n".join(self.directory_list) - result=pkginfo_from_rsync_output(rsync_out) - self.assertEqual(tuple(), result) - - def testNames(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="name") - self.assertEqual(k, v) - - def testVersions(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="version") - self.assertEqual(k, v) - - def testArchs(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="arch") - self.assertEqual(k, v) - - def testReleases(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="release") - self.assertEqual(k, v) - - def testLocations(self): - for i in self.examples: - k,v = self.generate_results(example_tuple=i,attr="location") - self.assertEqual(k, v) + try: + output_file = open("rsync_output_sample") + rsync_out= output_file.read() + output_file.close() + except IOError: print("There is no rsync_output_sample file") + + pkglist = pkginfo_from_rsync_output(rsync_out) + + def testOutputArePackages(self): + if not self.pkglist: + self.fail("not pkglist:" + str(self.pkglist)) + for pkg in self.pkglist: + self.assertIsInstance(pkg,Package) + + def testFirstPkg(self): + first_package_info=Package() + first_package_info.package_info={ "name" : "alex", + "version" : "2.3.4", + "release" : "1", + "arch" : "i686", + "license" : False, + "location": "community-staging/os/i686/alex-2.3.4-1-i686.pkg.tar.xz"} + if self.pkglist: + first_package=self.pkglist[0] + else: + self.fail(self.pkglist) + self.assertEqual(first_package,first_package_info) if __name__ == "__main__": unittest.main() -- cgit v1.2.3-54-g00ecf From 3866f148dae1f6c90fc6d903784b65e452c048c6 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 22:45:11 -0600 Subject: * Added debug action to generate_exclude_list_from_blacklist * Added test data to test_pkginfo_from_rsync_output.py --- filter.py | 2 +- test/test_pkginfo_from_rsync_output.py | 38 ++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/filter.py b/filter.py index 55ab94a..f8182e3 100644 --- a/filter.py +++ b/filter.py @@ -108,7 +108,7 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, if debug: printf(a) - + return a try: fsock = open(exclude_file,"w") try: diff --git a/test/test_pkginfo_from_rsync_output.py b/test/test_pkginfo_from_rsync_output.py index 81f14d9..5ed5dd8 100644 --- a/test/test_pkginfo_from_rsync_output.py +++ b/test/test_pkginfo_from_rsync_output.py @@ -11,7 +11,27 @@ from repm.config import * from repm.filter import * import unittest -class KnownValues(unittest.TestCase): +example_package_list=(Package(),Package(),Package()) +example_package_list[0].package_info={ "name" : "alex", + "version" : "2.3.4", + "release" : "1", + "arch" : "i686", + "license" : False, + "location": "community-staging/os/i686/alex-2.3.4-1-i686.pkg.tar.xz"} +example_package_list[1].package_info={ "name" : "any2dvd", + "version" : "0.34", + "release" : "4", + "arch" : "any", + "license" : False, + "location": "community/os/any/any2dvd-0.34-4-any.pkg.tar.xz"} +example_package_list[2].package_info={ "name" : "gmime22", + "version" : "2.2.26", + "release" : "1", + "arch" : "x86_64", + "license" : False, + "location": "community/os/x86_64/gmime22-2.2.26-1-x86_64.pkg.tar.xz"} + +class pkginfoFromRsyncOutput(unittest.TestCase): try: output_file = open("rsync_output_sample") rsync_out= output_file.read() @@ -26,19 +46,15 @@ class KnownValues(unittest.TestCase): for pkg in self.pkglist: self.assertIsInstance(pkg,Package) - def testFirstPkg(self): - first_package_info=Package() - first_package_info.package_info={ "name" : "alex", - "version" : "2.3.4", - "release" : "1", - "arch" : "i686", - "license" : False, - "location": "community-staging/os/i686/alex-2.3.4-1-i686.pkg.tar.xz"} + def testPackageInfo(self): if self.pkglist: first_package=self.pkglist[0] else: self.fail(self.pkglist) - self.assertEqual(first_package,first_package_info) - + self.assertEqual(first_package,example_package_list[0]) + +class generateRsyncBlacklist(unittest.TestCase): + """ Test Blacklist generation """ + if __name__ == "__main__": unittest.main() -- cgit v1.2.3-54-g00ecf From 9de298a7b88f7f36aec4c9344356a935c67cfeb3 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 14 Feb 2011 23:27:46 -0600 Subject: * Added test for generate_exclude_list_from_blacklist * Fixed listado to strip spaces --- filter.py | 1 - pato2.py | 2 +- test/blacklist_sample | 2 ++ test/test_pkginfo_from_rsync_output.py | 17 +++++++++++------ 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 test/blacklist_sample diff --git a/filter.py b/filter.py index f8182e3..f91ec68 100644 --- a/filter.py +++ b/filter.py @@ -107,7 +107,6 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, a.append(package["location"]) if debug: - printf(a) return a try: fsock = open(exclude_file,"w") diff --git a/pato2.py b/pato2.py index e32a4dd..5bc97a9 100644 --- a/pato2.py +++ b/pato2.py @@ -42,7 +42,7 @@ def listado(filename_): archivo = open(filename_,"r") lista = archivo.read().split("\n") archivo.close() - return [pkg.split(":")[0] for pkg in lista if pkg] + return [pkg.split(":")[0].rstrip() for pkg in lista if pkg] def db(repo_,arch_): """Construye un nombre para sincronizar una base de datos.""" diff --git a/test/blacklist_sample b/test/blacklist_sample new file mode 100644 index 0000000..2a02af6 --- /dev/null +++ b/test/blacklist_sample @@ -0,0 +1,2 @@ +alex:alex-libre: Aquí va un comentario +gmime22 ::Non free dependencies \ No newline at end of file diff --git a/test/test_pkginfo_from_rsync_output.py b/test/test_pkginfo_from_rsync_output.py index 5ed5dd8..aca49e8 100644 --- a/test/test_pkginfo_from_rsync_output.py +++ b/test/test_pkginfo_from_rsync_output.py @@ -47,14 +47,19 @@ class pkginfoFromRsyncOutput(unittest.TestCase): self.assertIsInstance(pkg,Package) def testPackageInfo(self): - if self.pkglist: - first_package=self.pkglist[0] - else: - self.fail(self.pkglist) - self.assertEqual(first_package,example_package_list[0]) + if not self.pkglist: + self.fail("Pkglist doesn't exist: " + str(self.pkglist)) + self.assertEqual(self.pkglist,example_package_list) class generateRsyncBlacklist(unittest.TestCase): """ Test Blacklist generation """ - + def testListado(self): + self.assertEqual(listado("blacklist_sample"),["alex","gmime22"]) + + def testExcludeFiles(self): + a=generate_exclude_list_from_blacklist(example_package_list,listado("blacklist_sample"),debug=True) + b=[example_package_list[0]["location"],example_package_list[2]["location"]] + self.assertEqual(a,b) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3-54-g00ecf From cf3253774c64e6430d4e3afb826cc6c8b0e4b91b Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 15 Feb 2011 00:13:37 -0600 Subject: * Upgraded sync_all_repo --- config.py | 2 +- pato2.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/config.py b/config.py index 465a8a8..36b54df 100644 --- a/config.py +++ b/config.py @@ -44,7 +44,7 @@ rsync_blacklist = docs + "/rsyncBlacklist" # Rsync commands rsync_list_command="rsync -a --no-motd --list-only " - +rsync_update_command="rsync -av --delete-after --delay-updates " # Classes and Exceptions class NonValidFile(ValueError): pass diff --git a/pato2.py b/pato2.py index 5bc97a9..9b902f4 100644 --- a/pato2.py +++ b/pato2.py @@ -25,7 +25,7 @@ """ from repm.config import * - +from repm.filter import * import tarfile from glob import glob from os.path import isdir, isfile @@ -52,12 +52,14 @@ def packages(repo_, arch_, expr="*"): """ Get packages on a repo, arch folder """ return tuple( glob( repodir + "/" + repo_ + "/os/" + arch_ + "/" + expr ) ) -def sync_all_repo(verbose_=verbose): - folders = ",".join(repo_list + dir_list) - cmd_ = "rsync -av --delete-after --delay-updates " + mirror + mirrorpath + "/{" + folders + "} " + repodir - printf(cmd_) - a=commands.getoutput(cmd_) - if verbose_: printf(a) +def sync_all_repo(debug=verbose): + cmd=generate_rsync_command(rsync_list_command) + rsout=run_rsync(cmd) + pkgs=pkginfo_from_rsync_output(rsout) + generate_exclude_list_from_blacklist(pkgs,listado(blacklist)) + cmd=generate_rsync_command(rsync_update_command,blacklist_file=blacklist) + a=run_rsync(cmd) + if debug: printf(a) def get_from_desc(desc, var,db_tar_file=False): """ Get a var from desc file """ @@ -166,7 +168,7 @@ def get_licenses(verbose_=verbose): a=commands.getoutput(cmd_) if verbose_: printf(a) -def generate_rsync_command(base_command, dir_list, destdir=repodir, +def generate_rsync_command(base_command, dir_list=(repo_list + dir_list), destdir=repodir, source=mirror+mirrorpath, blacklist_file=False): """ Generates an rsync command for executing it by combining all parameters. @@ -198,10 +200,8 @@ def generate_rsync_command(base_command, dir_list, destdir=repodir, os.path.join(source, dir_list), destdir)) return " ".join((base_command, os.path.join(source, dir_list), destdir)) -def run_rsync(base_for_rsync, dir_list_for_rsync=(repo_list + dir_list), - debug=verbose): +def run_rsync(command,debug=verbose): """ Runs rsync and gets returns it's output """ - cmd = str(generate_rsync_command(base_for_rsync, (repo_list + dir_list))) if debug: printf("rsync_command: " + cmd) return commands.getoutput(cmd) -- cgit v1.2.3-54-g00ecf From 8975a9021c8b04fb81d9b9358a55b89ecdb373b7 Mon Sep 17 00:00:00 2001 From: Parabola Date: Mon, 14 Feb 2011 22:18:36 -0800 Subject: changed config --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 36b54df..c60e8f3 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,7 @@ other = ("any",) # Output output = True -verbose = False +verbose = True # Files blacklist = docs + "/blacklist.txt" -- cgit v1.2.3-54-g00ecf From fb247388925beabe01162f28bfcba7fcf8809254 Mon Sep 17 00:00:00 2001 From: Parabola Date: Mon, 14 Feb 2011 22:41:29 -0800 Subject: * Fixed for rsync to run --- pato2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pato2.py b/pato2.py index 9b902f4..c598c2f 100644 --- a/pato2.py +++ b/pato2.py @@ -196,15 +196,15 @@ def generate_rsync_command(base_command, dir_list=(repo_list + dir_list), destdi dir_list="{" + ",".join(dir_list) + "}" if blacklist_file: - return " ".join((base_command, "--exclude-from-file="+blacklist_file, + return " ".join((base_command, "--exclude-from="+blacklist_file, os.path.join(source, dir_list), destdir)) return " ".join((base_command, os.path.join(source, dir_list), destdir)) def run_rsync(command,debug=verbose): """ Runs rsync and gets returns it's output """ if debug: - printf("rsync_command: " + cmd) - return commands.getoutput(cmd) + printf("rsync_command: " + command) + return commands.getoutput(command) if __name__ == "__main__": from time import time -- cgit v1.2.3-54-g00ecf From 7bb59afd65871ed2949b86ec6cef805ea2fd3dd2 Mon Sep 17 00:00:00 2001 From: Nicolás Reynolds Date: Tue, 15 Feb 2011 19:25:51 -0800 Subject: Fixed add_free_repo --- config.py | 1 + pato2.py | 295 ++++++++++++++++++++++++++++++++------------------------------ 2 files changed, 152 insertions(+), 144 deletions(-) diff --git a/config.py b/config.py index c60e8f3..6420355 100644 --- a/config.py +++ b/config.py @@ -19,6 +19,7 @@ logdir = path + "/log" ## Must be defined logname= logdir + "/" + time__ + "-repo-maintainer.log" +freedir= path + "/free/" repodir= path + "/repo" tmp = home + "/tmp" archdb = tmp + "/db" diff --git a/pato2.py b/pato2.py index c598c2f..f5deb48 100644 --- a/pato2.py +++ b/pato2.py @@ -31,142 +31,149 @@ from glob import glob from os.path import isdir, isfile def printf(text,output_=output): - """Guarda el texto en la variable log y puede imprimir en pantalla.""" - log_file = open(logname, 'a') - log_file.write("\n" + str(text) + "\n") - log_file.close() - if output_: print (str(text) + "\n") + """Guarda el texto en la variable log y puede imprimir en pantalla.""" + log_file = open(logname, 'a') + log_file.write("\n" + str(text) + "\n") + log_file.close() + if output_: print (str(text) + "\n") def listado(filename_): - """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] + """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] def db(repo_,arch_): - """Construye un nombre para sincronizar una base de datos.""" - return "/%s/os/%s/%s.db.tar.gz" % (repo_, arch_, repo_) + """Construye un nombre para sincronizar una base de datos.""" + return "/%s/os/%s/%s.db.tar.gz" % (repo_, arch_, repo_) def packages(repo_, arch_, expr="*"): - """ Get packages on a repo, arch folder """ - return tuple( glob( repodir + "/" + repo_ + "/os/" + arch_ + "/" + expr ) ) + """ Get packages on a repo, arch folder """ + return tuple( glob( repodir + "/" + repo_ + "/os/" + arch_ + "/" + expr ) ) def sync_all_repo(debug=verbose): - cmd=generate_rsync_command(rsync_list_command) - rsout=run_rsync(cmd) - pkgs=pkginfo_from_rsync_output(rsout) - generate_exclude_list_from_blacklist(pkgs,listado(blacklist)) - cmd=generate_rsync_command(rsync_update_command,blacklist_file=blacklist) - a=run_rsync(cmd) - if debug: printf(a) + cmd=generate_rsync_command(rsync_list_command) + rsout=run_rsync(cmd) + pkgs=pkginfo_from_rsync_output(rsout) + generate_exclude_list_from_blacklist(pkgs,listado(blacklist)) + cmd=generate_rsync_command(rsync_update_command,blacklist_file=blacklist) + a=run_rsync(cmd) + if debug: printf(a) def get_from_desc(desc, var,db_tar_file=False): - """ Get a var from desc file """ - desc = desc.split("\n") - return desc[desc.index(var)+1] + """ Get a var from desc file """ + desc = desc.split("\n") + return desc[desc.index(var)+1] def get_info(repo_,arch_,db_tar_file=False,verbose_=verbose): - """ Makes a list of package name, file and license """ - info=list() - # Extract DB tar.gz - commands.getoutput("mkdir -p " + archdb) - if not db_tar_file: - db_tar_file = repodir + db(repo_,arch_) - if isfile(db_tar_file): - try: - db_open_tar = tarfile.open(db_tar_file, 'r:gz') - except tarfile.ReadError: - printf("No valid db_file %s" % db_tar_file) - return(tuple()) - else: - printf("No db_file %s" % db_tar_file) - return(tuple()) - for file in db_open_tar.getmembers(): - db_open_tar.extract(file, archdb) - db_open_tar.close() - # Get info from file - for dir_ in glob(archdb + "/*"): - if isdir(dir_) and isfile(dir_ + "/desc"): - pkg_desc_file = open(dir_ + "/desc", "r") - desc = pkg_desc_file.read() - pkg_desc_file.close() - info.append(( get_from_desc(desc,"%NAME%"), - dir_.split("/")[-1], - get_from_desc(desc,"%LICENSE%") )) - if verbose_: printf(info) - commands.getoutput("rm -r %s/*" % archdb) - return tuple(info) + """ Makes a list of package name, file and license """ + info=list() + # Extract DB tar.gz + commands.getoutput("mkdir -p " + archdb) + if not db_tar_file: + db_tar_file = repodir + db(repo_,arch_) + if isfile(db_tar_file): + try: + db_open_tar = tarfile.open(db_tar_file, 'r:gz') + except tarfile.ReadError: + printf("No valid db_file %s" % db_tar_file) + return(tuple()) + else: + printf("No db_file %s" % db_tar_file) + return(tuple()) + for file in db_open_tar.getmembers(): + db_open_tar.extract(file, archdb) + db_open_tar.close() + # Get info from file + for dir_ in glob(archdb + "/*"): + if isdir(dir_) and isfile(dir_ + "/desc"): + pkg_desc_file = open(dir_ + "/desc", "r") + desc = pkg_desc_file.read() + pkg_desc_file.close() + info.append(( get_from_desc(desc,"%NAME%"), + dir_.split("/")[-1], + get_from_desc(desc,"%LICENSE%") )) + if verbose_: printf(info) + commands.getoutput("rm -r %s/*" % archdb) + return tuple(info) def make_pending(repo_,arch_,info_): - """ Si los paquetes no están en blacklist ni whitelist y la licencia contiene "custom" los agrega a pending""" - search = tuple( listado(blacklist) + listado (whitelist) ) - if verbose: printf("blaclist + whitelist= " + str(search) ) - lista_=list() - for (name,pkg_,license_) in info_: - if "custom" in license_: - if name not in search: - lista_.append( (name, license_ ) ) - elif not name: - printf( pkg_ + " package has no %NAME% attibute " ) - if verbose: printf( lista_ ) - a=open( pending + "-" + repo_ + ".txt", "w" ).write( - "\n".join([name + ":" + license_ for (name,license_) in lista_]) ) + """ Si los paquetes no están en blacklist ni whitelist y la licencia contiene "custom" los agrega a pending""" + search = tuple( listado(blacklist) + listado (whitelist) ) + if verbose: printf("blaclist + whitelist= " + str(search) ) + lista_=list() + for (name,pkg_,license_) in info_: + if "custom" in license_: + if name not in search: + lista_.append( (name, license_ ) ) + elif not name: + printf( pkg_ + " package has no %NAME% attibute " ) + if verbose: printf( lista_ ) + a=open( pending + "-" + repo_ + ".txt", "w" ).write( + "\n".join([name + ":" + license_ for (name,license_) in lista_]) ) def remove_from_blacklist(repo_,arch_,info_,blacklist_): - """ Check the blacklist and remove packages on the db""" - lista_=list() - pack_=list() - for (name_, pkg_, license_) in info_: - if name_ in blacklist_: - lista_.append(name_) - for p in packages(repo_,arch_,pkg_ + "*"): - pack_.append(p) - if lista_: - lista_=" ".join(lista_) - com_ = "repo-remove " + repodir + db(repo_,arch_) + " " + lista_ - printf(com_) - a = commands.getoutput(com_) - if verbose: printf(a) - if pack_: - pack_=" ".join(pack_) - com_="chmod a-r " + pack_ - printf(com_) - a=commands.getoutput(com_) - if verbose: printf(a) + """ Check the blacklist and remove packages on the db""" + lista_=list() + pack_=list() + for (name_, pkg_, license_) in info_: + if name_ in blacklist_: + lista_.append(name_) + for p in packages(repo_,arch_,pkg_ + "*"): + pack_.append(p) + if lista_: + lista_=" ".join(lista_) + com_ = "repo-remove " + repodir + db(repo_,arch_) + " " + lista_ + printf(com_) + a = commands.getoutput(com_) + if verbose: printf(a) + if pack_: + pack_=" ".join(pack_) + com_="chmod a-r " + pack_ + printf(com_) + a=commands.getoutput(com_) + if verbose: printf(a) def link(repo_,arch_,file_): - """ Makes a link in the repo for the package """ - cmd_="ln -f " + file_ + " " + repodir + "/" + repo_ + "/os/" + arch_ - a=commands.getoutput(cmd_) - if verbose: - printf(cmd_ + a) + """ Makes a link in the repo for the package """ + cmd_="ln -f " + file_ + " " + repodir + "/" + repo_ + "/os/" + arch_ + a=commands.getoutput(cmd_) + if verbose: + printf(cmd_ + a) def add_free_repo(verbose_=verbose): - for repo_ in repo_list: - for arch_ in arch_list: - lista_=list() - for file_ in glob(free_path + repo_ + "/os/" + arch_ + "/*.pkg.tar.*"): - lista_.append(file_) - link(repo_,arch_,file_) - for dir_ in other: - for file_ in glob(free_path + repo_ + "/os/" + dir_ + "/*.pkg.tar.*"): - lista_.append(file_) - link(repo_,arch_,file_) - if lista_: - lista_=" ".join(lista_) - if verbose: printf(lista_) - cmd_="repo-add " + repodir + db(repo_,arch_) + " " + lista_ - printf(cmd_) - a=commands.getoutput(cmd_) - if verbose: printf(a) + cmd_=home + "/usr/bin/sync-free" + printf(cmd_) + a=commands.getoutput(cmd_) + if verbose_: printf(a) + for repo_ in repo_list: + for arch_ in arch_list: + lista_=list() + for file_ in glob(freedir + repo_ + "/os/" + arch_ + "/*.pkg.tar.*"): + lista_.append(file_) + # link(repo_,arch_,file_) + for dir_ in other: + for file_ in glob(freedir + repo_ + "/os/" + dir_ + "/*.pkg.tar.*"): + lista_.append(file_) + # link(repo_,arch_,file_) + + printf(lista_) + + if lista_: + lista_=" ".join(lista_) + if verbose: printf(lista_) + cmd_="repo-add " + repodir + db(repo_,arch_) + " " + lista_ + printf(cmd_) + a=commands.getoutput(cmd_) + if verbose: printf(a) def get_licenses(verbose_=verbose): - """ Extract the license from packages in repo_,arch_ and in pending_ file""" - cmd_=home + "/usr/bin/get_license.sh" - printf(cmd_) - a=commands.getoutput(cmd_) - if verbose_: printf(a) + """ Extract the license from packages in repo_,arch_ and in pending_ file""" + cmd_=home + "/usr/bin/get_license.sh" + printf(cmd_) + a=commands.getoutput(cmd_) + if verbose_: printf(a) def generate_rsync_command(base_command, dir_list=(repo_list + dir_list), destdir=repodir, source=mirror+mirrorpath, blacklist_file=False): @@ -207,33 +214,33 @@ def run_rsync(command,debug=verbose): return commands.getoutput(command) if __name__ == "__main__": - from time import time - start_time = time() - def minute(): - return str(round((time() - start_time)/60, 1)) - - printf(" Cleaning %s folder " % (tmp) ) - commands.getoutput("rm -r %s/*" % tmp) - printf(" Syncing repo") - sync_all_repo(True) - - printf(" Updating databases and pending files lists: minute %s \n" % minute() ) - for repo in repo_list: - for arch in arch_list: - printf( "\n" + repo + "-" + arch + "\n" ) - printf( "Get info: minute %s " % minute() ) - info=get_info(repo,arch) - printf( "Make pending: minute %s" % minute() ) - make_pending(repo,arch,info) - printf( "Update DB: minute %s" % minute() ) - remove_from_blacklist( - repo, arch, info, tuple( listado(blacklist) + listado(pending + "-" + repo + ".txt") ) ) - - printf("Adding Parabola Packages: minute %s\n" % minute() ) - add_free_repo(True) - - printf("Extracting licenses in pending: minute %s" % minute() ) - get_licenses() - - printf("\n\nDelay: %s minutes \n" % minute()) - + from time import time + start_time = time() + def minute(): + return str(round((time() - start_time)/60, 1)) + + printf(" Cleaning %s folder " % (tmp) ) + commands.getoutput("rm -r %s/*" % tmp) + printf(" Syncing repo") + sync_all_repo(True) + + printf(" Updating databases and pending files lists: minute %s \n" % minute() ) + for repo in repo_list: + for arch in arch_list: + printf( "\n" + repo + "-" + arch + "\n" ) + printf( "Get info: minute %s " % minute() ) + info=get_info(repo,arch) + printf( "Make pending: minute %s" % minute() ) + make_pending(repo,arch,info) + printf( "Update DB: minute %s" % minute() ) + remove_from_blacklist( + repo, arch, info, tuple( listado(blacklist) + listado(pending + "-" + repo + ".txt") ) ) + + printf("Adding Parabola Packages: minute %s\n" % minute() ) + add_free_repo(True) + + printf("Extracting licenses in pending: minute %s" % minute() ) + get_licenses() + + printf("\n\nDelay: %s minutes \n" % minute()) + -- cgit v1.2.3-54-g00ecf From 9793aaf4e9a716f126e71a1db412cbd32f161593 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Thu, 3 Mar 2011 20:11:33 -0600 Subject: * repo-maintainer doesn't take out reading permission from pending files * Removed commented code --- pato2.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pato2.py b/pato2.py index f5deb48..21dde16 100644 --- a/pato2.py +++ b/pato2.py @@ -128,12 +128,6 @@ def remove_from_blacklist(repo_,arch_,info_,blacklist_): printf(com_) a = commands.getoutput(com_) if verbose: printf(a) - if pack_: - pack_=" ".join(pack_) - com_="chmod a-r " + pack_ - printf(com_) - a=commands.getoutput(com_) - if verbose: printf(a) def link(repo_,arch_,file_): """ Makes a link in the repo for the package """ @@ -152,11 +146,9 @@ def add_free_repo(verbose_=verbose): lista_=list() for file_ in glob(freedir + repo_ + "/os/" + arch_ + "/*.pkg.tar.*"): lista_.append(file_) - # link(repo_,arch_,file_) for dir_ in other: for file_ in glob(freedir + repo_ + "/os/" + dir_ + "/*.pkg.tar.*"): lista_.append(file_) - # link(repo_,arch_,file_) printf(lista_) -- cgit v1.2.3-54-g00ecf From a3694fd2824f6aab2905f52f64a138437f7e004b Mon Sep 17 00:00:00 2001 From: Parabola Date: Sat, 5 Mar 2011 10:56:49 -0800 Subject: Taken out «sources» from dir_list for rsync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index 6420355..b198450 100644 --- a/config.py +++ b/config.py @@ -27,9 +27,10 @@ archdb = tmp + "/db" free_path= path + "/free/" # Repo, arch, and other folders to use for repo -repo_list = ("core", "extra", "community", "testing", "community-testing", "multilib") -dir_list = ("pool","sources") -arch_list = ("i686", "x86_64") +# This are tuples, so **always keep a comma before closing parenthesis ** +repo_list = ("core", "extra", "community", "testing", "community-testing", "multilib",) +dir_list = ("pool",) +arch_list = ("i686", "x86_64",) other = ("any",) # Output -- cgit v1.2.3-54-g00ecf From 5a4480f1f3e2e7d0aec965b21f72f4454618333e Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Sat, 5 Mar 2011 13:13:41 -0600 Subject: * Added «depends» field to Package class. * Merged tests for filter functions in test_filter.py * Added testfiles for test_filter.py in test directory * Added pkginfo_from_desc function to filter.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 3 +- filter.py | 35 ++++++- test/core.db.tar.gz | Bin 0 -> 1637 bytes test/depends | 4 + test/desc | 39 ++++++++ test/test_filter.py | 169 +++++++++++++++++++++++++++++++++ test/test_pkginfo_from_file.py | 76 --------------- test/test_pkginfo_from_rsync_output.py | 65 ------------- 8 files changed, 248 insertions(+), 143 deletions(-) create mode 100644 test/core.db.tar.gz create mode 100644 test/depends create mode 100644 test/desc create mode 100644 test/test_filter.py delete mode 100644 test/test_pkginfo_from_file.py delete mode 100644 test/test_pkginfo_from_rsync_output.py diff --git a/config.py b/config.py index 6420355..688d6b5 100644 --- a/config.py +++ b/config.py @@ -62,7 +62,8 @@ class Package: "release" : False, "arch" : False, "license" : False, - "location": False} + "location": False, + "depends" : False,} def __setitem__(self, key, item): if key in self.package_info.keys(): diff --git a/filter.py b/filter.py index f91ec68..2fe61f0 100644 --- a/filter.py +++ b/filter.py @@ -26,6 +26,37 @@ def pkginfo_from_filename(filename): pkg["name"] = "-".join(fileattrs) return pkg +def pkginfo_from_desc(filename): + """ Returns pkginfo from desc file. + + Parameters: + ---------- + filename -> str File must exist + + 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_map={"name" :("%NAME%" , None), + "version" :("%VERSION%" , 0 ), + "release" :("%VERSION%" , 1 ), + "arch" :("%ARCH%" , None), + "license" :("%LICENSE%" , None), + "location":("%FILENAME%", None),} + + for key in info_map.keys(): + field,pos=info_map[key] + pkg[key]=info[info.index(field)+1] + if pos is not None: + pkg[key]=pkg[key].split("-")[pos] + return pkg def pkginfo_from_rsync_output(rsync_output): """ Generates a list of packages and versions from an rsync output @@ -45,7 +76,7 @@ def pkginfo_from_rsync_output(rsync_output): return pkginfo_from_filename(line.rsplit()[location_field]) def do_nothing(): - """""" + pass options = { "d": do_nothing, "l": package_or_link, @@ -84,6 +115,8 @@ def pkginfo_from_files_in_dir(directory): package_list.append(pkginfo_from_filename(filename)) return tuple(package_list) + + def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, exclude_file=rsync_blacklist, debug=verbose): """ Generate an exclude list for rsync diff --git a/test/core.db.tar.gz b/test/core.db.tar.gz new file mode 100644 index 0000000..a28ea64 Binary files /dev/null and b/test/core.db.tar.gz differ diff --git a/test/depends b/test/depends new file mode 100644 index 0000000..7ff3ad4 --- /dev/null +++ b/test/depends @@ -0,0 +1,4 @@ +%DEPENDS% +glibc>=2.13 +zlib + diff --git a/test/desc b/test/desc new file mode 100644 index 0000000..abba644 --- /dev/null +++ b/test/desc @@ -0,0 +1,39 @@ +%FILENAME% +binutils-2.21-4-x86_64.pkg.tar.xz + +%NAME% +binutils + +%VERSION% +2.21-4 + +%DESC% +A set of programs to assemble and manipulate binary and object files + +%GROUPS% +base + +%CSIZE% +3412892 + +%ISIZE% +17571840 + +%MD5SUM% +4e666f87c78998f4839f33dc06d2043a + +%URL% +http://www.gnu.org/software/binutils/ + +%LICENSE% +GPL + +%ARCH% +x86_64 + +%BUILDDATE% +1297240369 + +%PACKAGER% +Allan McRae + diff --git a/test/test_filter.py b/test/test_filter.py new file mode 100644 index 0000000..5127b75 --- /dev/null +++ b/test/test_filter.py @@ -0,0 +1,169 @@ +# -*- encoding: utf-8 -*- +""" """ + +__author__ = "Joshua Ismael Haase Hernández " +__version__ = "$Revision: 1.1 $" +__date__ = "$Date: 2011/02/08 $" +__copyright__ = "Copyright (c) 2011 Joshua Ismael Haase Hernández" +__license__ = "GPL3+" + +from repm.config import * +from repm.filter import * +import unittest + +class pkginfo_from_file_KnownValues(unittest.TestCase): + # (filename, name, version, release, arch) + # filename is location + known=( + ("community-testing/os/i686/inputattach-1.24-3-i686.pkg.tar.xz","inputattach","1.24","3","i686"), + ("community-testing/os/i686/ngspice-22-1-i686.pkg.tar.xz","ngspice","22","1","i686"), + ("community-testing/os/i686/tmux-1.4-2-i686.pkg.tar.xz","tmux","1.4","2","i686"), + ("community-testing/os/i686/tor-0.2.1.29-2-i686.pkg.tar.xz","tor","0.2.1.29","2","i686"), + ("../../../pool/community/tor-0.2.1.29-2-i686.pkg.tar.xz","tor","0.2.1.29","2","i686"), + ("community-testing/os/x86_64/inputattach-1.24-3-x86_64.pkg.tar.xz","inputattach","1.24","3","x86_64"), + ("../../../pool/community/inputattach-1.24-3-x86_64.pkg.tar.xz","inputattach","1.24","3","x86_64"), + ("tor-0.2.1.29-2-x86_64.pkg.tar.xz","tor","0.2.1.29","2","x86_64"), + ) + + def generate_results(self, example_tuple, attr): + location, name, version, release, arch = example_tuple + return pkginfo_from_filename(location)[attr], locals()[attr] + + def testReturnPackageObject(self): + for i in self.known: + location, name, version, release, arch = i + self.assertIsInstance(pkginfo_from_filename(location),Package) + + def testNames(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="name") + self.assertEqual(k, v) + + def testVersions(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="version") + self.assertEqual(k, v) + + def testArchs(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="arch") + self.assertEqual(k, v) + + def testReleases(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="release") + self.assertEqual(k, v) + + def testLocations(self): + for i in self.known: + k,v = self.generate_results(example_tuple=i,attr="location") + self.assertEqual(k, v) + +class pkginfo_from_file_BadInput(unittest.TestCase): + bad=("community-testing/os/i686/community-testing.db", + "community-testing/os/i686/community-testing.db.tar.gz", + "community-testing/os/i686/community-testing.db.tar.gz.old", + "community-testing/os/i686/community-testing.files", + "community-testing/os/i686/community-testing.files.tar.gz", + "community-testing/os/x86_64") + + def testBadInput(self): + for i in self.bad: + self.assertRaises(NonValidFile,pkginfo_from_filename,i) + +class pkginfoFromRsyncOutput(unittest.TestCase): + example_package_list=(Package(),Package(),Package()) + example_package_list[0].package_info={ "name" : "alex", + "version" : "2.3.4", + "release" : "1", + "arch" : "i686", + "license" : False, + "location": "community-staging/os/i686/alex-2.3.4-1-i686.pkg.tar.xz", + "depends" : False,} + example_package_list[1].package_info={ "name" : "any2dvd", + "version" : "0.34", + "release" : "4", + "arch" : "any", + "license" : False, + "location": "community/os/any/any2dvd-0.34-4-any.pkg.tar.xz", + "depends" : False,} + example_package_list[2].package_info={ "name" : "gmime22", + "version" : "2.2.26", + "release" : "1", + "arch" : "x86_64", + "license" : False, + "location": "community/os/x86_64/gmime22-2.2.26-1-x86_64.pkg.tar.xz", + "depends" : False,} + + try: + output_file = open("rsync_output_sample") + rsync_out= output_file.read() + output_file.close() + except IOError: print("There is no rsync_output_sample file") + + pkglist = pkginfo_from_rsync_output(rsync_out) + + def testOutputArePackages(self): + if not self.pkglist: + self.fail("not pkglist:" + str(self.pkglist)) + for pkg in self.pkglist: + self.assertIsInstance(pkg,Package) + + def testPackageInfo(self): + if not self.pkglist: + self.fail("Pkglist doesn't exist: " + str(self.pkglist)) + self.assertEqual(self.pkglist,self.example_package_list) + +class generateRsyncBlacklist(unittest.TestCase): + example_package_list=(Package(),Package(),Package()) + example_package_list[0].package_info={ "name" : "alex", + "version" : "2.3.4", + "release" : "1", + "arch" : "i686", + "license" : False, + "location": "community-staging/os/i686/alex-2.3.4-1-i686.pkg.tar.xz", + "depends" : False,} + example_package_list[1].package_info={ "name" : "any2dvd", + "version" : "0.34", + "release" : "4", + "arch" : "any", + "license" : False, + "location": "community/os/any/any2dvd-0.34-4-any.pkg.tar.xz", + "depends" : False,} + example_package_list[2].package_info={ "name" : "gmime22", + "version" : "2.2.26", + "release" : "1", + "arch" : "x86_64", + "license" : False, + "location": "community/os/x86_64/gmime22-2.2.26-1-x86_64.pkg.tar.xz", + "depends" : False,} + + def testListado(self): + self.assertEqual(listado("blacklist_sample"),["alex","gmime22"]) + + def testExcludeFiles(self): + a=generate_exclude_list_from_blacklist(self.example_package_list,listado("blacklist_sample"),debug=True) + b=[self.example_package_list[0]["location"],self.example_package_list[2]["location"]] + self.assertEqual(a,b) + +class pkginfo_from_descKnownValues(unittest.TestCase): + pkgsample=Package() + pkgsample.package_info={"name" : "binutils", + "version" : "2.21", + "release" : "4", + "arch" : "x86_64", + "license" : "GPL", + "location": "binutils-2.21-4-x86_64.pkg.tar.xz", + "depends" : False,} + pkggen=pkginfo_from_desc("desc") + def testPkginfoFromDesc(self): + if self.pkggen is None: + self.fail("return value is None") + self.assertEqual(self.pkgsample,self.pkggen) + +class pkginfo_from_db(unittest.TestCase): + archdb = os.path.join("./workdir") + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_pkginfo_from_file.py b/test/test_pkginfo_from_file.py deleted file mode 100644 index 0d7ede6..0000000 --- a/test/test_pkginfo_from_file.py +++ /dev/null @@ -1,76 +0,0 @@ -#! /usr/bin/python -# -*- encoding: utf-8 -*- -""" """ - -__author__ = "Joshua Ismael Haase Hernández " -__version__ = "$Revision: 1.1 $" -__date__ = "$Date: 2011/02/08 $" -__copyright__ = "Copyright (c) 2011 Joshua Ismael Haase Hernández" -__license__ = "GPL3+" - -from repm.config import * -from repm.filter import * -import unittest - -class KnownValues(unittest.TestCase): - # (filename, name, version, release, arch) - # filename is location - known=( - ("community-testing/os/i686/inputattach-1.24-3-i686.pkg.tar.xz","inputattach","1.24","3","i686"), - ("community-testing/os/i686/ngspice-22-1-i686.pkg.tar.xz","ngspice","22","1","i686"), - ("community-testing/os/i686/tmux-1.4-2-i686.pkg.tar.xz","tmux","1.4","2","i686"), - ("community-testing/os/i686/tor-0.2.1.29-2-i686.pkg.tar.xz","tor","0.2.1.29","2","i686"), - ("../../../pool/community/tor-0.2.1.29-2-i686.pkg.tar.xz","tor","0.2.1.29","2","i686"), - ("community-testing/os/x86_64/inputattach-1.24-3-x86_64.pkg.tar.xz","inputattach","1.24","3","x86_64"), - ("../../../pool/community/inputattach-1.24-3-x86_64.pkg.tar.xz","inputattach","1.24","3","x86_64"), - ("tor-0.2.1.29-2-x86_64.pkg.tar.xz","tor","0.2.1.29","2","x86_64"), - ) - - def generate_results(self, example_tuple, attr): - location, name, version, release, arch = example_tuple - return pkginfo_from_filename(location)[attr], locals()[attr] - - def testReturnPackageObject(self): - for i in self.known: - location, name, version, release, arch = i - self.assertIsInstance(pkginfo_from_filename(location),Package) - - def testNames(self): - for i in self.known: - k,v = self.generate_results(example_tuple=i,attr="name") - self.assertEqual(k, v) - - def testVersions(self): - for i in self.known: - k,v = self.generate_results(example_tuple=i,attr="version") - self.assertEqual(k, v) - - def testArchs(self): - for i in self.known: - k,v = self.generate_results(example_tuple=i,attr="arch") - self.assertEqual(k, v) - - def testReleases(self): - for i in self.known: - k,v = self.generate_results(example_tuple=i,attr="release") - self.assertEqual(k, v) - - def testLocations(self): - for i in self.known: - k,v = self.generate_results(example_tuple=i,attr="location") - self.assertEqual(k, v) - -class BadInput(unittest.TestCase): - bad=("community-testing/os/i686/community-testing.db", - "community-testing/os/i686/community-testing.db.tar.gz", - "community-testing/os/i686/community-testing.db.tar.gz.old", - "community-testing/os/i686/community-testing.files", - "community-testing/os/i686/community-testing.files.tar.gz", - "community-testing/os/x86_64") - - def testBadInput(self): - for i in self.bad: - self.assertRaises(NonValidFile,pkginfo_from_filename,i) - -if __name__ == "__main__": - unittest.main() diff --git a/test/test_pkginfo_from_rsync_output.py b/test/test_pkginfo_from_rsync_output.py deleted file mode 100644 index aca49e8..0000000 --- a/test/test_pkginfo_from_rsync_output.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- encoding: utf-8 -*- -""" """ - -__author__ = "Joshua Ismael Haase Hernández " -__version__ = "$Revision: 1.1 $" -__date__ = "$Date: 2011/02/08 $" -__copyright__ = "Copyright (c) 2011 Joshua Ismael Haase Hernández" -__license__ = "GPL3+" - -from repm.config import * -from repm.filter import * -import unittest - -example_package_list=(Package(),Package(),Package()) -example_package_list[0].package_info={ "name" : "alex", - "version" : "2.3.4", - "release" : "1", - "arch" : "i686", - "license" : False, - "location": "community-staging/os/i686/alex-2.3.4-1-i686.pkg.tar.xz"} -example_package_list[1].package_info={ "name" : "any2dvd", - "version" : "0.34", - "release" : "4", - "arch" : "any", - "license" : False, - "location": "community/os/any/any2dvd-0.34-4-any.pkg.tar.xz"} -example_package_list[2].package_info={ "name" : "gmime22", - "version" : "2.2.26", - "release" : "1", - "arch" : "x86_64", - "license" : False, - "location": "community/os/x86_64/gmime22-2.2.26-1-x86_64.pkg.tar.xz"} - -class pkginfoFromRsyncOutput(unittest.TestCase): - try: - output_file = open("rsync_output_sample") - rsync_out= output_file.read() - output_file.close() - except IOError: print("There is no rsync_output_sample file") - - pkglist = pkginfo_from_rsync_output(rsync_out) - - def testOutputArePackages(self): - if not self.pkglist: - self.fail("not pkglist:" + str(self.pkglist)) - for pkg in self.pkglist: - self.assertIsInstance(pkg,Package) - - def testPackageInfo(self): - if not self.pkglist: - self.fail("Pkglist doesn't exist: " + str(self.pkglist)) - self.assertEqual(self.pkglist,example_package_list) - -class generateRsyncBlacklist(unittest.TestCase): - """ Test Blacklist generation """ - def testListado(self): - self.assertEqual(listado("blacklist_sample"),["alex","gmime22"]) - - def testExcludeFiles(self): - a=generate_exclude_list_from_blacklist(example_package_list,listado("blacklist_sample"),debug=True) - b=[example_package_list[0]["location"],example_package_list[2]["location"]] - self.assertEqual(a,b) - -if __name__ == "__main__": - unittest.main() -- cgit v1.2.3-54-g00ecf From 8c9ff0c97d0802fadc96fe9eacaef7eaa2db5ad2 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Sun, 6 Mar 2011 16:37:36 -0600 Subject: * Using os.path.join for joining path instead of str + str to avoid errors --- pato2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pato2.py b/pato2.py index 21dde16..936e97a 100644 --- a/pato2.py +++ b/pato2.py @@ -137,7 +137,7 @@ def link(repo_,arch_,file_): printf(cmd_ + a) def add_free_repo(verbose_=verbose): - cmd_=home + "/usr/bin/sync-free" + cmd_=os.path.join(home,"/usr/bin/sync-free") printf(cmd_) a=commands.getoutput(cmd_) if verbose_: printf(a) -- cgit v1.2.3-54-g00ecf From 31a0d9e077ed10c5a4b9f461bbde8979f127bdf7 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Sun, 6 Mar 2011 16:43:18 -0600 Subject: * Changed rsync-update-command to not delete (delete made by ftp-dir-cleanup) --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index ada17f0..37bebc0 100644 --- a/config.py +++ b/config.py @@ -46,7 +46,7 @@ rsync_blacklist = docs + "/rsyncBlacklist" # Rsync commands rsync_list_command="rsync -a --no-motd --list-only " -rsync_update_command="rsync -av --delete-after --delay-updates " +rsync_update_command="rsync -av --delay-updates " # Classes and Exceptions class NonValidFile(ValueError): pass -- cgit v1.2.3-54-g00ecf From e2385920015311376c1631a42a1ca8f1c45dae4f Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Sun, 6 Mar 2011 18:08:25 -0600 Subject: * Fixed error that leaked non-free files to repo --- pato2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pato2.py b/pato2.py index 936e97a..336c6fb 100644 --- a/pato2.py +++ b/pato2.py @@ -56,7 +56,7 @@ def sync_all_repo(debug=verbose): cmd=generate_rsync_command(rsync_list_command) rsout=run_rsync(cmd) pkgs=pkginfo_from_rsync_output(rsout) - generate_exclude_list_from_blacklist(pkgs,listado(blacklist)) + generate_exclude_list_from_blacklist(pkgs,listado(blacklist),debug=False) cmd=generate_rsync_command(rsync_update_command,blacklist_file=blacklist) a=run_rsync(cmd) if debug: printf(a) -- cgit v1.2.3-54-g00ecf From 58a67fb771fbbf433fe3ab2dafb9194e6f635f13 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Sun, 6 Mar 2011 18:09:52 -0600 Subject: * Added --delete to rsync-update-command until ftp-dir-cleanup can do delete --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 37bebc0..ada17f0 100644 --- a/config.py +++ b/config.py @@ -46,7 +46,7 @@ rsync_blacklist = docs + "/rsyncBlacklist" # Rsync commands rsync_list_command="rsync -a --no-motd --list-only " -rsync_update_command="rsync -av --delay-updates " +rsync_update_command="rsync -av --delete-after --delay-updates " # Classes and Exceptions class NonValidFile(ValueError): pass -- cgit v1.2.3-54-g00ecf From 125df5a815e0a327739e928cc765ffdcf4bd0aea Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Sun, 6 Mar 2011 18:19:03 -0600 Subject: * Added function for cleanup dir --- pato2.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pato2.py b/pato2.py index 336c6fb..03afebd 100644 --- a/pato2.py +++ b/pato2.py @@ -129,6 +129,12 @@ def remove_from_blacklist(repo_,arch_,info_,blacklist_): a = commands.getoutput(com_) if verbose: printf(a) +def cleanup_nonfree_in_dir(directory,blacklisted_names): + pkgs=pkginfo_from_files_in_dir(directory) + for package in pkgs: + if package["name"] in blacklisted_names: + os.remove(package["location"]) + def link(repo_,arch_,file_): """ Makes a link in the repo for the package """ cmd_="ln -f " + file_ + " " + repodir + "/" + repo_ + "/os/" + arch_ -- cgit v1.2.3-54-g00ecf From 15ed2078e8743f87efcd63ac62cc0bfd5b39dc96 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Sun, 6 Mar 2011 18:34:28 -0600 Subject: * Corrected import glob function --- filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filter.py b/filter.py index 2fe61f0..b6e8105 100644 --- a/filter.py +++ b/filter.py @@ -1,6 +1,6 @@ #! /usr/bin/python #-*- encoding: utf-8 -*- -import glob +from glob import glob from repm.config import * from repm.pato2 import * -- cgit v1.2.3-54-g00ecf From a41f5f44a8f812dfa2aacaf359bb51782d7a1633 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Sun, 6 Mar 2011 19:02:14 -0600 Subject: * Fixed blacklist for rsync_command at sync_all_repo --- pato2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pato2.py b/pato2.py index 03afebd..18ace85 100644 --- a/pato2.py +++ b/pato2.py @@ -57,7 +57,7 @@ def sync_all_repo(debug=verbose): rsout=run_rsync(cmd) pkgs=pkginfo_from_rsync_output(rsout) generate_exclude_list_from_blacklist(pkgs,listado(blacklist),debug=False) - cmd=generate_rsync_command(rsync_update_command,blacklist_file=blacklist) + cmd=generate_rsync_command(rsync_update_command,blacklist_file=rsync_blacklist) a=run_rsync(cmd) if debug: printf(a) -- cgit v1.2.3-54-g00ecf From 0889827f252c9f6c21c1d4f2afc704b9b303e083 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Thu, 10 Mar 2011 13:59:35 -0600 Subject: * Fixed issue 71: pending list ends with newline --- pato2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pato2.py b/pato2.py index 18ace85..27a3962 100644 --- a/pato2.py +++ b/pato2.py @@ -111,7 +111,7 @@ def make_pending(repo_,arch_,info_): printf( pkg_ + " package has no %NAME% attibute " ) if verbose: printf( lista_ ) a=open( pending + "-" + repo_ + ".txt", "w" ).write( - "\n".join([name + ":" + license_ for (name,license_) in lista_]) ) + "\n".join([name + ":" + license_ for (name,license_) in lista_]) + "\n") def remove_from_blacklist(repo_,arch_,info_,blacklist_): """ Check the blacklist and remove packages on the db""" -- cgit v1.2.3-54-g00ecf From 47045b1934932b0695dd301a9c76b9dab1b03023 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 21 Mar 2011 17:30:40 -0600 Subject: * Changed sync_all_repo to adress bug83 --- config.py | 3 ++- filter.py | 3 ++- pato2.py | 6 +++++- test/core.db.tar.gz | Bin 1637 -> 1345 bytes test/test_filter.py | 23 +++++++++++++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index ada17f0..c218ddd 100644 --- a/config.py +++ b/config.py @@ -46,7 +46,8 @@ rsync_blacklist = docs + "/rsyncBlacklist" # Rsync commands rsync_list_command="rsync -a --no-motd --list-only " -rsync_update_command="rsync -av --delete-after --delay-updates " +rsync_update_command="rsync -av --delay-updates --exclude='*.db.tar.{gz|xz}' " +rsync_post_command="rsync -av --delete " # Classes and Exceptions class NonValidFile(ValueError): pass diff --git a/filter.py b/filter.py index b6e8105..668822b 100644 --- a/filter.py +++ b/filter.py @@ -115,7 +115,8 @@ def pkginfo_from_files_in_dir(directory): package_list.append(pkginfo_from_filename(filename)) return tuple(package_list) - +def pkginfo_from_db(path_to_db): + """ """ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, exclude_file=rsync_blacklist, debug=verbose): diff --git a/pato2.py b/pato2.py index 27a3962..0d77d6b 100644 --- a/pato2.py +++ b/pato2.py @@ -59,7 +59,11 @@ def sync_all_repo(debug=verbose): generate_exclude_list_from_blacklist(pkgs,listado(blacklist),debug=False) cmd=generate_rsync_command(rsync_update_command,blacklist_file=rsync_blacklist) a=run_rsync(cmd) - if debug: printf(a) + cmd=generate_rsync_command(rsync_post_command,blacklist_file=rsync_blacklist) + b=run_rsync(cmd) + if debug: + printf(a) + printf(b) def get_from_desc(desc, var,db_tar_file=False): """ Get a var from desc file """ diff --git a/test/core.db.tar.gz b/test/core.db.tar.gz index a28ea64..5eb2081 100644 Binary files a/test/core.db.tar.gz and b/test/core.db.tar.gz differ diff --git a/test/test_filter.py b/test/test_filter.py index 5127b75..1906b87 100644 --- a/test/test_filter.py +++ b/test/test_filter.py @@ -163,7 +163,30 @@ class pkginfo_from_descKnownValues(unittest.TestCase): class pkginfo_from_db(unittest.TestCase): archdb = os.path.join("./workdir") + example_package_list=(Package(),Package(),Package()) + example_package_list[0].package_info={ "name" : "acl", + "version" : "2.2.49", + "release" : "2", + "arch" : "x86_64", + "license" : ("LGPL",), + "location": "acl-2.2.49-2-x86_64.pkg.tar.xz" + "depends" : ("attr>=2.4.41"),} + example_package_list[1].package_info={ "name" : "glibc", + "version" : "2.13", + "release" : "4", + "arch" : "x86_64", + "license" : ("GPL","LGPL"), + "location": "glibc-2.13-4-x86_64.pkg.tar.xz" + "depends" : ("linux-api-headers>=2.6.37","tzdata",),} + example_package_list[2].package_info={ "name" : "", + "version" : "2.2.26", + "release" : "1", + "arch" : "x86_64", + "license" : False, + "location": "" + "depends" : False,} if __name__ == "__main__": unittest.main() + -- cgit v1.2.3-54-g00ecf From fa11d216d567cec3c96c964829c51bd923b493c5 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 21 Mar 2011 17:49:24 -0600 Subject: * Don't update *.abs.tar.* --- config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index c218ddd..c643bb5 100644 --- a/config.py +++ b/config.py @@ -46,8 +46,8 @@ rsync_blacklist = docs + "/rsyncBlacklist" # Rsync commands rsync_list_command="rsync -a --no-motd --list-only " -rsync_update_command="rsync -av --delay-updates --exclude='*.db.tar.{gz|xz}' " -rsync_post_command="rsync -av --delete " +rsync_update_command="rsync -av --delay-updates --exclude=*.{abs|db}.tar.* " +rsync_post_command="rsync -av --delete --exclude=*.abs.tar.* " # Classes and Exceptions class NonValidFile(ValueError): pass -- cgit v1.2.3-54-g00ecf