Update pycatfile.py
[PyCatFile.git] / mkcatfilebundle.py
blobd562fa0de439f4aab6c32fdc0478f0cee9757857
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 '''
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the Revised BSD License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 Revised BSD License for more details.
13 Copyright 2018-2024 Cool Dude 2k - http://idb.berlios.de/
14 Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15 Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
17 $FileInfo: mkbundle.py - ast Update: 10/22/2024 Ver. 0.14.2 RC 1 - Author: cooldude2k $
18 '''
20 import os
21 import sys
22 import shutil
23 import subprocess
24 import tempfile
25 import subprocess
26 import platform
28 tempdir = tempfile.gettempdir()
29 if(os.sep == "\\"):
30 tempdir = tempdir.replace(os.sep, "/")
31 elif(os.path.sep == "\\"):
32 tempdir = tempdir.replace(os.path.sep, "/")
34 pyimplementation = platform.python_implementation()
35 pylist = ['CPython', 'IronPython', 'PyPy', 'CPython2', 'CPython3', 'Python2',
36 'Python3', 'Python', 'PyPy2', 'PyPy3', 'IronPython2', 'IronPython3']
38 if(len(sys.argv) > 1):
39 if(sys.argv[1] in pylist):
40 if(sys.argv[1] == "CPython"):
41 pystring = "python3"
42 elif(sys.argv[1] == "IronPython"):
43 pystring = "ipy2"
44 elif(sys.argv[1] == "PyPy"):
45 pystring = "pypy3"
46 elif(sys.argv[1] == "CPython2"):
47 pystring = "python2"
48 elif(sys.argv[1] == "CPython3"):
49 pystring = "python3"
50 elif(sys.argv[1] == "Python2"):
51 pystring = "python2"
52 elif(sys.argv[1] == "Python3"):
53 pystring = "python3"
54 elif(sys.argv[1] == "PyPy2"):
55 pystring = "pypy"
56 elif(sys.argv[1] == "PyPy3"):
57 pystring = "pypy3"
58 elif(sys.argv[1] == "IronPython2"):
59 pystring = "ipy2"
60 elif(sys.argv[1] == "IronPython3"):
61 pystring = "ipy3"
62 else:
63 sys.exit()
64 else:
65 sys.exit()
67 if(len(sys.argv) < 1):
68 if(pyimplementation == "CPython"):
69 pystring = "python"+str(sys.version_info[0])
70 elif(pyimplementation == "IronPython"):
71 pystring = "ipy"+str(sys.version_info[0])
72 elif(pyimplementation == "PyPy"):
73 if(sys.version_info[0] == 2):
74 pystring = "pypy"
75 elif(sys.version_info[0] == 3):
76 pystring = "pypy"+str(sys.version_info[0])
77 else:
78 sys.exit(1)
79 else:
80 sys.exit(1)
82 if(len(sys.argv) > 2):
83 if(os.path.exists("./"+sys.argv[2]) and os.path.isfile("./"+sys.argv[2])):
84 infile = sys.argv[2]
85 outfilebin = os.path.splitext(infile)[0]
86 outfilezip = outfilebin+".zip"
87 elif(os.path.exists("./"+sys.argv[2]) and os.path.isdir("./"+sys.argv[2])):
88 infile = "catfile.py"
89 outfilebin = os.path.splitext(infile)[0]
90 outfilezip = outfilebin+".zip"
91 else:
92 infile = "catfile.py"
93 outfilebin = os.path.splitext(infile)[0]
94 outfilezip = outfilebin+".zip"
95 else:
96 infile = "catfile.py"
97 outfilebin = os.path.splitext(infile)[0]
98 outfilezip = outfilebin+".zip"
99 if(os.path.exists(tempdir+"/pybundle") and os.path.isfile(tempdir+"/pybundle")):
100 os.unlink(tempdir+"/pybundle")
101 if(os.path.exists(tempdir+"/pybundle") and os.path.isdir(tempdir+"/pybundle")):
102 shutil.rmtree(tempdir+"/pybundle")
103 os.mkdir(tempdir+"/pybundle")
104 if(os.path.exists(tempdir+"/pybundle/__main__.py") and os.path.isfile(tempdir+"/pybundle/__main__.py")):
105 os.unlink(tempdir+"/pybundle/__main__.py")
106 if(os.path.exists(tempdir+"/pybundle/__main__.py") and os.path.isdir(tempdir+"/pybundle/__main__.py")):
107 shutil.rmtree(tempdir+"/pybundle/__main__.py")
108 shutil.copy2("./"+infile, tempdir+"/pybundle/__main__.py")
109 if(os.path.exists(tempdir+"/pybundle/pycatfile.py") and os.path.isfile(tempdir+"/pybundle/pycatfile.py")):
110 os.unlink(tempdir+"/pybundle/pycatfile.py")
111 if(os.path.exists(tempdir+"/pybundle/pycatfile.py") and os.path.isdir(tempdir+"/pybundle/pycatfile.py")):
112 shutil.rmtree(tempdir+"/pybundle/pycatfile.py")
113 shutil.copy2("./pycatfile.py", tempdir+"/pybundle/pycatfile.py")
114 if(os.path.exists(tempdir+"/"+outfilezip) and os.path.isfile(tempdir+"/"+outfilezip)):
115 os.unlink(tempdir+"/"+outfilezip)
116 if(os.path.exists(tempdir+"/"+outfilezip) and os.path.isdir(tempdir+"/"+outfilezip)):
117 shutil.rmtree(tempdir+"/"+outfilezip)
118 shutil.make_archive(tempdir+"/"+outfilebin, "zip", tempdir+"/pybundle")
119 if(os.path.exists(tempdir+"/pybundle/"+outfilezip) and os.path.isfile(tempdir+"/pybundle/"+outfilezip)):
120 os.unlink(tempdir+"/pybundle/"+outfilezip)
121 if(os.path.exists(tempdir+"/pybundle/"+outfilezip) and os.path.isdir(tempdir+"/pybundle/"+outfilezip)):
122 shutil.rmtree(tempdir+"/pybundle/"+outfilezip)
123 shutil.move(tempdir+"/"+outfilezip, tempdir+"/pybundle/"+outfilezip)
124 if(os.path.exists(tempdir+"/pybundle/"+outfilebin) and os.path.isfile(tempdir+"/pybundle/"+outfilebin)):
125 os.unlink(tempdir+"/pybundle/"+outfilebin)
126 if(os.path.exists(tempdir+"/pybundle/"+outfilebin) and os.path.isdir(tempdir+"/pybundle/"+outfilebin)):
127 shutil.rmtree(tempdir+"/pybundle/"+outfilebin)
128 mkbstring = "#!/usr/bin/env "+pystring+"\n\n"
129 mkbfp = open(tempdir+"/pybundle/"+outfilebin, "wb+")
130 mkbfp.write(mkbstring.encode())
131 zipfp = open(tempdir+"/pybundle/"+outfilezip, "rb")
132 mkbfp.write(zipfp.read())
133 mkbfp.close()
134 zipfp.close()
135 shutil.rmtree("./bundle/"+pystring)
136 os.mkdir("./bundle/"+pystring)
137 shutil.move(tempdir+"/pybundle/"+outfilebin,
138 "./bundle/"+pystring+"/"+outfilebin)
139 os.chmod("./bundle/"+pystring+"/"+outfilebin, 0o755)
140 shutil.rmtree(tempdir+"/pybundle")
141 oldpath = os.getcwd()
142 os.chdir("./bundle/"+pystring)
143 curscrpath = os.path.dirname("./"+outfilebin)
144 if(curscrpath == ""):
145 curscrpath = "."
146 if(os.sep == "\\"):
147 curscrpath = curscrpath.replace(os.sep, "/")
148 elif(os.path.sep == "\\"):
149 curscrpath = curscrpath.replace(os.path.sep, "/")
150 curscrpath = curscrpath+os.path.sep
151 scrfile = curscrpath+outfilebin
153 if(os.path.exists(scrfile) and os.path.isfile(scrfile) and infile=="catfile.py"):
154 scrcmd = subprocess.Popen([sys.executable, scrfile, "mksymlinks"]);
155 scrcmd.wait();
157 os.chdir(oldpath)