aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas C. Villa Real <lucasvr@gmail.com>2018-06-29 16:45:02 -0300
committerLucas C. Villa Real <lucasvr@gmail.com>2018-06-29 16:45:02 -0300
commit66fb74ab6a86b9b03ca9237fa336f20b9d16d07e (patch)
tree23cb2c38b886ff6b083f9021f64cee8fa7fa0071
parentd2ba94f7a053be93b80d6c94ef1c1fe8ed22f9e1 (diff)
downloadThirdPartyInstallers-66fb74ab6a86b9b03ca9237fa336f20b9d16d07e.tar.xz
Moved to Python 3 and fixed indentation issues.
-rwxr-xr-xbin/RPMFinder114
1 files changed, 58 insertions, 56 deletions
diff --git a/bin/RPMFinder b/bin/RPMFinder
index 1797174..49900b6 100755
--- a/bin/RPMFinder
+++ b/bin/RPMFinder
@@ -1,4 +1,6 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# vim: set noexpandtab tabstop=4 shiftwidth=4 autoindent smartindent:
# Searches over the network to find out which RPM package distributes
# a given file.
@@ -10,75 +12,75 @@ import os
import sys
import argparse
import subprocess
-from HTMLParser import HTMLParser
+from html.parser import HTMLParser
class RPMFind_Parser(HTMLParser):
- '''
- Parses the HTML data output by rpmfind.net
- '''
- def __init__(self):
- self.tags = []
- self.candidates = []
- HTMLParser.__init__(self)
+ '''
+ Parses the HTML data output by rpmfind.net
+ '''
+ def __init__(self):
+ self.tags = []
+ self.candidates = []
+ HTMLParser.__init__(self)
- def handle_starttag(self, tag, attrs):
- self.tags.append(tag)
+ def handle_starttag(self, tag, attrs):
+ self.tags.append(tag)
- def handle_endtag(self, tag):
- self.tags.pop()
+ def handle_endtag(self, tag):
+ self.tags.pop()
- def handle_data(self, data):
- if len(self.tags) and self.tags[-1] == "a" and data.find(".rpm") >= 0:
- self.candidates.append(data)
+ def handle_data(self, data):
+ if len(self.tags) and self.tags[-1] == "a" and data.find(".rpm") >= 0:
+ self.candidates.append(data)
- def get_pkgname(self):
- if len(self.candidates) == 0:
- return ""
- name = os.path.commonprefix(self.candidates)
- if name.endswith("-"):
- name = name[:-1]
- return name
+ def get_pkgname(self):
+ if len(self.candidates) == 0:
+ return ""
+ name = os.path.commonprefix(self.candidates)
+ if name.endswith("-"):
+ name = name[:-1]
+ return name
class RPMFinder:
- def find(self, path, arch, distro):
- '''
- Searches rpmfind.net for a given file. Arch and distro can
- be provided to reduce the search scope. Returns the package
- name on success or an empty string if no matches were found.
- '''
- self.path = path
- self.arch = arch
- self.distro = distro
- return self.__search_rpmfind_net()
-
- def __search_rpmfind_net(self):
- path = self.path.replace("/", "%2F")
- arch = self.arch
- baseuri = "http://rpmfind.net/linux/rpm2html/search.php"
- query = "?query={0}&submit=Search+...&system=&arch={1}".format(path, arch)
- html = subprocess.check_output(["wget", "--quiet", "{0}{1}".format(baseuri, query), "-O", "-"])
-
- htmlparser = RPMFind_Parser()
- htmlparser.feed(html)
- return htmlparser.get_pkgname()
+ def find(self, path, arch, distro):
+ '''
+ Searches rpmfind.net for a given file. Arch and distro can
+ be provided to reduce the search scope. Returns the package
+ name on success or an empty string if no matches were found.
+ '''
+ self.path = path
+ self.arch = arch
+ self.distro = distro
+ return self.__search_rpmfind_net()
+
+ def __search_rpmfind_net(self):
+ path = self.path.replace("/", "%2F")
+ arch = self.arch
+ baseuri = "http://rpmfind.net/linux/rpm2html/search.php"
+ query = "?query={0}&submit=Search+...&system=&arch={1}".format(path, arch)
+ html = subprocess.check_output(["wget", "--quiet", "{0}{1}".format(baseuri, query), "-O", "-"])
+
+ htmlparser = RPMFind_Parser()
+ htmlparser.feed(html)
+ return htmlparser.get_pkgname()
def main():
- argparser = argparse.ArgumentParser(argument_default="")
- argparser.add_argument("--path", type=str, help="File name to search for in the remote RPM databases")
- argparser.add_argument("--arch", type=str, help="Architecture (optional)")
- argparser.add_argument("--distro", type=str, help="Distribution (optional)")
- args = argparser.parse_args()
+ argparser = argparse.ArgumentParser(argument_default="")
+ argparser.add_argument("--path", type=str, help="File name to search for in the remote RPM databases")
+ argparser.add_argument("--arch", type=str, help="Architecture (optional)")
+ argparser.add_argument("--distro", type=str, help="Distribution (optional)")
+ args = argparser.parse_args()
- if len(args.path) == 0:
- argparser.print_help()
- sys.exit(1)
+ if len(args.path) == 0:
+ argparser.print_help()
+ sys.exit(1)
- pkgname = RPMFinder().find(args.path, args.arch, args.distro)
- if len(pkgname):
- print pkgname
+ pkgname = RPMFinder().find(args.path, args.arch, args.distro)
+ if len(pkgname):
+ print(pkgname)
if __name__ == "__main__":
- main()
+ main()