Update setup.py
[PyWWW-Get.git] / pypkg-gen.py
blob73f2abe34c83a608ef53eead3c2fe2af185dfec9
1 #!/usr/bin/env python
3 '''
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the Revised BSD License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 Revised BSD License for more details.
12 Copyright 2011-2016 Game Maker 2k - https://github.com/GameMaker2k
13 Copyright 2011-2016 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
15 $FileInfo: pypkg-gen.py - Last Update: 6/1/2016 Ver. 0.2.0 RC 1 - Author: cooldude2k $
16 '''
18 from __future__ import absolute_import, division, print_function, unicode_literals;
19 import re, os, sys, time, platform, datetime, argparse, subprocess;
21 __version_info__ = (0, 2, 0, "rc1");
22 if(__version_info__[3]!=None):
23 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2])+"+"+str(__version_info__[3]);
24 if(__version_info__[3]==None):
25 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2]);
27 proname = "pypkg-gen";
28 prover = __version__;
29 profullname = proname+" "+prover;
31 def which_exec(execfile):
32 for path in os.environ["PATH"].split(":"):
33 if os.path.exists(path + "/" + execfile):
34 return path + "/" + execfile;
36 getlinuxdist = platform.linux_distribution();
37 setdistroname = "debian";
38 setdistrocname = "jessie";
39 if(getlinuxdist[0].lower()=="debian" or getlinuxdist[0].lower()=="ubuntu" or getlinuxdist[0].lower()=="linuxmint"):
40 setdistroname = getlinuxdist[0].lower();
41 setdistrocname = getlinuxdist[2].lower();
42 if(setdistrocname==""):
43 lsblocatout = which_exec("lsb_release");
44 pylsblistp = subprocess.Popen([lsblocatout, "-c"], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
45 pylsbout, pylsberr = pylsblistp.communicate();
46 if(sys.version[0]=="3"):
47 pylsbout = pylsbout.decode("utf-8");
48 pylsb_esc = re.escape("Codename:")+'([a-zA-Z\t+\s+]+)';
49 pylsbname = re.findall(pylsb_esc, pylsbout)[0].lower();
50 setdistrocname = pylsbname.strip();
51 if(getlinuxdist[0].lower()=="archlinux"):
52 setdistroname = getlinuxdist[0].lower();
53 setdistrocname = None;
54 parser = argparse.ArgumentParser(conflict_handler = "resolve", add_help = True);
55 parser.add_argument("-v", "--version", action = "version", version = profullname);
56 parser.add_argument("-s", "--source", default = os.path.realpath(os.getcwd()), help = "source dir");
57 parser.add_argument("-d", "--distro", default = setdistroname, help = "enter linux distribution name");
58 parser.add_argument("-c", "--codename", default = setdistrocname, help = "enter release code name");
59 parser.add_argument("-p", "--pyver", default = sys.version[0], help = "enter version of python to use");
60 getargs = parser.parse_args();
62 bashlocatout = which_exec("bash");
64 getargs.source = os.path.realpath(getargs.source);
65 getargs.codename = getargs.codename.lower();
66 getargs.distro = getargs.distro.lower();
68 if(getargs.pyver=="2"):
69 getpyver = "python2";
70 if(getargs.pyver=="3"):
71 getpyver = "python3";
72 if(getargs.pyver!="2" and getargs.pyver!="3"):
73 if(sys.version[0]=="2"):
74 getpyver = "python2";
75 if(sys.version[0]=="3"):
76 getpyver = "python3";
78 get_pkgbuild_dir = os.path.realpath(getargs.source+os.path.sep+"pkgbuild");
79 get_pkgbuild_dist_pre_list = [d for d in os.listdir(get_pkgbuild_dir) if os.path.isdir(os.path.join(get_pkgbuild_dir, d))];
80 get_pkgbuild_dist_list = [];
81 for dists in get_pkgbuild_dist_pre_list:
82 tmp_pkgbuild_python = os.path.realpath(get_pkgbuild_dir+os.path.sep+dists+os.path.sep+getpyver);
83 if(os.path.exists(tmp_pkgbuild_python) and os.path.isdir(tmp_pkgbuild_python)):
84 get_pkgbuild_dist_list.append(dists);
85 if(not getargs.distro in get_pkgbuild_dist_list):
86 print("Could not build for "+getargs.distro+" distro.");
87 sys.exit();
89 if(getargs.distro=="debian" or getargs.distro=="ubuntu" or getargs.distro=="linuxmint"):
90 pypkgpath = os.path.realpath(getargs.source+os.path.sep+"pkgbuild"+os.path.sep+getargs.distro+os.path.sep+getpyver+os.path.sep+"pydeb-gen.sh");
91 pypkgenlistp = subprocess.Popen([bashlocatout, pypkgpath, getargs.source, getargs.codename], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
92 pypkgenout, pypkgenerr = pypkgenlistp.communicate();
93 if(sys.version[0]=="3"):
94 pypkgenout = pypkgenout.decode("utf-8");
95 print(pypkgenout);
96 pypkgenlistp.wait();
98 if(getargs.distro=="archlinux"):
99 pypkgpath = os.path.realpath(getargs.source+os.path.sep+"pkgbuild"+os.path.sep+getargs.distro+os.path.sep+getpyver+os.path.sep+"pypac-gen.sh");
100 pypkgenlistp = subprocess.Popen([bashlocatout, pypkgpath, getargs.source, getargs.codename], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
101 pypkgenout, pypkgenerr = pypkgenlistp.communicate();
102 if(sys.version[0]=="3"):
103 pypkgenout = pypkgenout.decode("utf-8");
104 print(pypkgenout);
105 pypkgenlistp.wait();