From: biao716.wang Date: Fri, 4 Nov 2022 12:09:29 +0000 (+0900) Subject: port code from python2.x to python3.x X-Git-Tag: upstream/0.17.4^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28c0ff61456926ad670e2962f9ea08d922f5e95a;p=services%2Fcreaterepo_c.git port code from python2.x to python3.x Disable binding to python Change-Id: I1c83b716ffcdcf64464da2fedeab913ac4137589 Signed-off-by: biao716.wang --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bf560fb..a89a1fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ IF (ENABLE_DRPM) ENDIF (ENABLE_DRPM) # option to enable/disable python support -OPTION (ENABLE_PYTHON "Enable python support?" ON) +OPTION (ENABLE_PYTHON "Enable python support?" OFF) # Threaded XZ Compression # Note: This option is disabled by default, because Createrepo_c diff --git a/acceptance_tests/tests/base.py b/acceptance_tests/tests/base.py index 3bd91d5..bce2162 100644 --- a/acceptance_tests/tests/base.py +++ b/acceptance_tests/tests/base.py @@ -329,7 +329,7 @@ class BaseTestCase(unittest.TestCase): def assert_repo_files(self, repo, file_patterns, additional_files_allowed=True): """Assert that files (defined by re) are in the repo """ - compiled_patterns = map(re.compile, file_patterns) + compiled_patterns = list(map(re.compile, file_patterns)) fns = os.listdir(os.path.join(repo, "repodata/")) used_patterns = [] for pattern in compiled_patterns: @@ -352,7 +352,7 @@ class BaseTestCase(unittest.TestCase): self.assertTrue(os.path.isdir(a)) self.assertTrue(os.path.isdir(b)) - _, logfn = tempfile.mkstemp(prefix="out_dircmp_%s_" % long(time.time()), dir=self.tdir) + _, logfn = tempfile.mkstemp(prefix="out_dircmp_%s_" % int(time.time()), dir=self.tdir) logfile = open(logfn, "w") logfile.write("A: %s\n" % a) logfile.write("B: %s\n" % b) diff --git a/debian/control b/debian/control index cc2cd51..c5a068d 100644 --- a/debian/control +++ b/debian/control @@ -2,19 +2,19 @@ Source: createrepo-c Section: devel Priority: extra Maintainer: Jian-feng Ding -Build-Depends: debhelper (>= 7.0.15), cdbs, libpython2.7, python-dev, dh-python, python-docutils, cmake, dpatch, libbz2-dev, librpm-dev, liblzma-dev, libcurl3 | libcurl4, libcurl4-openssl-dev, libmagic-dev, libexpat1, doxygen, pkg-config, libglib2.0-dev, libssl-dev +Build-Depends: debhelper (>= 7.0.15), cdbs, libpython3-dev, python3-dev, libpython3-all-dev, dh-python, python3-docutils, cmake, dpatch, libbz2-dev, librpm-dev, liblzma-dev, libcurl3 | libcurl4, libcurl4-openssl-dev, libmagic-dev, libexpat1, doxygen, pkg-config, libglib2.0-dev, libssl-dev Standards-Version: 0.10.4 Homepage: http://www.tizen.org Package: createrepo-c Architecture: i386 amd64 -Depends: ${python:Depends}, +Depends: ${python3:Depends}, rpm, - python-rpm, - python-urlgrabber, + python3-rpm, + python3-urlgrabber, cpio, bzip2, - libpython2.7, + libpython3-dev, libcurl3 | libcurl4, libxml2, gzip, @@ -26,10 +26,10 @@ Description: image creator for Linux distributions Package: createrepo-c-devel Architecture: i386 amd64 -Depends: ${python:Depends}, +Depends: ${python3:Depends}, rpm, - python-rpm, - python-urlgrabber, + python3-rpm, + python3-urlgrabber, cpio, bzip2, libcreaterepo-c, @@ -39,7 +39,7 @@ Description: image creator for Linux distributions Package: libcreaterepo-c Architecture: i386 amd64 -Depends: ${python:Depends}, +Depends: ${python3:Depends}, cpio, bzip2, libcurl3 | libcurl4, diff --git a/debian/createrepo-c-devel.install b/debian/createrepo-c-devel.install index a083e81..40bb3ae 100644 --- a/debian/createrepo-c-devel.install +++ b/debian/createrepo-c-devel.install @@ -1,5 +1,4 @@ usr/include/createrepo_c /usr/include/ usr/lib/libcreaterepo_c.so /usr/lib/ usr/lib/pkgconfig/createrepo_c.pc /usr/lib/pkgconfig/ -usr/lib/python2.7/dist-packages/createrepo_c /usr/lib/python2.7/dist-packages/ diff --git a/debian/rules b/debian/rules index 259d2a0..2b57755 100755 --- a/debian/rules +++ b/debian/rules @@ -25,7 +25,8 @@ install: build # Installing package make DESTDIR=$(CURDIR) sysconfdir=$(CURDIR)/etc install - if [ -e usr/lib64 ]; then cp -arf usr/lib64/* usr/lib/; fi + mkdir -p $(CURDIR)/usr/lib + if [ -e usr/lib64 ]; then cp -arf usr/lib64/* $(CURDIR)/usr/lib/; fi #To compatible with createrepo for i in createrepo mergerepo modifyrepo sqliterepo;do \ ln -s /usr/bin/$$i\_c $(CURDIR)/usr/bin/$$i; \ @@ -44,7 +45,6 @@ binary-indep: build install dh_strip dh_compress dh_fixperms - dh_python2 dh_installdeb # dh_shlibdeps -l/$(CURDIR)/usr/lib dh_gencontrol diff --git a/doc/python/conf.py b/doc/python/conf.py index 2ca3a9f..b5eea45 100644 --- a/doc/python/conf.py +++ b/doc/python/conf.py @@ -41,8 +41,8 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'createrepo_c' -copyright = u'2013, Red Hat' +project = 'createrepo_c' +copyright = '2013, Red Hat' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -184,8 +184,8 @@ latex_elements = { # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'createrepo_c.tex', u'createrepo_c Documentation', - u'Tomas Mlcoch', 'manual'), + ('index', 'createrepo_c.tex', 'createrepo_c Documentation', + 'Tomas Mlcoch', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -214,8 +214,8 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'createrepo_c', u'createrepo_c Documentation', - [u'Tomas Mlcoch'], 1) + ('index', 'createrepo_c', 'createrepo_c Documentation', + ['Tomas Mlcoch'], 1) ] # If true, show URL addresses after external links. @@ -228,8 +228,8 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'createrepo_c', u'createrepo_c Documentation', - u'Tomas Mlcoch', 'createrepo_c', 'One line description of project.', + ('index', 'createrepo_c', 'createrepo_c Documentation', + 'Tomas Mlcoch', 'createrepo_c', 'One line description of project.', 'Miscellaneous'), ] diff --git a/examples/python/contenthash_calculation.py b/examples/python/contenthash_calculation.py index b39b2d1..d6bc66c 100755 --- a/examples/python/contenthash_calculation.py +++ b/examples/python/contenthash_calculation.py @@ -48,4 +48,4 @@ if __name__ == "__main__": path = REPO_PATH if len(sys.argv) == 2: path = sys.argv[1] - print (calculate_contenthash(path)) + print((calculate_contenthash(path))) diff --git a/examples/python/repodata_parsing.py b/examples/python/repodata_parsing.py index 6df99a1..98b716f 100755 --- a/examples/python/repodata_parsing.py +++ b/examples/python/repodata_parsing.py @@ -11,59 +11,59 @@ REPO_PATH = "repo/" def print_package_info(pkg): def print_pcors(lst, requires=False): for item in lst: - print (" Name: %s" % item[cr.PCOR_ENTRY_NAME]) - print (" Flags: %s" % item[cr.PCOR_ENTRY_FLAGS]) - print (" Epoch: %s" % item[cr.PCOR_ENTRY_EPOCH]) - print (" Version: %s" % item[cr.PCOR_ENTRY_VERSION]) - print (" Release: %s" % item[cr.PCOR_ENTRY_RELEASE]) + print((" Name: %s" % item[cr.PCOR_ENTRY_NAME])) + print((" Flags: %s" % item[cr.PCOR_ENTRY_FLAGS])) + print((" Epoch: %s" % item[cr.PCOR_ENTRY_EPOCH])) + print((" Version: %s" % item[cr.PCOR_ENTRY_VERSION])) + print((" Release: %s" % item[cr.PCOR_ENTRY_RELEASE])) if requires: - print( " Pre: %s" % item[cr.PCOR_ENTRY_PRE]) + print(( " Pre: %s" % item[cr.PCOR_ENTRY_PRE])) print (" +-----------------------------------+") def print_files(lst): for item in lst: - print (" Name: %s" % item[cr.FILE_ENTRY_NAME]) - print (" Path: %s" % item[cr.FILE_ENTRY_PATH]) - print (" Type: %s" % item[cr.FILE_ENTRY_TYPE]) + print((" Name: %s" % item[cr.FILE_ENTRY_NAME])) + print((" Path: %s" % item[cr.FILE_ENTRY_PATH])) + print((" Type: %s" % item[cr.FILE_ENTRY_TYPE])) print (" +-----------------------------------+") def print_changelogs(lst): for item in lst: - print (" Author: %s" % item[cr.CHANGELOG_ENTRY_AUTHOR]) - print (" Date: %s" % item[cr.CHANGELOG_ENTRY_DATE]) - print (" Changelog: %s" % item[cr.CHANGELOG_ENTRY_CHANGELOG]) + print((" Author: %s" % item[cr.CHANGELOG_ENTRY_AUTHOR])) + print((" Date: %s" % item[cr.CHANGELOG_ENTRY_DATE])) + print((" Changelog: %s" % item[cr.CHANGELOG_ENTRY_CHANGELOG])) print (" +-----------------------------------+") print ("+=======================================+") - print (" %s" % pkg.name) + print((" %s" % pkg.name)) print ("+=======================================+") - print ("NEVRA: %s" % pkg.nevra()) - print( "NVRA: %s" % pkg.nvra()) - print ("Name: %s" % pkg.name) - print( "Checksum (pkgId): %s" % pkg.pkgId) - print ("Checksum type: %s" % pkg.checksum_type) - print ("Arch: %s" % pkg.arch) - print( "Version: %s" % pkg.version) - print ("Epoch: %s" % pkg.epoch) - print ("Release: %s" % pkg.release) - print ("Summary: %s" % pkg.summary) - print ("Description: %s" % pkg.description) - print ("URL: %s" % pkg.url) - print ("Time file: %s" % pkg.time_file) - print( "Time build: %s" % pkg.time_build) - print ("License: %s" % pkg.rpm_license) - print ("Vendor: %s" % pkg.rpm_vendor) - print ("Group: %s" % pkg.rpm_group) - print ("Buildhost: %s" % pkg.rpm_buildhost) - print ("Source RPM: %s" % pkg.rpm_sourcerpm) - print ("Header start: %s" % pkg.rpm_header_start) - print ("Header end: %s" % pkg.rpm_header_end) - print ("Packager: %s" % pkg.rpm_packager) - print ("Size package: %s" % pkg.size_package) - print ("Size installed: %s" % pkg.size_installed) - print ("Size archive: %s" % pkg.size_archive) - print ("Location href: %s" % pkg.location_href) - print ("Location base: %s" % pkg.location_base) + print(("NEVRA: %s" % pkg.nevra())) + print(( "NVRA: %s" % pkg.nvra())) + print(("Name: %s" % pkg.name)) + print(( "Checksum (pkgId): %s" % pkg.pkgId)) + print(("Checksum type: %s" % pkg.checksum_type)) + print(("Arch: %s" % pkg.arch)) + print(( "Version: %s" % pkg.version)) + print(("Epoch: %s" % pkg.epoch)) + print(("Release: %s" % pkg.release)) + print(("Summary: %s" % pkg.summary)) + print(("Description: %s" % pkg.description)) + print(("URL: %s" % pkg.url)) + print(("Time file: %s" % pkg.time_file)) + print(( "Time build: %s" % pkg.time_build)) + print(("License: %s" % pkg.rpm_license)) + print(("Vendor: %s" % pkg.rpm_vendor)) + print(("Group: %s" % pkg.rpm_group)) + print(("Buildhost: %s" % pkg.rpm_buildhost)) + print(("Source RPM: %s" % pkg.rpm_sourcerpm)) + print(("Header start: %s" % pkg.rpm_header_start)) + print(("Header end: %s" % pkg.rpm_header_end)) + print(("Packager: %s" % pkg.rpm_packager)) + print(("Size package: %s" % pkg.size_package)) + print(("Size installed: %s" % pkg.size_installed)) + print(("Size archive: %s" % pkg.size_archive)) + print(("Location href: %s" % pkg.location_href)) + print(("Location base: %s" % pkg.location_base)) print ("Requires:") print_pcors(pkg.requires, requires=True) print( "Provides:") @@ -81,7 +81,7 @@ def first_method(): """Use of this method is discouraged.""" md = cr.Metadata() md.locate_and_load_xml(REPO_PATH) - for key in md.keys(): + for key in list(md.keys()): pkg = md.get(key) print_package_info(pkg) @@ -156,7 +156,7 @@ def second_method(): the XML_WARNING_* constants. :param message: String message. """ - print ("PARSER WARNING: %s" % message) + print(("PARSER WARNING: %s" % message)) return True repomd2 = cr.Repomd() @@ -208,7 +208,7 @@ def second_method(): newpkgcb=newpkgcb, warningcb=warningcb) - for pkg in packages.itervalues(): + for pkg in packages.values(): print_package_info(pkg) diff --git a/examples/python/repomd_parsing.py b/examples/python/repomd_parsing.py index b0a0c40..73e2f7c 100755 --- a/examples/python/repomd_parsing.py +++ b/examples/python/repomd_parsing.py @@ -9,27 +9,27 @@ REPO_PATH = "repo/" def parse_repomd(path): repomd = cr.Repomd(path) - print( "Revision:", repomd.revision) + print(( "Revision:", repomd.revision)) if repomd.contenthash: - print( "Contenthash:", repomd.contenthash) - print( "Contenthash type:", repomd.contenthash_type) - print ("Repo tags:", repomd.repo_tags) - print ("Content tags:", repomd.content_tags) - print ("Distro tags:", repomd.distro_tags) - print + print(( "Contenthash:", repomd.contenthash)) + print(( "Contenthash type:", repomd.contenthash_type)) + print(("Repo tags:", repomd.repo_tags)) + print(("Content tags:", repomd.content_tags)) + print(("Distro tags:", repomd.distro_tags)) + print() for rec in repomd.records: - print ("Type:", rec.type) - print ("Location href:", rec.location_href) - print ("Location base:", rec.location_base) - print ("Checksum:", rec.checksum) - print( "Checksum type:", rec.checksum_type) - print( "Checksum open:", rec.checksum_open) - print ("Checksum open type:", rec.checksum_open_type) - print ("Timestamp:", rec.timestamp) - print( "Size:", rec.size) - print ("Size open:", rec.size_open) + print(("Type:", rec.type)) + print(("Location href:", rec.location_href)) + print(("Location base:", rec.location_base)) + print(("Checksum:", rec.checksum)) + print(( "Checksum type:", rec.checksum_type)) + print(( "Checksum open:", rec.checksum_open)) + print(("Checksum open type:", rec.checksum_open_type)) + print(("Timestamp:", rec.timestamp)) + print(( "Size:", rec.size)) + print(("Size open:", rec.size_open)) if rec.db_ver: - print ("Db version:", rec.db_ver) + print(("Db version:", rec.db_ver)) print() if __name__ == "__main__": diff --git a/examples/python/simple_createrepo.py b/examples/python/simple_createrepo.py index 748db3a..3cd74b8 100755 --- a/examples/python/simple_createrepo.py +++ b/examples/python/simple_createrepo.py @@ -50,7 +50,7 @@ def do_repodata(path): for filename in pkg_list: pkg = cr.package_from_rpm(filename) pkg.location_href = os.path.basename(filename) - print ("Processing: %s" % pkg.nevra()) + print(("Processing: %s" % pkg.nevra())) pri_xml.add_pkg(pkg) fil_xml.add_pkg(pkg) oth_xml.add_pkg(pkg) @@ -90,9 +90,9 @@ def do_repodata(path): if __name__ == "__main__": if len(sys.argv) != 2 or not os.path.isdir(sys.argv[1]): - print( "Usage: %s " % (sys.argv[0])) + print(( "Usage: %s " % (sys.argv[0]))) sys.exit(1) do_repodata(sys.argv[1]) - print ("Repository created in %s" % sys.argv[1]) + print(("Repository created in %s" % sys.argv[1])) diff --git a/examples/python/simple_modifyrepo.py b/examples/python/simple_modifyrepo.py index 451801a..3929f01 100755 --- a/examples/python/simple_modifyrepo.py +++ b/examples/python/simple_modifyrepo.py @@ -27,7 +27,7 @@ def modifyrepo(filename, repodata): if __name__ == '__main__': # Generate the updateinfo.xml - execfile('updateinfo_gen_02.py') + exec(compile(open('updateinfo_gen_02.py', "rb").read(), 'updateinfo_gen_02.py', 'exec')) #OUT_FILE is defined in updateinfo_gen_02.py, it will be OK at runtime. modifyrepo(OUT_FILE, REPO_PATH) #pylint: disable=undefined-variable diff --git a/examples/python/updateinfo_gen_01.py b/examples/python/updateinfo_gen_01.py index dcd61b9..e1b30c2 100755 --- a/examples/python/updateinfo_gen_01.py +++ b/examples/python/updateinfo_gen_01.py @@ -46,7 +46,7 @@ def generate(): ui = cr.UpdateInfo() ui.append(rec) - print( ui.xml_dump(),) + print(( ui.xml_dump(),)) if __name__ == "__main__": generate() diff --git a/examples/python/updateinfo_gen_02.py b/examples/python/updateinfo_gen_02.py index f99f9e2..5ad8fc9 100755 --- a/examples/python/updateinfo_gen_02.py +++ b/examples/python/updateinfo_gen_02.py @@ -50,7 +50,7 @@ def generate(): f.add_chunk(chunk) f.close() - print ("See the %s" % OUT_FILE) + print(("See the %s" % OUT_FILE)) if __name__ == "__main__": diff --git a/examples/python/updateinfo_parsing.py b/examples/python/updateinfo_parsing.py index 02e5aab..f45daa8 100755 --- a/examples/python/updateinfo_parsing.py +++ b/examples/python/updateinfo_parsing.py @@ -10,44 +10,44 @@ import createrepo_c as cr def parse_updateinfo(path): uinfo = cr.UpdateInfo(path) for update in uinfo.updates: - print( "From: %s" % update.fromstr) - print ("Status: %s" % update.status) - print ("Type: %s" % update.type) - print ("Version: %s" % update.version) - print( "Id: %s" % update.id) - print ("Title: %s" % update.title) - print ("Issued date: %s" % update.issued_date) - print ("Updated date: %s" % update.updated_date) - print ("Rights: %s" % update.rights) - print ("Release: %s" % update.release) - print( "Pushcount: %s" % update.pushcount) - print ("Severity: %s" % update.severity) - print ("Summary: %s" % update.summary) - print ("Description: %s" % update.description) - print ("Solution: %s" % update.solution) + print(( "From: %s" % update.fromstr)) + print(("Status: %s" % update.status)) + print(("Type: %s" % update.type)) + print(("Version: %s" % update.version)) + print(( "Id: %s" % update.id)) + print(("Title: %s" % update.title)) + print(("Issued date: %s" % update.issued_date)) + print(("Updated date: %s" % update.updated_date)) + print(("Rights: %s" % update.rights)) + print(("Release: %s" % update.release)) + print(( "Pushcount: %s" % update.pushcount)) + print(("Severity: %s" % update.severity)) + print(("Summary: %s" % update.summary)) + print(("Description: %s" % update.description)) + print(("Solution: %s" % update.solution)) print ("References:") for ref in update.references: - print( " Href: %s" % ref.href) - print( " Id: %s" % ref.id) - print( " Type: %s" % ref.type) - print (" Title: %s" % ref.title) + print(( " Href: %s" % ref.href)) + print(( " Id: %s" % ref.id)) + print(( " Type: %s" % ref.type)) + print((" Title: %s" % ref.title)) print( " ----------------------------") print ("Pkglist (collections):") for col in update.collections: - print (" Short: %s" % col.shortname) - print (" name: %s" % col.name) + print((" Short: %s" % col.shortname)) + print((" name: %s" % col.name)) print( " Packages:") for pkg in col.packages: - print (" Name: %s" % pkg.name) - print (" Version: %s" % pkg.version) - print (" Release: %s" % pkg.release) - print( " Epoch: %s" % pkg.epoch) - print (" Arch: %s" % pkg.arch) - print( " Src: %s" % pkg.src) - print (" Filename: %s" % pkg.filename) - print (" Sum: %s" % pkg.sum) - print( " Sum type: %s (%s)" % (pkg.sum_type, cr.checksum_name_str(pkg.sum_type))) - print (" Reboot suggested: %s" % pkg.reboot_suggested) + print((" Name: %s" % pkg.name)) + print((" Version: %s" % pkg.version)) + print((" Release: %s" % pkg.release)) + print(( " Epoch: %s" % pkg.epoch)) + print((" Arch: %s" % pkg.arch)) + print(( " Src: %s" % pkg.src)) + print((" Filename: %s" % pkg.filename)) + print((" Sum: %s" % pkg.sum)) + print(( " Sum type: %s (%s)" % (pkg.sum_type, cr.checksum_name_str(pkg.sum_type)))) + print((" Reboot suggested: %s" % pkg.reboot_suggested)) print (" ----------------------------") print( "==============================") diff --git a/packaging/createrepo_c.spec b/packaging/createrepo_c.spec index b7a6a86..1d8445a 100644 --- a/packaging/createrepo_c.spec +++ b/packaging/createrepo_c.spec @@ -7,7 +7,7 @@ Group: System/Base Source: %{name}-%{version}.tar.gz Source1001: createrepo_c.manifest BuildRequires: libbz2-devel cmake libexpat-devel file-devel -BuildRequires: libcurl-devel libxml2-devel python-devel gcc-c++ +BuildRequires: libcurl-devel libxml2-devel python3-devel gcc-c++ BuildRequires: rpm-devel openssl-devel sqlite-devel doxygen BuildRequires: glib2-devel xz-devel @@ -72,7 +72,7 @@ done %{_libdir}/libcreaterepo_c.so %{_libdir}/pkgconfig/createrepo_c.pc %{_includedir}/createrepo_c -%{python_sitearch}/createrepo_c +#%{python3_sitearch}/createrepo_c %files -n libcreaterepo_c0 %defattr(-, root, root,-) diff --git a/src/python/__init__.py b/src/python/__init__.py index b493e2a..c754834 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -14,7 +14,7 @@ VERSION_MINOR = _createrepo_c.VERSION_MINOR #: Minor version VERSION_PATCH = _createrepo_c.VERSION_PATCH #: Patch version #: Version string -VERSION = u"%d.%d.%d" % (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) +VERSION = "%d.%d.%d" % (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) UNKNOWN_CHECKSUM = _createrepo_c.CHECKSUM_UNKNOWN #: Checksum unknown CHECKSUM_UNKNOWN = _createrepo_c.CHECKSUM_UNKNOWN #: Checksum unknown diff --git a/tests/python/tests/test_load_metadata.py b/tests/python/tests/test_load_metadata.py index e12a86f..2dbf205 100644 --- a/tests/python/tests/test_load_metadata.py +++ b/tests/python/tests/test_load_metadata.py @@ -12,9 +12,9 @@ class TestCaseLoadMetadata(unittest.TestCase): self.assertEqual(md.key, cr.HT_KEY_DEFAULT) self.assertEqual(md.len(), 0) - self.assertEqual(md.keys(), []) - self.assertFalse(md.has_key("foo")) - self.assertFalse(md.has_key("")) + self.assertEqual(list(md.keys()), []) + self.assertFalse("foo" in md) + self.assertFalse("" in md) self.assertFalse(md.remove("foo")) self.assertFalse(md.get("xxx")) @@ -26,9 +26,9 @@ class TestCaseLoadMetadata(unittest.TestCase): self.assertEqual(md.key, cr.HT_KEY_DEFAULT) self.assertEqual(md.len(), 1) - self.assertEqual(md.keys(), ['152824bff2aa6d54f429d43e87a3ff3a0286505c6d93ec87692b5e3a9e3b97bf']) - self.assertFalse(md.has_key("foo")) - self.assertFalse(md.has_key("")) + self.assertEqual(list(md.keys()), ['152824bff2aa6d54f429d43e87a3ff3a0286505c6d93ec87692b5e3a9e3b97bf']) + self.assertFalse("foo" in md) + self.assertFalse("" in md) self.assertFalse(md.remove("foo")) pkg = md.get('152824bff2aa6d54f429d43e87a3ff3a0286505c6d93ec87692b5e3a9e3b97bf') @@ -44,11 +44,11 @@ class TestCaseLoadMetadata(unittest.TestCase): self.assertEqual(md.key, cr.HT_KEY_DEFAULT) self.assertEqual(md.len(), 2) - self.assertEqual(md.keys(), + self.assertEqual(list(md.keys()), ['6d43a638af70ef899933b1fd86a866f18f65b0e0e17dcbf2e42bfd0cdd7c63c3', '90f61e546938a11449b710160ad294618a5bd3062e46f8cf851fd0088af184b7']) - self.assertFalse(md.has_key("foo")) - self.assertFalse(md.has_key("")) + self.assertFalse("foo" in md) + self.assertFalse("" in md) self.assertFalse(md.remove("foo")) pkg = md.get('152824bff2aa6d54f429d43e87a3ff3a0286505c6d93ec87692b5e3a9e3b97bf') diff --git a/tests/python/tests/test_sqlite.py b/tests/python/tests/test_sqlite.py index 2f02201..78d40c7 100644 --- a/tests/python/tests/test_sqlite.py +++ b/tests/python/tests/test_sqlite.py @@ -68,38 +68,38 @@ class TestCaseSqlite(unittest.TestCase): con = sqlite3.connect(path) # Check tables self.assertEqual(con.execute("""select name from sqlite_master where type="table";""").fetchall(), - [(u'db_info',), - (u'packages',), - (u'files',), - (u'requires',), - (u'provides',), - (u'conflicts',), - (u'obsoletes',), - (u'suggests',), - (u'enhances',), - (u'recommends',), - (u'supplements',), + [('db_info',), + ('packages',), + ('files',), + ('requires',), + ('provides',), + ('conflicts',), + ('obsoletes',), + ('suggests',), + ('enhances',), + ('recommends',), + ('supplements',), ]) # Check indexes self.assertEqual(con.execute("""select name from sqlite_master where type="index";""").fetchall(), - [(u'packagename',), - (u'packageId',), - (u'filenames',), - (u'pkgfiles',), - (u'pkgrequires',), - (u'requiresname',), - (u'pkgprovides',), - (u'providesname',), - (u'pkgconflicts',), - (u'pkgobsoletes',), - (u'pkgsuggests',), - (u'pkgenhances',), - (u'pkgrecommends',), - (u'pkgsupplements',), + [('packagename',), + ('packageId',), + ('filenames',), + ('pkgfiles',), + ('pkgrequires',), + ('requiresname',), + ('pkgprovides',), + ('providesname',), + ('pkgconflicts',), + ('pkgobsoletes',), + ('pkgsuggests',), + ('pkgenhances',), + ('pkgrecommends',), + ('pkgsupplements',), ]) # Check triggers self.assertEqual(con.execute("""select name from sqlite_master where type="trigger";""").fetchall(), - [(u'removals',)]) + [('removals',)]) def test_sqlite_filelists_schema(self): path = os.path.join(self.tmpdir, "filelists.db") @@ -109,13 +109,13 @@ class TestCaseSqlite(unittest.TestCase): con = sqlite3.connect(path) # Check tables self.assertEqual(con.execute("""select name from sqlite_master where type="table";""").fetchall(), - [(u'db_info',), (u'packages',), (u'filelist',)]) + [('db_info',), ('packages',), ('filelist',)]) # Check indexes self.assertEqual(con.execute("""select name from sqlite_master where type="index";""").fetchall(), - [(u'keyfile',), (u'pkgId',), (u'dirnames',)]) + [('keyfile',), ('pkgId',), ('dirnames',)]) # Check triggers self.assertEqual(con.execute("""select name from sqlite_master where type="trigger";""").fetchall(), - [(u'remove_filelist',)]) + [('remove_filelist',)]) def test_sqlite_other_schema(self): path = os.path.join(self.tmpdir, "other.db") @@ -125,13 +125,13 @@ class TestCaseSqlite(unittest.TestCase): con = sqlite3.connect(path) # Check tables self.assertEqual(con.execute("""select name from sqlite_master where type="table";""").fetchall(), - [(u'db_info',), (u'packages',), (u'changelog',)]) + [('db_info',), ('packages',), ('changelog',)]) # Check indexes self.assertEqual(con.execute("""select name from sqlite_master where type="index";""").fetchall(), - [(u'keychange',), (u'pkgId',)]) + [('keychange',), ('pkgId',)]) # Check triggers self.assertEqual(con.execute("""select name from sqlite_master where type="trigger";""").fetchall(), - [(u'remove_changelogs',)]) + [('remove_changelogs',)]) def test_sqlite_primary(self): path = os.path.join(self.tmpdir, "primary.db") @@ -154,55 +154,55 @@ class TestCaseSqlite(unittest.TestCase): # Check packages table res = con.execute("select * from packages").fetchall() self.assertEqual(res, - [(1, u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e', - u'Archer', u'x86_64', u'3.4.5', u'2', u'6', u'Complex package.', - u'Archer package', u'http://soo_complex_package.eu/', - res[0][10], 1365416480, u'GPL', u'ISIS', u'Development/Tools', - u'localhost.localdomain', u'Archer-3.4.5-6.src.rpm', 280, 2865, - u'Sterling Archer', 3101, 0, 544, None, None, u'sha256')]) + [(1, '4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e', + 'Archer', 'x86_64', '3.4.5', '2', '6', 'Complex package.', + 'Archer package', 'http://soo_complex_package.eu/', + res[0][10], 1365416480, 'GPL', 'ISIS', 'Development/Tools', + 'localhost.localdomain', 'Archer-3.4.5-6.src.rpm', 280, 2865, + 'Sterling Archer', 3101, 0, 544, None, None, 'sha256')]) # Check provides table self.assertEqual(con.execute("select * from provides").fetchall(), - [(u'bara', u'LE', u'0', u'22', None, 1), - (u'barb', u'GE', u'0', u'11.22.33', u'44', 1), - (u'barc', u'EQ', u'0', u'33', None, 1), - (u'bard', u'LT', u'0', u'44', None, 1), - (u'bare', u'GT', u'0', u'55', None, 1), - (u'Archer', u'EQ', u'2', u'3.4.5', u'6', 1), - (u'Archer(x86-64)', u'EQ', u'2', u'3.4.5', u'6', 1)]) + [('bara', 'LE', '0', '22', None, 1), + ('barb', 'GE', '0', '11.22.33', '44', 1), + ('barc', 'EQ', '0', '33', None, 1), + ('bard', 'LT', '0', '44', None, 1), + ('bare', 'GT', '0', '55', None, 1), + ('Archer', 'EQ', '2', '3.4.5', '6', 1), + ('Archer(x86-64)', 'EQ', '2', '3.4.5', '6', 1)]) # Check conflicts table self.assertEqual(con.execute("select * from conflicts").fetchall(), - [(u'bba', u'LE', u'0', u'2222', None, 1), - (u'bbb', u'GE', u'0', u'1111.2222.3333', u'4444', 1), - (u'bbc', u'EQ', u'0', u'3333', None, 1), - (u'bbd', u'LT', u'0', u'4444', None, 1), - (u'bbe', u'GT', u'0', u'5555', None, 1)]) + [('bba', 'LE', '0', '2222', None, 1), + ('bbb', 'GE', '0', '1111.2222.3333', '4444', 1), + ('bbc', 'EQ', '0', '3333', None, 1), + ('bbd', 'LT', '0', '4444', None, 1), + ('bbe', 'GT', '0', '5555', None, 1)]) # Check obsoletes table self.assertEqual(con.execute("select * from obsoletes").fetchall(), - [(u'aaa', u'LE', u'0', u'222', None, 1), - (u'aab', u'GE', u'0', u'111.2.3', u'4', 1), - (u'aac', u'EQ', u'0', u'333', None, 1), - (u'aad', u'LT', u'0', u'444', None, 1), - (u'aae', u'GT', u'0', u'555', None, 1)]) + [('aaa', 'LE', '0', '222', None, 1), + ('aab', 'GE', '0', '111.2.3', '4', 1), + ('aac', 'EQ', '0', '333', None, 1), + ('aad', 'LT', '0', '444', None, 1), + ('aae', 'GT', '0', '555', None, 1)]) # Check requires table self.assertEqual(con.execute("select * from requires").fetchall(), - [(u'fooa', u'LE', u'0', u'2', None, 1, u'FALSE'), - (u'foob', u'GE', u'0', u'1.0.0', u'1', 1, u'FALSE'), - (u'fooc', u'EQ', u'0', u'3', None, 1, u'FALSE'), - (u'food', u'LT', u'0', u'4', None, 1, u'FALSE'), - (u'fooe', u'GT', u'0', u'5', None, 1, u'FALSE'), - (u'foof', u'EQ', u'0', u'6', None, 1, u'TRUE')]) + [('fooa', 'LE', '0', '2', None, 1, 'FALSE'), + ('foob', 'GE', '0', '1.0.0', '1', 1, 'FALSE'), + ('fooc', 'EQ', '0', '3', None, 1, 'FALSE'), + ('food', 'LT', '0', '4', None, 1, 'FALSE'), + ('fooe', 'GT', '0', '5', None, 1, 'FALSE'), + ('foof', 'EQ', '0', '6', None, 1, 'TRUE')]) # Check files table self.assertEqual(con.execute("select * from files").fetchall(), - [(u'/usr/bin/complex_a', u'file', 1)]) + [('/usr/bin/complex_a', 'file', 1)]) # Check db_info table self.assertEqual(con.execute("select * from db_info").fetchall(), - [(10, u'somechecksum')]) + [(10, 'somechecksum')]) def test_sqlite_filelists(self): path = os.path.join(self.tmpdir, "filelists.db") @@ -218,17 +218,17 @@ class TestCaseSqlite(unittest.TestCase): # Check packages table self.assertEqual(con.execute("select * from packages").fetchall(), - [(1, u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e')]) + [(1, '4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e')]) # Check files table self.assertEqual(set(con.execute("select * from filelist").fetchall()), - set([(1, u'/usr/share/doc', u'Archer-3.4.5', u'd'), - (1, u'/usr/bin', u'complex_a', u'f'), - (1, u'/usr/share/doc/Archer-3.4.5', u'README', u'f')])) + set([(1, '/usr/share/doc', 'Archer-3.4.5', 'd'), + (1, '/usr/bin', 'complex_a', 'f'), + (1, '/usr/share/doc/Archer-3.4.5', 'README', 'f')])) # Check db_info table self.assertEqual(con.execute("select * from db_info").fetchall(), - [(10, u'somechecksum2')]) + [(10, 'somechecksum2')]) def test_sqlite_other(self): path = os.path.join(self.tmpdir, "other.db") @@ -244,14 +244,14 @@ class TestCaseSqlite(unittest.TestCase): # Check packages table self.assertEqual(con.execute("select * from packages").fetchall(), - [(1, u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e')]) + [(1, '4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e')]) # Check filelist table self.assertEqual(set(con.execute("select * from filelist").fetchall()), - set([(1, u'/usr/share/doc', u'Archer-3.4.5', u'd'), - (1, u'/usr/bin', u'complex_a', u'f'), - (1, u'/usr/share/doc/Archer-3.4.5', u'README', u'f')])) + set([(1, '/usr/share/doc', 'Archer-3.4.5', 'd'), + (1, '/usr/bin', 'complex_a', 'f'), + (1, '/usr/share/doc/Archer-3.4.5', 'README', 'f')])) # Check db_info table self.assertEqual(con.execute("select * from db_info").fetchall(), - [(10, u'somechecksum3')]) + [(10, 'somechecksum3')]) diff --git a/utils/gen_rst.py b/utils/gen_rst.py index 90291ba..848edd8 100755 --- a/utils/gen_rst.py +++ b/utils/gen_rst.py @@ -70,13 +70,13 @@ def parse_arguments_from_c_file(filename): try: content = open(filename, "r").read() except IOError: - print( "Error: Cannot open file %s" % filename) + print(( "Error: Cannot open file %s" % filename)) return args re_cmd_entries = re.compile(r"\s*(static|const)[ ]+GOptionEntry[^{]*{(?P.*)\s*NULL\s*}[,]?\s*};", re.MULTILINE|re.DOTALL) match = re_cmd_entries.search(content) if not match: - print ("Warning: Cannot find GOptionEntry section in %s" % filename) + print(("Warning: Cannot find GOptionEntry section in %s" % filename)) return args re_single_entry = re.compile(r"""{\s*"(?P[^"]*)"\s*, # long name @@ -134,7 +134,7 @@ def parse_arguments_from_c_file(filename): entry_match = re_single_entry.search(raw_entries_str[start:]) # End while - print >> sys.stderr, "Loaded %2d arguments" % (i,) + print("Loaded %2d arguments" % (i,), file=sys.stderr) return args @@ -147,7 +147,7 @@ if __name__ == "__main__": options, args = parser.parse_args() if len(args) < 1: - print >> sys.stderr, "Error: Must specify a input filename. (Example: ../src/cmd_parser.c)" + print("Error: Must specify a input filename. (Example: ../src/cmd_parser.c)", file=sys.stderr) sys.exit(1) args = parse_arguments_from_c_file(args[0]) @@ -181,7 +181,7 @@ if __name__ == "__main__": ret = info.gen_rst() if not ret: - print >> sys.stderr,"Error: Rst has not been generated" + print("Error: Rst has not been generated", file=sys.stderr) sys.exit(1) print (ret) diff --git a/utils/get_version.py b/utils/get_version.py index 8e707e9..2e4aeaa 100755 --- a/utils/get_version.py +++ b/utils/get_version.py @@ -11,7 +11,7 @@ VERSION_FILE_PATH = "VERSION.cmake" def parse(root_dir): path = os.path.join(root_dir, VERSION_FILE_PATH) if not os.path.exists(path): - print ("File %s doesn't exists" % path) + print(("File %s doesn't exists" % path)) return None content = open(path, "r").read() @@ -42,12 +42,12 @@ if __name__ == "__main__": sys.exit(1) if options.major: - print (ver['major']) + print((ver['major'])) elif options.minor: - print( ver['minor']) + print(( ver['minor'])) elif options.patch: - print( ver['patch']) + print(( ver['patch'])) else: - print( "%(major)s.%(minor)s.%(patch)s" % ver) + print(( "%(major)s.%(minor)s.%(patch)s" % ver)) sys.exit(0)