Skip to content

Commit 3d6539c

Browse files
authored
added Python Compile
1 parent 578044d commit 3d6539c

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

helperfunctions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
telegraph.create_account(short_name='file-converter')
1313

1414

15+
# pyinstaller compile
16+
def pyinstallcommand(message,inputt):
17+
ofold = str(message.id) + "/"
18+
tfold = str(message.id) + "t/"
19+
basename = inputt.split("/")[-1].split(".")[0]
20+
out = ofold + basename
21+
temp = basename + ".spec"
22+
cmd = f'pyinstaller --onefile --distpath {ofold} --workpath {tfold} {inputt}'
23+
return cmd, out, ofold, tfold, temp
24+
25+
1526
# g++ compile command
1627
def gppcommand(inputt):
1728
filename = inputt.split("/")[-1].split(".")[0]

main.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,29 @@ def compile(message,oldm):
541541
else:
542542
app.send_message(message.chat.id,"__Error while Compiling__", reply_to_message_id=message.id)
543543

544+
545+
# python compile
546+
if ext.upper() == "PY":
547+
cmd, output, ofold, tfold, temp = helperfunctions.pyinstallcommand(message,file)
548+
os.system(cmd)
549+
os.remove(file)
550+
if os.path.exists(output) and os.path.getsize(output) > 0:
551+
app.send_document(message.chat.id,document=output, caption="__Linux Executable__", force_document=True, reply_to_message_id=message.id)
552+
os.remove(output)
553+
else:
554+
app.send_message(message.chat.id,"__Error while Compiling__", reply_to_message_id=message.id)
555+
556+
if os.path.exists(temp):
557+
os.remove(temp)
558+
if os.path.exists(ofold):
559+
shutil.rmtree(ofold)
560+
if os.path.exists(tfold):
561+
shutil.rmtree(tfold)
562+
563+
564+
# not supported yet
544565
else:
545-
app.send_message(message.chat.id,"__At this time Compilation only supports from JAR, C and CPP Files__", reply_to_message_id=message.id)
566+
app.send_message(message.chat.id,"__At this time Compilation only supports from JAR, PY, C and CPP Files__", reply_to_message_id=message.id)
546567

547568

548569
# delete message

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ Pillow
1414
bs4
1515
ttconv
1616
py2many
17-
pyzbar
17+
pyzbar
18+
pyinstaller

0 commit comments

Comments
 (0)