From 602d16ee7499dd7be391f4d10da8416ea79525bf Mon Sep 17 00:00:00 2001 From: "biao716.wang" Date: Mon, 25 Nov 2019 10:27:50 +0800 Subject: [PATCH] fix pylint error for createrepo_c Change-Id: I7936d9ed28608be9e682b13f59c3bb75f08654a5 Signed-off-by: biao716.wang --- examples/python/contenthash_calculation.py | 2 +- examples/python/repodata_parsing.py | 112 ++++++++++++++--------------- examples/python/repomd_parsing.py | 36 +++++----- examples/python/simple_createrepo.py | 6 +- examples/python/simple_modifyrepo.py | 3 +- examples/python/updateinfo_gen_01.py | 2 +- examples/python/updateinfo_gen_02.py | 2 +- examples/python/updateinfo_parsing.py | 74 +++++++++---------- src/python/__init__.py | 5 +- tests/python/tests/test_repomd.py | 4 +- tests/python/tests/test_repomdrecord.py | 2 +- tests/python/tests/test_version.py | 6 +- tests/python/tests/test_xml_parser.py | 18 ++--- utils/gen_rst.py | 8 +-- utils/get_version.py | 10 +-- 15 files changed, 146 insertions(+), 144 deletions(-) diff --git a/examples/python/contenthash_calculation.py b/examples/python/contenthash_calculation.py index 8b0557f..b39b2d1 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 78b2f81..6df99a1 100755 --- a/examples/python/repodata_parsing.py +++ b/examples/python/repodata_parsing.py @@ -11,70 +11,70 @@ 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 " +-----------------------------------+" + 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 " +-----------------------------------+" + 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 " +-----------------------------------+" - - print "+=======================================+" - 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 "Requires:" + 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 ("+=======================================+") + 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:" + print( "Provides:") print_pcors(pkg.provides) - print "Conflicts:" + print ("Conflicts:") print_pcors(pkg.conflicts) - print "Obsoletes:" + print ("Obsoletes:") print_pcors(pkg.obsoletes) - print "Files:" + print( "Files:") print_files(pkg.files) - print "Changelogs:" + print( "Changelogs:") print_changelogs(pkg.changelogs) def first_method(): @@ -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() @@ -213,11 +213,11 @@ def second_method(): if __name__ == "__main__": - print '"All in one shot" method:' + print( '"All in one shot" method:') first_method() - print + print() - print "Callback based method:" + print( "Callback based method:") second_method() diff --git a/examples/python/repomd_parsing.py b/examples/python/repomd_parsing.py index 48d8c14..b0a0c40 100755 --- a/examples/python/repomd_parsing.py +++ b/examples/python/repomd_parsing.py @@ -9,28 +9,28 @@ 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( "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 + print ("Db version:", rec.db_ver) + print() if __name__ == "__main__": repomd_path = os.path.join(REPO_PATH, "repodata/repomd.xml") diff --git a/examples/python/simple_createrepo.py b/examples/python/simple_createrepo.py index e5b3478..748db3a 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 c66d133..451801a 100755 --- a/examples/python/simple_modifyrepo.py +++ b/examples/python/simple_modifyrepo.py @@ -28,5 +28,6 @@ def modifyrepo(filename, repodata): if __name__ == '__main__': # Generate the updateinfo.xml execfile('updateinfo_gen_02.py') + #OUT_FILE is defined in updateinfo_gen_02.py, it will be OK at runtime. + modifyrepo(OUT_FILE, REPO_PATH) #pylint: disable=undefined-variable - modifyrepo(OUT_FILE, REPO_PATH) diff --git a/examples/python/updateinfo_gen_01.py b/examples/python/updateinfo_gen_01.py index 799efc6..dcd61b9 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 fe70bf9..f99f9e2 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 364ed63..02e5aab 100755 --- a/examples/python/updateinfo_parsing.py +++ b/examples/python/updateinfo_parsing.py @@ -10,46 +10,46 @@ 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 "References:" + 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 " ----------------------------" - print "Pkglist (collections):" + 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 " Packages:" + 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 " ----------------------------" - print "==============================" + 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( "==============================") if __name__ == "__main__": diff --git a/src/python/__init__.py b/src/python/__init__.py index 95483ab..e71394a 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -4,8 +4,9 @@ import sys, os, site sys.path.append(os.path.join(site.getsitepackages()[0], 'createrepo_c/')) sys.path.append('/usr/lib/pyshared/python2.7/createrepo_c') -import _createrepo_c -from _createrepo_c import * +#_createrepo_c is a so lib that belong to createrepo_c, it will be OK to import using the above statement at runtime. +import _createrepo_c #pylint: disable=import-error +from _createrepo_c import * #pylint: disable=import-error VERSION_MAJOR = _createrepo_c.VERSION_MAJOR #: Major version VERSION_MINOR = _createrepo_c.VERSION_MINOR #: Minor version diff --git a/tests/python/tests/test_repomd.py b/tests/python/tests/test_repomd.py index 6b6b3ad..5a41f17 100644 --- a/tests/python/tests/test_repomd.py +++ b/tests/python/tests/test_repomd.py @@ -47,11 +47,11 @@ class TestCaseRepomd(unittest.TestCase): md.set_revision("foobar") self.assertEqual(md.revision, "foobar") - self.assertEqual(md.repoid, None); + self.assertEqual(md.repoid, None) md.set_repoid("barid", "sha256") self.assertEqual(md.repoid, "barid") - self.assertEqual(md.contenthash, None); + self.assertEqual(md.contenthash, None) md.set_contenthash("fooid", "sha256") self.assertEqual(md.contenthash, "fooid") diff --git a/tests/python/tests/test_repomdrecord.py b/tests/python/tests/test_repomdrecord.py index 9d2a14b..7e2a0bc 100644 --- a/tests/python/tests/test_repomdrecord.py +++ b/tests/python/tests/test_repomdrecord.py @@ -141,7 +141,7 @@ class TestCaseRepomdRecord(unittest.TestCase): self.assertEqual(rec.checksum_open_type, None) self.assertEqual(rec.size, 0) - rec.load_contentstat(stat); + rec.load_contentstat(stat) self.assertEqual(rec.checksum_open, "foobar") self.assertEqual(rec.checksum_open_type, "sha256") diff --git a/tests/python/tests/test_version.py b/tests/python/tests/test_version.py index 2a944c2..93cabe4 100644 --- a/tests/python/tests/test_version.py +++ b/tests/python/tests/test_version.py @@ -5,6 +5,6 @@ from . import fixtures class TestCaseVersion(unittest.TestCase): def test_version(self): - self.assertTrue(isinstance(cr.VERSION_MAJOR, int)); - self.assertTrue(isinstance(cr.VERSION_MINOR, int)); - self.assertTrue(isinstance(cr.VERSION_PATCH, int)); + self.assertTrue(isinstance(cr.VERSION_MAJOR, int)) + self.assertTrue(isinstance(cr.VERSION_MINOR, int)) + self.assertTrue(isinstance(cr.VERSION_PATCH, int)) diff --git a/tests/python/tests/test_xml_parser.py b/tests/python/tests/test_xml_parser.py index a5f5d6a..3c37342 100644 --- a/tests/python/tests/test_xml_parser.py +++ b/tests/python/tests/test_xml_parser.py @@ -174,7 +174,7 @@ class TestCaseXmlParserPrimary(unittest.TestCase): def test_xml_parser_primary_newpkgcb_abort(self): def newpkgcb(pkgId, name, arch): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_primary, REPO_02_PRIXML, newpkgcb, None, None, 1) @@ -183,7 +183,7 @@ class TestCaseXmlParserPrimary(unittest.TestCase): def newpkgcb(pkgId, name, arch): return cr.Package() def pkgcb(pkg): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_primary, REPO_02_PRIXML, newpkgcb, pkgcb, None, 1) @@ -192,7 +192,7 @@ class TestCaseXmlParserPrimary(unittest.TestCase): def newpkgcb(pkgId, name, arch): return cr.Package() def warningcb(type, msg): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_primary, PRIMARY_MULTI_WARN_00_PATH, @@ -348,7 +348,7 @@ class TestCaseXmlParserFilelists(unittest.TestCase): def test_xml_parser_filelists_newpkgcb_abort(self): def newpkgcb(pkgId, name, arch): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_filelists, REPO_02_FILXML, newpkgcb, None, None) @@ -357,7 +357,7 @@ class TestCaseXmlParserFilelists(unittest.TestCase): def newpkgcb(pkgId, name, arch): return cr.Package() def pkgcb(pkg): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_filelists, REPO_02_FILXML, newpkgcb, pkgcb, None) @@ -366,7 +366,7 @@ class TestCaseXmlParserFilelists(unittest.TestCase): def newpkgcb(pkgId, name, arch): return cr.Package() def warningcb(type, msg): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_filelists, FILELISTS_MULTI_WARN_00_PATH, @@ -526,7 +526,7 @@ class TestCaseXmlParserOther(unittest.TestCase): def test_xml_parser_other_newpkgcb_abort(self): def newpkgcb(pkgId, name, arch): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_other, REPO_02_OTHXML, newpkgcb, None, None) @@ -535,7 +535,7 @@ class TestCaseXmlParserOther(unittest.TestCase): def newpkgcb(pkgId, name, arch): return cr.Package() def pkgcb(pkg): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_other, REPO_02_OTHXML, newpkgcb, pkgcb, None) @@ -544,7 +544,7 @@ class TestCaseXmlParserOther(unittest.TestCase): def newpkgcb(pkgId, name, arch): return cr.Package() def warningcb(type, msg): - raise Error("Foo error") + raise Exception("Foo error") self.assertRaises(cr.CreaterepoCError, cr.xml_parse_other, OTHER_MULTI_WARN_00_PATH, diff --git a/utils/gen_rst.py b/utils/gen_rst.py index a5395f5..90291ba 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 @@ -181,7 +181,7 @@ if __name__ == "__main__": ret = info.gen_rst() if not ret: - print >> sys.stderr, "Error: Rst has not been generated" + print >> sys.stderr,"Error: Rst has not been generated" sys.exit(1) - print ret + print (ret) diff --git a/utils/get_version.py b/utils/get_version.py index c840003..8e707e9 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) -- 2.7.4