Yet another small update to PyPKG-Gen/PKGBuild.
[PyMotherless.git] / pypkg-gen.py
blobb250723c44943fba35e17874c4f27b0bcfe394bc
1 '''
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the Revised BSD License.
5 This program is distributed in the hope that it will be useful,
6 but WITHOUT ANY WARRANTY; without even the implied warranty of
7 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 Revised BSD License for more details.
10 Copyright 2011-2016 Game Maker 2k - https://github.com/GameMaker2k
11 Copyright 2011-2016 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
13 $FileInfo: pypkg-gen.py - Last Update: 2/15/2016 Ver. 0.1.7 RC 1 - Author: cooldude2k $
14 '''
16 from __future__ import absolute_import, division, print_function, unicode_literals;
17 import re, os, sys, time, platform, datetime, argparse, subprocess;
19 __version_info__ = (0, 1, 7, "rc1");
20 if(__version_info__[3]!=None):
21 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2])+"+"+str(__version_info__[3]);
22 if(__version_info__[3]==None):
23 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2]);
25 proname = "pypkg-gen";
26 prover = __version__;
27 profullname = proname+" "+prover;
29 getlinuxdist = platform.linux_distribution();
30 setdistroname = "debian";
31 setdistrocname = "jessie";
32 if(getlinuxdist[0].lower()=="debian" or getlinuxdist[0].lower()=="ubuntu" or getlinuxdist[0].lower()=="linuxmint"):
33 setdistroname = getlinuxdist[0].lower();
34 setdistrocname = getlinuxdist[2].lower();
35 if(getlinuxdist[0].lower()=="archlinux"):
36 setdistroname = getlinuxdist[0].lower();
37 setdistrocname = None;
38 parser = argparse.ArgumentParser(conflict_handler = "resolve", add_help = True);
39 parser.add_argument("-v", "--version", action = "version", version = profullname);
40 parser.add_argument("-s", "--source", default = os.path.realpath(os.getcwd()), help = "source dir");
41 parser.add_argument("-d", "--distro", default = setdistroname, help = "enter linux distribution name");
42 parser.add_argument("-c", "--codename", default = setdistrocname, help = "enter release code name");
43 parser.add_argument("-p", "--pyver", default = sys.version[0], help = "enter version of python to use");
44 getargs = parser.parse_args();
46 def which_exec(execfile):
47 for path in os.environ["PATH"].split(":"):
48 if os.path.exists(path + "/" + execfile):
49 return path + "/" + execfile;
50 bashlocatout = which_exec("bash");
52 getargs.source = os.path.realpath(getargs.source);
53 getargs.codename = getargs.codename.lower();
54 getargs.distro = getargs.distro.lower();
56 if(getargs.pyver=="2"):
57 getpyver = "python2";
58 if(getargs.pyver=="3"):
59 getpyver = "python3";
60 if(getargs.pyver!="2" and getargs.pyver!="3"):
61 if(sys.version[0]=="2"):
62 getpyver = "python2";
63 if(sys.version[0]=="3"):
64 getpyver = "python3";
66 get_pkgbuild_dir = os.path.realpath(getargs.source+os.path.sep+"pkgbuild");
67 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))];
68 get_pkgbuild_dist_list = [];
69 for dists in get_pkgbuild_dist_pre_list:
70 tmp_pkgbuild_python = os.path.realpath(get_pkgbuild_dir+os.path.sep+dists+os.path.sep+getpyver);
71 if(os.path.exists(tmp_pkgbuild_python) and os.path.isdir(tmp_pkgbuild_python)):
72 get_pkgbuild_dist_list.append(dists);
73 if(not getargs.distro in get_pkgbuild_dist_list):
74 print("Could not build for "+getargs.distro+" distro.");
75 sys.exit();
77 if(getargs.distro=="debian" or getargs.distro=="ubuntu" or getargs.distro=="linuxmint"):
78 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");
79 pypkgenlistp = subprocess.Popen([bashlocatout, pypkgpath, getargs.source, getargs.codename], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
80 pypkgenout, pypkgenerr = pypkgenlistp.communicate();
81 if(sys.version[0]=="3"):
82 pypkgenout = pypkgenout.decode("utf-8");
83 print(pypkgenout);
84 pypkgenlistp.wait();
86 if(getargs.distro=="archlinux"):
87 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");
88 pypkgenlistp = subprocess.Popen([bashlocatout, pypkgpath, getargs.source, getargs.codename], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
89 pypkgenout, pypkgenerr = pypkgenlistp.communicate();
90 if(sys.version[0]=="3"):
91 pypkgenout = pypkgenout.decode("utf-8");
92 print(pypkgenout);
93 pypkgenlistp.wait();