From 80402467cf38f32373ac14d992d2daee4736ad82 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 00:42:33 -0600 Subject: Added primitive testcase --- test/directory_list | 2 ++ test/link_list | 2 ++ test/package_list | 3 +++ test/test1.py | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 test/directory_list create mode 100644 test/link_list create mode 100644 test/package_list create mode 100644 test/test1.py (limited to 'test') diff --git a/test/directory_list b/test/directory_list new file mode 100644 index 0000000..c0f7f47 --- /dev/null +++ b/test/directory_list @@ -0,0 +1,2 @@ +drwxrwxr-x 15 2010/09/11 11:28:50 community-staging +drwxrwxr-x 30 2010/09/11 11:28:50 community-staging/os \ No newline at end of file diff --git a/test/link_list b/test/link_list new file mode 100644 index 0000000..d015364 --- /dev/null +++ b/test/link_list @@ -0,0 +1,2 @@ +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 +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 \ No newline at end of file diff --git a/test/package_list b/test/package_list new file mode 100644 index 0000000..6ffa1de --- /dev/null +++ b/test/package_list @@ -0,0 +1,3 @@ +-rw-rw-r-- 5846249 2010/11/13 10:54:25 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 +-rw-rw-r-- 982764 2011/02/05 14:38:40 pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz \ No newline at end of file diff --git a/test/test1.py b/test/test1.py new file mode 100644 index 0000000..8e5cd1e --- /dev/null +++ b/test/test1.py @@ -0,0 +1,22 @@ +""" """ + +__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+" + +import repm.filter +import unittest +import commands + +class KnownValues(unittest.TestCase): + + def testDirectoryOutput(self): + """get_file_list_from_rsync_output should ignore directories""" + output=commands.getoutput("cat ./directory_list") + result=get_file_list_from_rsync_output(output) + self.assertEqual(tuple(), result) + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3-54-g00ecf From 0bdbdeaf186a9ab73f596b60748b6ae8a25ebaeb Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 01:18:18 -0600 Subject: Added some testcases. --- test/test1.py | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/test1.py b/test/test1.py index 8e5cd1e..a42e9a5 100644 --- a/test/test1.py +++ b/test/test1.py @@ -6,17 +6,59 @@ __date__ = "$Date: 2011/02/08 $" __copyright__ = "Copyright (c) 2011 Joshua Ismael Haase Hernández" __license__ = "GPL3+" -import repm.filter +from repm.config import * +from repm.filter import * import unittest -import commands 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") + # (output, name, version, arch) + link_list=( + ("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"), + ("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"), + ) + package_list=( + ("-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"), + ("-rw-rw-r-- 982768 2011/02/05 14:38:17 pool/community/acetoneiso2-2.3-2-i686.pkg.tar.xz", + "acetoneiso2","2.3","i686"), + ("-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") + ) + + def generate_results(example_tuple): + a=list() + for output, name, version, arch in example_tuple: + pkg=Packages() + pkg["name"] = name + pkg["version"] = version + pkg["arch"] = arch + a.append(pkg) + return tuple(a) def testDirectoryOutput(self): """get_file_list_from_rsync_output should ignore directories""" - output=commands.getoutput("cat ./directory_list") + rsync_out="\n".join(directory_list) result=get_file_list_from_rsync_output(output) self.assertEqual(tuple(), result) + def testLinkOutput(self): + """get_file_list_from_rsync_output should make a Package Object + from links """ + correct_result=generate_results(link_list) + rsync_out="\n".join([a for a,b,c,d in link_list]) + result=get_file_list_from_rsync_output(rsync_out) + self.assertEqual(correct_result, result) + + + def testPackageOutput(self): + """get_file_list_from_rsync_output should make a Package Object + from links """ + correct_result=generate_results(package_list) + rsync_out="\n".join([a for a,b,c,d in package_list]) + result=get_file_list_from_rsync_output(rsync_out) + self.assertEqual(correct_result, result) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3-54-g00ecf From 3633ea3c4ec93436b2344dba79b06ff00c7ae528 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 01:30:35 -0600 Subject: Corrected first testcases. --- test/test1.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/test1.py b/test/test1.py index a42e9a5..495ba05 100644 --- a/test/test1.py +++ b/test/test1.py @@ -1,3 +1,4 @@ +# -*- encoding: utf-8 -*- """ """ __author__ = "Joshua Ismael Haase Hernández " @@ -27,10 +28,10 @@ class KnownValues(unittest.TestCase): "acetoneiso2","2.3","x86_64") ) - def generate_results(example_tuple): + def generate_results(self, example_tuple): a=list() for output, name, version, arch in example_tuple: - pkg=Packages() + pkg=Package() pkg["name"] = name pkg["version"] = version pkg["arch"] = arch @@ -39,24 +40,23 @@ class KnownValues(unittest.TestCase): def testDirectoryOutput(self): """get_file_list_from_rsync_output should ignore directories""" - rsync_out="\n".join(directory_list) + rsync_out="\n".join(self.directory_list) result=get_file_list_from_rsync_output(output) self.assertEqual(tuple(), result) def testLinkOutput(self): """get_file_list_from_rsync_output should make a Package Object from links """ - correct_result=generate_results(link_list) - rsync_out="\n".join([a for a,b,c,d in link_list]) + correct_result=self.generate_results(self.link_list) + rsync_out="\n".join([a for a,b,c,d in self.link_list]) result=get_file_list_from_rsync_output(rsync_out) self.assertEqual(correct_result, result) - def testPackageOutput(self): """get_file_list_from_rsync_output should make a Package Object from links """ - correct_result=generate_results(package_list) - rsync_out="\n".join([a for a,b,c,d in package_list]) + correct_result=self.generate_results(self.package_list) + rsync_out="\n".join([a for a,b,c,d in self.package_list]) result=get_file_list_from_rsync_output(rsync_out) self.assertEqual(correct_result, result) -- cgit v1.2.3-54-g00ecf From 61f5ecfa6b57f31c14430a7de5099640fcbe3525 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 03:13:39 -0600 Subject: * Updated Package class * Corrected test1.py -> for get_package_list_from_rsync_output --- config.py | 1 + test/test1.py | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/config.py b/config.py index 6dcd348..a7087c4 100644 --- a/config.py +++ b/config.py @@ -49,6 +49,7 @@ class Package: """ An object that has information about a package. """ package_info={ "name" : False, "version" : False, + "release" : False, "arch" : False, "license" : False, "location": False} diff --git a/test/test1.py b/test/test1.py index 495ba05..db87f51 100644 --- a/test/test1.py +++ b/test/test1.py @@ -14,41 +14,43 @@ 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") - # (output, name, version, arch) + # (output, name, version, arch, release, location) link_list=( - ("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"), - ("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"), + ("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"), ) package_list=( ("-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"), + "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"), + "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") + "acetoneiso2","2.3","x86_64","2","pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz") ) def generate_results(self, example_tuple): a=list() - for output, name, version, arch in example_tuple: + for output, name, version, arch, release, location in example_tuple: pkg=Package() pkg["name"] = name pkg["version"] = version pkg["arch"] = arch + pkg["release"] = release + pkg["location"] = location a.append(pkg) return tuple(a) def testDirectoryOutput(self): """get_file_list_from_rsync_output should ignore directories""" rsync_out="\n".join(self.directory_list) - result=get_file_list_from_rsync_output(output) + result=get_file_list_from_rsync_output(rsync_out) self.assertEqual(tuple(), result) def testLinkOutput(self): """get_file_list_from_rsync_output should make a Package Object from links """ correct_result=self.generate_results(self.link_list) - rsync_out="\n".join([a for a,b,c,d in self.link_list]) + rsync_out="\n".join([a for a,b,c,d,e,f in self.link_list]) result=get_file_list_from_rsync_output(rsync_out) self.assertEqual(correct_result, result) @@ -56,7 +58,7 @@ class KnownValues(unittest.TestCase): """get_file_list_from_rsync_output should make a Package Object from links """ correct_result=self.generate_results(self.package_list) - rsync_out="\n".join([a for a,b,c,d in self.package_list]) + rsync_out="\n".join([a for a,b,c,d,e,f in self.package_list]) result=get_file_list_from_rsync_output(rsync_out) self.assertEqual(correct_result, result) -- cgit v1.2.3-54-g00ecf From 8fcf2f7f622de21b580ee808de53cffcc9200639 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 03:41:12 -0600 Subject: Better testcases --- test/test1.py | 60 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/test1.py b/test/test1.py index db87f51..4ec72d3 100644 --- a/test/test1.py +++ b/test/test1.py @@ -14,12 +14,10 @@ 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") - # (output, name, version, arch, release, location) - link_list=( + # (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"), - ) - package_list=( ("-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", @@ -29,16 +27,8 @@ class KnownValues(unittest.TestCase): ) def generate_results(self, example_tuple): - a=list() - for output, name, version, arch, release, location in example_tuple: - pkg=Package() - pkg["name"] = name - pkg["version"] = version - pkg["arch"] = arch - pkg["release"] = release - pkg["location"] = location - a.append(pkg) - return tuple(a) + rsync_out="\n".join([a for a,b,c,d,e,f in example_tuple]) + return get_file_list_from_rsync_output(rsync_out) def testDirectoryOutput(self): """get_file_list_from_rsync_output should ignore directories""" @@ -46,21 +36,35 @@ class KnownValues(unittest.TestCase): result=get_file_list_from_rsync_output(rsync_out) self.assertEqual(tuple(), result) - def testLinkOutput(self): - """get_file_list_from_rsync_output should make a Package Object - from links """ - correct_result=self.generate_results(self.link_list) - rsync_out="\n".join([a for a,b,c,d,e,f in self.link_list]) - result=get_file_list_from_rsync_output(rsync_out) - self.assertEqual(correct_result, result) + def testNames(self): + results=self.generate_results(self.examples) + var =[name for rsync_out, name, version, arch, release, location in self.examples] + for i in range(len(results)): + self.assertEqual(results[i]["name"], var[i]) - def testPackageOutput(self): - """get_file_list_from_rsync_output should make a Package Object - from links """ - correct_result=self.generate_results(self.package_list) - rsync_out="\n".join([a for a,b,c,d,e,f in self.package_list]) - result=get_file_list_from_rsync_output(rsync_out) - self.assertEqual(correct_result, result) + def testVersions(self): + results=self.generate_results(self.examples) + var = [version for rsync_out, name, version, arch, release, location in self.examples] + for i in range(len(results)): + self.assertEqual(results[i]["name"], var[i]) + + def testArchs(self): + results=self.generate_results(self.examples) + var = [arch for rsync_out, name, version, arch, release, location in self.examples] + for i in range(len(results)): + self.assertEqual(results[i]["name"], var[i]) + + def testReleases(self): + results=self.generate_results(self.examples) + var = [release for rsync_out, name, version, arch, release, location in self.examples] + for i in range(len(results)): + self.assertEqual(results[i]["name"], var[i]) + + def testLocations(self): + results=self.generate_results(self.examples) + var = [location for rsync_out, name, version, arch, release, location in self.examples] + for i in range(len(results)): + self.assertEqual(results[i]["name"], var[i]) if __name__ == "__main__": unittest.main() -- cgit v1.2.3-54-g00ecf From 748ef10d89e5898c1ebffb08165f18cd3829119e Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 03:43:07 -0600 Subject: Fixed stupid error. --- test/test1.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/test1.py b/test/test1.py index 4ec72d3..ea488e9 100644 --- a/test/test1.py +++ b/test/test1.py @@ -46,25 +46,25 @@ class KnownValues(unittest.TestCase): results=self.generate_results(self.examples) var = [version for rsync_out, name, version, arch, release, location in self.examples] for i in range(len(results)): - self.assertEqual(results[i]["name"], var[i]) + self.assertEqual(results[i]["version"], var[i]) def testArchs(self): results=self.generate_results(self.examples) var = [arch for rsync_out, name, version, arch, release, location in self.examples] for i in range(len(results)): - self.assertEqual(results[i]["name"], var[i]) + self.assertEqual(results[i]["arch"], var[i]) def testReleases(self): results=self.generate_results(self.examples) var = [release for rsync_out, name, version, arch, release, location in self.examples] for i in range(len(results)): - self.assertEqual(results[i]["name"], var[i]) + self.assertEqual(results[i]["release"], var[i]) def testLocations(self): results=self.generate_results(self.examples) var = [location for rsync_out, name, version, arch, release, location in self.examples] for i in range(len(results)): - self.assertEqual(results[i]["name"], var[i]) + self.assertEqual(results[i]["location"], var[i]) if __name__ == "__main__": unittest.main() -- cgit v1.2.3-54-g00ecf From df79a07c092880259a851d4ebf9febe9a8e19880 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 10:47:55 -0600 Subject: Fixed test1.py --- test/test1.py | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/test1.py b/test/test1.py index ea488e9..61b0651 100644 --- a/test/test1.py +++ b/test/test1.py @@ -26,9 +26,9 @@ class KnownValues(unittest.TestCase): "acetoneiso2","2.3","x86_64","2","pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz") ) - def generate_results(self, example_tuple): - rsync_out="\n".join([a for a,b,c,d,e,f in example_tuple]) - return get_file_list_from_rsync_output(rsync_out) + 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] def testDirectoryOutput(self): """get_file_list_from_rsync_output should ignore directories""" @@ -37,34 +37,29 @@ class KnownValues(unittest.TestCase): self.assertEqual(tuple(), result) def testNames(self): - results=self.generate_results(self.examples) - var =[name for rsync_out, name, version, arch, release, location in self.examples] - for i in range(len(results)): - self.assertEqual(results[i]["name"], var[i]) + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="name") + self.assertEqual(k, v) def testVersions(self): - results=self.generate_results(self.examples) - var = [version for rsync_out, name, version, arch, release, location in self.examples] - for i in range(len(results)): - self.assertEqual(results[i]["version"], var[i]) + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="version") + self.assertEqual(k, v) def testArchs(self): - results=self.generate_results(self.examples) - var = [arch for rsync_out, name, version, arch, release, location in self.examples] - for i in range(len(results)): - self.assertEqual(results[i]["arch"], var[i]) + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="arch") + self.assertEqual(k, v) def testReleases(self): - results=self.generate_results(self.examples) - var = [release for rsync_out, name, version, arch, release, location in self.examples] - for i in range(len(results)): - self.assertEqual(results[i]["release"], var[i]) + for i in self.examples: + k,v = self.generate_results(example_tuple=i,attr="release") + self.assertEqual(k, v) def testLocations(self): - results=self.generate_results(self.examples) - var = [location for rsync_out, name, version, arch, release, location in self.examples] - for i in range(len(results)): - self.assertEqual(results[i]["location"], var[i]) + 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 9c8b6615d537a9c7bb483457cd8a300d7f9c597e Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 10:55:33 -0600 Subject: * Added filter.py * Added __init__.py for test module * Removed unused files --- filter.py | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/__init__.py | 0 test/link_list | 2 -- test/package_list | 3 -- 4 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 filter.py create mode 100644 test/__init__.py delete mode 100644 test/link_list delete mode 100644 test/package_list (limited to 'test') diff --git a/filter.py b/filter.py new file mode 100644 index 0000000..5229e63 --- /dev/null +++ b/filter.py @@ -0,0 +1,90 @@ +#! /usr/bin/python +#-*- encoding: utf-8 -*- +import commands +import os +import re +from repm.config import * +from repm.pato2 import * + +rsync_list_command="rsync -av --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 Must be a dir + blacklist_file -> False or str 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. + + Parameters: + ---------- + rsync_output -> str containing output from rsync + + Returns: + ---------- + package_list -> tuple of 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 + + options = { "d": directory, + "l": package_or_link, + "-": package_or_link} + + for line in rsync_output.split("\n"): + if ".pkg.tar.gz" or ".pkg.tar.xz" in line: + pkginfo=options[line[0]](line) + if pkginfo: + a.append(pkginfo) + + return tuple(a) + diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/link_list b/test/link_list deleted file mode 100644 index d015364..0000000 --- a/test/link_list +++ /dev/null @@ -1,2 +0,0 @@ -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 -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 \ No newline at end of file diff --git a/test/package_list b/test/package_list deleted file mode 100644 index 6ffa1de..0000000 --- a/test/package_list +++ /dev/null @@ -1,3 +0,0 @@ --rw-rw-r-- 5846249 2010/11/13 10:54:25 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 --rw-rw-r-- 982764 2011/02/05 14:38:40 pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz \ No newline at end of file -- cgit v1.2.3-54-g00ecf From d9ac9d17a92607b09fb9afa91ff96aeae38dbdf3 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 11:55:25 -0600 Subject: Delete unneeded file. --- test/directory_list | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 test/directory_list (limited to 'test') diff --git a/test/directory_list b/test/directory_list deleted file mode 100644 index c0f7f47..0000000 --- a/test/directory_list +++ /dev/null @@ -1,2 +0,0 @@ -drwxrwxr-x 15 2010/09/11 11:28:50 community-staging -drwxrwxr-x 30 2010/09/11 11:28:50 community-staging/os \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 072787627a2339c3d5aca541086c2e4545bbad8d Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Tue, 8 Feb 2011 14:06:58 -0600 Subject: * Changed variable name in filter.py * Added example in test1.py --- filter.py | 15 +++++++-------- test/test1.py | 5 +++-- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/filter.py b/filter.py index 817a228..ffc0965 100644 --- a/filter.py +++ b/filter.py @@ -89,20 +89,19 @@ def get_file_list_from_rsync_output(rsync_output): return tuple(a) def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, - blacklist_file=rsync_blacklist, debug=verbose): + exclude_file=rsync_blacklist, debug=verbose): """ Generate an exclude list for rsync Parameters: ---------- - package_iterable -> list or tuple Contains Package objects - blacklisted_names-> list or tuple Contains blacklisted names - blacklist_file -> str Path to file - debug -> bool + package_iterable -> list or tuple Contains Package objects + blacklisted_names-> list or tuple Contains blacklisted names + exclude_file -> str Path to file + debug -> bool If True, file list gets logged Output: ---------- - if debug == False -> None - if debug == True -> blacklist """ + None """ a=list() for package in packages_iterable: @@ -115,7 +114,7 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, printf(a) try: - fsock = open(blacklist_file,"w") + fsock = open(exclude_file,"w") try: fsock.write("\n".join(a)) finally: diff --git a/test/test1.py b/test/test1.py index 61b0651..13b5660 100644 --- a/test/test1.py +++ b/test/test1.py @@ -13,7 +13,8 @@ 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") + "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"), @@ -60,6 +61,6 @@ class KnownValues(unittest.TestCase): 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 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(-) (limited to 'test') 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(-) (limited to 'test') 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 (limited to 'test') 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 (limited to 'test') 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 (limited to 'test') 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 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 (limited to 'test') 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(-) (limited to 'test') 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 (limited to 'test') 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 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 (limited to 'test') 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 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(-) (limited to 'test') 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 3fb5f8efef231dd7784be880934cd106603ab6f1 Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Mon, 11 Apr 2011 01:09:25 -0500 Subject: bash-port ready for testing. --- clean_repo.py | 45 +++++++++++ config.py | 10 ++- config.sh | 17 +++-- filter.py | 68 +++++++++++++---- get_license.sh | 10 +-- main.sh | 20 +++-- mkpending.py | 45 +++++++++++ pato2.py | 209 ++++------------------------------------------------ test/test_filter.py | 6 +- 9 files changed, 198 insertions(+), 232 deletions(-) create mode 100644 clean_repo.py create mode 100644 mkpending.py (limited to 'test') diff --git a/clean_repo.py b/clean_repo.py new file mode 100644 index 0000000..29d446d --- /dev/null +++ b/clean_repo.py @@ -0,0 +1,45 @@ +#! /usr/bin/python +#-*- encoding: utf-8 -*- +from repm.filter import * +import argparse + +def remove_from_blacklist(path_to_db, blacklisted_names, + debug=config["debug"]): + """ Check the blacklist and remove packages on the db""" + + pkgs=[pkg for pkg in pkginfo_from_db(path_to_db) if + pkg["name"] in blacklisted_names] + if pkgs: + lista=" ".join(pkgs) + cmd = "repo-remove " + path_to_db + " " + lista + printf(cmd) + a = check_output(cmd) + if debug: + printf(a) + return pkgs, cmd + +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"]) + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Clean a repo db and packages") + parser.add_argument("-b", "--database", type=str, + help="dabatase to clean") + parser.add_argument("-d", "--directory", type=str, + help="directory to clean") + args=parser.parse_args() + + if args.directory: + cleanup_nonfree_in_dir(args.database, listado(config["blacklist"])) + + if args.database: + pkgs=pkginfo_from_db(args.database) + remove_from_blacklist(args.database, pkgs, + tuple(listado(config["blacklist"]) + + listado(config["pending"]))) + if not args.directory and not args.database: + parser.print_help() diff --git a/config.py b/config.py index 8cf07a2..24ecfaf 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,4 @@ -#!/usr/bin/pythonn +#!/usr/bin/python # -*- coding: utf-8 -*- try: from subprocess import check_output @@ -7,22 +7,24 @@ except(ImportError): import os stringvars=("mirror", "mirrorpath", "logname", "tempdir", "docs_dir", - "repodir", "rsync_blacklist") + "repodir", "rsync_blacklist") listvars=("repo_list", "dir_list", "arch_list", "other",) boolvars=("output", "debug",) config=dict() -def exit_if_none: +def exit_if_none(var): if os.environ.get(var) is None: exit("%s is not defined" % var) for var in stringvars: exit_if_none(var) - config[var]=os.environ.get(var) + config[var]=os.environ.get(var) + for var in listvars: exit_if_none(var) config[var]=tuple(os.environ.get(var).split(":")) + for var in boolvars: exit_if_none(var) if os.environ.get(var) == "True": diff --git a/config.sh b/config.sh index 60bd4ea..741dee4 100755 --- a/config.sh +++ b/config.sh @@ -1,22 +1,25 @@ #!/bin/sh # -*- coding: utf-8 -*- - # Mirror options mirror="mirrors.eu.kernel.org" mirrorpath="::mirrors/archlinux" -# Directories and files - +# Directories ## Optionals paraboladir=~/parabolagnulinux.org logtime=$(date -u +%Y%m%d-%H:%M) - ## Must be defined logname=${paraboladir}/${logtime}-repo-maintainer.log tempdir=~/tmp/ docs_dir=${paraboladir}/docs repodir=${paraboladir}/repo +# End Directories + +# Files +blacklist=${docs_dir}/blacklist.txt +whitelist=${docs_dir}/whitelist.txt +pending=${docs_dir}/pending rsync_blacklist=${docs_dir}/rsyncBlacklist # Repos, arches, and dirs for repo @@ -33,16 +36,18 @@ debug="False" 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} \ mirrorpath=${mirrorpath} \ logname=${logname} \ tempdir=${tempdir} \ - rsync_blacklist=${rsync_blacklist} \ docs_dir=${docs_dir} \ repodir=${repodir} \ + blacklist=${blacklist} \ + whitelist=${whitelist} \ + pending=${pending} \ + rsync_blacklist=${rsync_blacklist} \ repo_list=${repo_list} \ dir_list=${dir_list} \ arch_list=${arch_list} \ diff --git a/filter.py b/filter.py index 668822b..1a0fa6f 100644 --- a/filter.py +++ b/filter.py @@ -4,6 +4,13 @@ from glob import glob from repm.config import * from repm.pato2 import * +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] + def pkginfo_from_filename(filename): """ Generates a Package object with info from a filename, filename can be relative or absolute @@ -116,10 +123,48 @@ 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: + ---------- + None """ + package_list=list() + + if not os.path.isfile(path_to_db): + raise NonValidFile(path_to_db + "is not a file") + + check_output("mkdir -p " + archdb) + + try: + db_open_tar = tarfile.open(db_tar_file, 'r:gz') + except tarfile.ReadError: + printf("No valid db_file %s or not readable" % 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"): + package_list.append(pkginfo_from_desc( + os.path.join(dir_,"desc"))) + check_output("rm -r %s/*" % archdb) + if verbose_: + printf(package_list) + return package_list + +def generate_exclude_list_from_blacklist(packages_iterable, + blacklisted_names, + exclude_file=config["rsync_blacklist"], + debug=config["debug"]): """ Generate an exclude list for rsync Parameters: @@ -132,16 +177,12 @@ 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 + return pkgs try: fsock = open(exclude_file,"w") try: @@ -149,9 +190,10 @@ def generate_exclude_list_from_blacklist(packages_iterable, blacklisted_names, finally: fsock.close() except IOError: - printf("%s wasnt written" % blacklist_file) + printf("%s wasnt written" % exclude_file) 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)) diff --git a/get_license.sh b/get_license.sh index a7241a1..0da58cb 100755 --- a/get_license.sh +++ b/get_license.sh @@ -31,12 +31,12 @@ rm -rf $dir/* tempdir=$(mktemp -d) cd $tempdir -a=($(cut -d: -f1 $docs/pending*.txt)) -echo ${a[@]} +pending=($(cut -d: -f1 $docs/pending*.txt)) +echo ${pending[@]} -for x in ${a[@]}; do - b=( $(ls $repo/*/os/*/$x*) ) - for y in ${b[@]}; do +for pkg in ${pending[@]}; do + pkg_in_repo=( $(ls ${repo}/*/os/*/${pkg}*) ) + for y in ${pkg_in_repo[@]}; do echo "chmod +r $y" chmod +r $y echo "tar -xf $y usr/share/licenses" diff --git a/main.sh b/main.sh index 2d59094..1a2c6c4 100644 --- a/main.sh +++ b/main.sh @@ -23,13 +23,17 @@ ${rsync_update_command} --exclude-from=${rsync_blacklist} \ ${mirror}${mirropath}/{$(echo ${repo_list} | tr ':' ',')} ${repodir} msg "Syncing each repo and cleaning" +msg2 "Remove pending files" +stdnull "rm -rf ${pending}*" for repo in $(echo ${repo_list} | tr ':' ' '); do - msg2 "Syncing ${repo}" - ${rsync_post_command} --exclude-from=${rsync_blacklist} \ - ${mirror}${mirropath}/${repo} ${repodir}/${repo} - msg2 "Cleaning ${repo}" - clean-repo.py -d ${repodir}/${repo} \ - -b ${repodir}/${repo}/${repo}.db.tar.gz - msg2 "Making pending list for ${repo}" - run_python_cmd "mkpending.py -r ${repo} -d ${repodir}/${repo}" + for arch in $(echo ${arch_list} | tr ':' ' '); do + msg2 "Syncing ${repo} ${arch}" + ${rsync_post_command} --exclude-from=${rsync_blacklist} \ + ${mirror}${mirropath}/${repo} ${repodir}/${repo} + msg2 "Making pending list for ${repo} ${arch}" + run_python_cmd "mkpending.py -r ${repo} -b ${repodir}/${repo}/os/${arch}" + msg2 "Cleaning ${repo} ${arch}" + run_python_cmd "clean-repo.py -b ${repodir}/${repo}/os/${arch}/${repo}.db.tar.gz -d ${repodir}/${repo}/os/${arch}/" + get_license.sh + done done diff --git a/mkpending.py b/mkpending.py new file mode 100644 index 0000000..43a5fb2 --- /dev/null +++ b/mkpending.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +from repm.filter import * + +def make_pending(path_to_db): + """ Determine wich packages are pending for license auditing.""" + packages_iterable=pkginfo_from_db(path_to_db) + search = tuple(listado(config["blacklist"]) + + listado(config["whitelist"])) + + pkgs=[pkg for pkg in packages_iterable + if "custom" in pkg["license"] + and pkg["name"] not in search] + return pkgs + +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 + help="database to check") + parser.add_argument("-r", "--repo", type=str, required=True + help="repo of database") + args=parser.parse_args() + + if args.database and args.repo: + pkgs=make_pending(args.database) + write_pending(pkgs, args.repo) + else: + parser.print_help() diff --git a/pato2.py b/pato2.py index 0d77d6b..4cdb536 100644 --- a/pato2.py +++ b/pato2.py @@ -27,159 +27,23 @@ from repm.config import * from repm.filter import * import tarfile -from glob import glob from os.path import isdir, isfile -def printf(text,output_=output): +def printf(text,output=config["output"]): """Guarda el texto en la variable log y puede imprimir en pantalla.""" - log_file = open(logname, 'a') + log_file = open(config["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] - -def db(repo_,arch_): - """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 ) ) - -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),debug=False) - cmd=generate_rsync_command(rsync_update_command,blacklist_file=rsync_blacklist) - a=run_rsync(cmd) - 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 """ - 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) - -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_]) + "\n") - -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) - -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_ - a=commands.getoutput(cmd_) - if verbose: - printf(cmd_ + a) - -def add_free_repo(verbose_=verbose): - cmd_=os.path.join(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_) - for dir_ in other: - for file_ in glob(freedir + repo_ + "/os/" + dir_ + "/*.pkg.tar.*"): - lista_.append(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) - -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. + if output_: + print (str(text) + "\n") + +def generate_rsync_command(base_command, + dir_list=(config["repo_list"] + + config["dir_list"]), + destdir=config["repodir"], + source=config["mirror"] +config["mirrorpath"]): + """ Generates an rsync command for executing + it by combining all parameters. Parameters: ---------- @@ -192,57 +56,16 @@ def generate_rsync_command(base_command, dir_list=(repo_list + dir_list), destdi 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) + "}" + return " ".join((base_command, os.path.join(source, dir_list), + destdir)) - if 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): +def run_rsync(command,debug=config["debug"]): """ Runs rsync and gets returns it's output """ if debug: printf("rsync_command: " + command) - 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()) - + return check_output(command) diff --git a/test/test_filter.py b/test/test_filter.py index 1906b87..5601d57 100644 --- a/test/test_filter.py +++ b/test/test_filter.py @@ -169,21 +169,21 @@ class pkginfo_from_db(unittest.TestCase): "release" : "2", "arch" : "x86_64", "license" : ("LGPL",), - "location": "acl-2.2.49-2-x86_64.pkg.tar.xz" + "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" + "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": "" + "location": "", "depends" : False,} -- cgit v1.2.3-54-g00ecf From deab65fad4ced009fb31f7033b1db8ef0af78aee Mon Sep 17 00:00:00 2001 From: Joshua Ismael Haase Hernández Date: Fri, 15 Apr 2011 04:53:27 -0500 Subject: Python parts ready for bash usage in python 2 and 3 --- clean_repo.py | 78 ++++++++++++++++++++++++++++++----------------------- config.py | 65 +++++++++----------------------------------- filter.py | 48 ++++++++++++++++++++------------- pato2.py | 63 ------------------------------------------- test/test_filter.py | 3 ++- 5 files changed, 88 insertions(+), 169 deletions(-) delete mode 100644 pato2.py (limited to 'test') diff --git a/clean_repo.py b/clean_repo.py index eccfd01..5423c4d 100755 --- a/clean_repo.py +++ b/clean_repo.py @@ -3,21 +3,16 @@ from repm.filter import * import argparse -def mkpending(path_to_db, repo, prefix=config["pending"]): +def mkpending(packages_iterable, pending_file, blacklisted_names, + whitelisted_names): """ Determine wich packages are pending for license auditing.""" - if "~" in path_to_db: - path_to_db=(os.path.expanduser(path_to_db)) - - search = tuple(listado(config["blacklist"]) + - listado(config["whitelist"])) + search = tuple(blacklisted_names + + whitelisted_names) - pkgs=list(pkginfo_from_db(path_to_db)) - - filename=prefix + "-" + repo + ".txt" try: - fsock=open(filename, "rw") - pkgs=[pkg for pkg in pkginfo_from_db(path_to_db) - if pkg["name"] not in listado(filename)] + fsock=open(pending_file, "r") + pkgs=[pkg for pkg in packages_iterable + if pkg["name"] not in listado(pending_file)] for line in fsock.readlines(): if line: pkg=Package() @@ -26,16 +21,16 @@ def mkpending(path_to_db, repo, prefix=config["pending"]): pkgs.append(pkg) pkgs=[pkg for pkg in pkgs if pkg["name"] not in search and "custom" in pkg["license"]] + fsock=open(pending_file, "w") fsock.write("\n".join([pkg["name"] + ":" + pkg["license"] for pkg in pkgs]) + "\n") except(IOError): - raise NonValidFile("Can't read or write %s" % filename) + raise NonValidFile("Can't read or write %s" % pending_file) finally: fsock.close() return pkgs -def remove_from_blacklist(path_to_db, blacklisted_names, - debug=config["debug"]): +def remove_from_blacklist(path_to_db, blacklisted_names): """ Check the blacklist and remove packages on the db""" if "~" in path_to_db: path_to_db=(os.path.expanduser(path_to_db)) @@ -47,9 +42,7 @@ def remove_from_blacklist(path_to_db, blacklisted_names, cmd = "repo-remove " + path_to_db + " " + lista printf(cmd) a = check_output(cmd) - if debug: - printf(a) - return pkgs, cmd + return pkgs def cleanup_nonfree_in_dir(directory, blacklisted_names): if "~" in directory: @@ -61,25 +54,42 @@ def cleanup_nonfree_in_dir(directory, blacklisted_names): if __name__ == "__main__": parser = argparse.ArgumentParser( - description="Clean a repo db and packages") - parser.add_argument("-b", "--database", type=str, - help="dabatase to clean") - parser.add_argument("-d", "--directory", type=str, - help="directory to clean") + prog="clean_repo", + description="Clean a repo db and packages",) + + parser.add_argument("-k", "--blacklist-file", type=str, + help="File containing blacklisted names", + required=True,) + + group_dir=parser.add_argument_group("Clean non-free packages in dir") + group_dir.add_argument("-d", "--directory", type=str, + help="directory to clean",) + + group_db=parser.add_argument_group("Clean non-free packages in db", + "All arguments need to be specified") + group_db.add_argument("-b", "--database", type=str, + help="dabatase to clean") + group_db.add_argument("-p", "--pending-file", type=str, + help="File in which to write pending list") + group_db.add_argument("-w", "--whitelist-file", type=str, + help="File containing whitelisted names") + args=parser.parse_args() + if not args.directory and not args.database: + parser.print_help() + elif not args.pending_file or not args.whitelist_file \ + and args.database: + parser.print_help() + else: + blacklisted=listado(args.blacklist_file) + if args.database: - repo=os.path.basename(args.database).split(".")[0] + whitelisted=listado(args.whitelist_file) pkgs=pkginfo_from_db(args.database) - remove_from_blacklist(args.database, pkgs, - tuple(listado(config["blacklist"]) + - listado(config["pending"] + - "-" + repo + ".txt"))) - mkpending(args.database, args.repo) + remove_from_blacklist(args.database, blacklisted) + mkpending(pkgs, args.pending_file, + blacklisted, whitelisted) if args.directory: - cleanup_nonfree_in_dir(args.directory, - listado(config["blacklist"])) - - if not args.directory and not args.database: - parser.print_help() + cleanup_nonfree_in_dir(args.directory, blacklisted) diff --git a/config.py b/config.py index 8b48c66..4e218a5 100755 --- a/config.py +++ b/config.py @@ -9,61 +9,26 @@ except(ImportError): return getoutput(cmd) import os -stringvars=("mirror", "mirrorpath", "logname", "tempdir", "archdb", - "repodir", "blacklist", "whitelist", "pending", - "rsync_blacklist",) -listvars=("repo_list", "dir_list", "arch_list", "other",) -boolvars=("output", "debug",) - -config=dict() - -def exit_if_none(var): - if os.environ.get(var) is None: - exit("%s is not defined" % var) - -for var in stringvars: - exit_if_none(var) - config[var]=os.environ.get(var) - -for var in listvars: - exit_if_none(var) - config[var]=tuple(os.environ.get(var).split(":")) - -for var in boolvars: - exit_if_none(var) - if os.environ.get(var) == "True": - config[var]=True - elif os.environ.get(var) =="False": - config[var]=False - else: - print('%s is not True or False' % var) # Rsync commands -rsync_list_command="rsync -a --no-motd --list-only " -def printf(text,output=config["output"]): +def printf(text, logfile=False): """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") + print (str(text) + "\n") + if logfile: + try: + log = open(logfile, 'a') + log.write("\n" + str(text) + "\n") + except: + print("Can't open %s" % logfile) + finally: + log.close() -del exit_if_none # Classes and Exceptions -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 NonValidFile(ValueError): pass +class NonValidDir(ValueError): pass +class NonValidCommand(ValueError): pass class Package: """ An object that has information about a package. """ @@ -101,7 +66,3 @@ class Package: return False else: return True - -if __name__=="__main__": - for key in config.keys(): - print("%s : %s" % (key,config[key])) diff --git a/filter.py b/filter.py index 4b9603d..add0235 100755 --- a/filter.py +++ b/filter.py @@ -2,7 +2,7 @@ #-*- encoding: utf-8 -*- from glob import glob from repm.config import * -from repm.pato2 import * +import tarfile def listado(filename,start=0,end=None): """Obtiene una lista de paquetes de un archivo.""" @@ -28,7 +28,7 @@ def pkginfo_from_filename(filename): ---------- pkg -> Package object""" if ".pkg.tar." not in filename: - raise NonValidFile + raise NonValidFile("File is not a pacman package") pkg = Package() pkg["location"] = filename fileattrs = os.path.basename(filename).split("-") @@ -140,19 +140,18 @@ def pkginfo_from_db(path_to_db): desc_files=[desc for desc in dbsock.getnames() if "/desc" in desc] for name in desc_files: - desc=dbsock.extractfile(name) - package_list.append(pkginfo_from_desc(desc.read())) + desc=dbsock.extractfile(name).read().decode("UTF-8") + package_list.append(pkginfo_from_desc(desc)) except tarfile.ReadError: raise NonValidFile("No valid db_file %s or not readable" % path_to_db) - return(tuple()) finally: dbsock.close() return package_list def rsyncBlacklist_from_blacklist(packages_iterable, blacklisted_names, - exclude_file=config["rsync_blacklist"]): + exclude_file): """ Generate an exclude list for rsync Parameters: @@ -168,20 +167,31 @@ def rsyncBlacklist_from_blacklist(packages_iterable, pkgs=[pkg["location"] for pkg in packages_iterable if isinstance(pkg, Package) and pkg["name"] in blacklisted_names] - - try: - fsock = open(exclude_file,"w") - fsock.write("\n".join(pkgs) + "\n") - except IOError: - printf("%s wasnt written" % exclude_file) - exit(1) - finally: - fsock.close() + if exclude_file: + try: + fsock = open(exclude_file,"w") + fsock.write("\n".join(pkgs) + "\n") + except IOError: + printf("%s wasnt written" % exclude_file) + exit(1) + finally: + fsock.close() return pkgs if __name__ == "__main__": - cmd=generate_rsync_command(rsync_list_command) - a=run_rsync(cmd) - packages=pkginfo_from_rsync_output(a) - rsyncBlaclist_from_blacklist(packages,listado(blacklist)) + import argparse + parser=argparse.ArgumentParser() + parser.add_argument("-r", "--rsync-exclude-file", type=str, + help="File in which to generate exclude list", + required=True,) + parser.add_argument("-k", "--blacklist-file", type=str, + help="File containing blacklisted names", + required=True,) + parser.add_argument("-c", "--rsync-command", type=str, + help="This command will be run to get a pkg list") + args=parser.parse_args() + rsout=check_output(args.rsync_command) + packages=pkginfo_from_rsync_output(rsout) + rsyncBlaclist_from_blacklist(packages, listado(args.blacklist_file), + args.rsync_exclude_file) diff --git a/pato2.py b/pato2.py deleted file mode 100644 index 6daa8b8..0000000 --- a/pato2.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -""" - parabola.py - Copyright 2009 Rafik Mas'ad - Copyright 2010 Joshua Ismael Haase Hernández - - ---------- GNU General Public License 3 ---------- - - This file is part of Parabola. - - Parabola is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Parabola is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Parabola. If not, see . - - -""" -from repm.config import * -from repm.filter import * -import tarfile -from os.path import isdir, isfile - -def generate_rsync_command(base_command, - dir_list=(config["repo_list"] + - config["dir_list"]), - destdir=config["repodir"], - source=config["mirror"] +config["mirrorpath"]): - """ 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 """ - if not os.path.isdir(destdir): - print(destdir + " is not a directory") - raise NonValidDir - - dir_list="{" + ",".join(dir_list) + "}" - return " ".join((base_command, os.path.join(source, dir_list), - destdir)) - -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.split()) diff --git a/test/test_filter.py b/test/test_filter.py index b6d5766..d8006f9 100644 --- a/test/test_filter.py +++ b/test/test_filter.py @@ -143,7 +143,8 @@ class generateRsyncBlacklist(unittest.TestCase): def testExcludeFiles(self): a=rsyncBlacklist_from_blacklist(self.example_package_list, - listado("blacklist_sample")) + listado("blacklist_sample"), + False) b=[self.example_package_list[0]["location"],self.example_package_list[2]["location"]] self.assertEqual(a,b) -- cgit v1.2.3-54-g00ecf