diff --git a/README.md b/README.md index bf96da5b2bfafeba7f1c7fb915fac2e6272b2f9f..66383da6a05792a3f591f9f81cdbeddb2b291163 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Install below software before using this tool pyporter is a tool to create spec file and create rpm for python modules For more details, please use pyporter -h -pyporter <package> -s -b -d -o python-<package>.spec +pyporter <package> -v <version> -s -b -d -o python-<package>.spec #### Contribution diff --git a/pyporter b/pyporter index 104812f9bb0efdc6fb3a9299639a96f5c00cc1aa..391779721ea13576dc462285001c72dd88442038 100755 --- a/pyporter +++ b/pyporter @@ -56,17 +56,26 @@ buildreq_tag_template = 'BuildRequires:\t{req}' class PyPorter: __url_template = 'https://pypi.org/pypi/{pkg_name}/json' + __url_template_ver = 'https://pypi.org/pypi/{pkg_name}/{pkg_ver}/json' __build_noarch = True __json = None __module_name = "" __spec_name = "" __pkg_name = "" - def __init__(self, arch, pkg): + def __init__(self, arch, pkg, ver): """ receive json from pypi.org """ - url = self.__url_template.format(pkg_name=pkg) + if not ver: + url = self.__url_template.format(pkg_name=pkg) + else: + url = self.__url_template_ver\ + .format( + pkg_name=pkg, + pkg_ver=ver + ) + print("url :[{}]".format(url)) resp = "" with urllib.request.urlopen(url) as u: self.__json = json.loads(u.read().decode('utf-8')) @@ -522,6 +531,7 @@ def build_spec(porter, output): def do_args(root): parser = argparse.ArgumentParser() + parser.add_argument("-v", "--version", help="Specify the python moduler version", type=str, default="") parser.add_argument("-s", "--spec", help="Create spec file", action="store_true") parser.add_argument("-R", "--requires", help="Get required python modules", action="store_true") parser.add_argument("-b", "--build", help="Build rpm package", action="store_true") @@ -538,9 +548,9 @@ def do_args(root): return parser -def porter_creator(t_str, arch, pkg): +def porter_creator(t_str, arch, pkg, ver): if t_str == "python": - return PyPorter(arch, pkg) + return PyPorter(arch, pkg, ver) return None @@ -552,8 +562,7 @@ if __name__ == "__main__": parser = do_args(dft_root_path) args = parser.parse_args() - - porter = porter_creator(args.type, args.arch, args.pkg) + porter = porter_creator(args.type, args.arch, args.pkg, args.version) if porter is None: print("Type %s is not supported now\n" % args.type) sys.exit(1) @@ -579,3 +588,4 @@ if __name__ == "__main__": download_source(porter, args.path) elif args.json: porter.store_json(args.path) +