Skip to content

Commit

Permalink
pycompile
Browse files Browse the repository at this point in the history
add scrips for pycompile task in vscode


.
  • Loading branch information
croghostrider committed Mar 20, 2022
1 parent c2436f8 commit 5a315cc
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ __pycache__/
*.py[cod]
*$py.class
output/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
16 changes: 16 additions & 0 deletions .vscode/compilers/fixes/pycompile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off

net session >nul 2>&1

if %errorLevel% == 0 (
echo Pip, setuptools and pyinstaller upgrading
pip install --upgrade pip
pip install --upgrade setuptools
pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
echo Now you can run pyinstaller
) else (
echo You need to run this script as admin
)

pause
17 changes: 17 additions & 0 deletions .vscode/compilers/fixes/pycompile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

chckusr=$(id -u);

if [ $chckusr = "0" ] ; then
echo "Pip, setuptools and pyinstaller upgrading";
pip install --upgrade pip;
pip install --upgrade setuptools;
pip uninstall pyinstaller;
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz;
echo "Now you can run pyinstaller";
exit;
else
echo "You need to run this script as root";
fi

read -p "Press enter to exit";
47 changes: 47 additions & 0 deletions .vscode/compilers/pycompile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

import os
import sys
import shutil
import subprocess

# ARGS
fileDirname = sys.argv[1]
fileBasename = sys.argv[2]
workspaceFolder = sys.argv[3]

# TRANSFORMATION
relativeFileDirname = fileDirname[len(workspaceFolder)+1:]
fileBasenameNoExtension = "".join(fileBasename.rsplit(".py", 1))
distpath = os.path.join(workspaceFolder, "output", relativeFileDirname)

# COMMAND GENERATOR
def construct():
COMMAND = []
COMMAND.append("pyinstaller")
COMMAND.append("--onefile")
COMMAND.append("--clean")
COMMAND.append("--noconsole")
COMMAND.append("--distpath")
COMMAND.append(distpath)
for file in os.listdir(fileDirname):
if file.endswith(".ico"):
COMMAND.append("--icon")
COMMAND.append(os.path.join(fileDirname, file))
break
COMMAND.append(fileBasename)
return COMMAND

# CLEANER
def clean():
path = os.path.join(fileDirname, "__pycache__")
shutil.rmtree(path)
path = os.path.join(fileDirname, "build")
shutil.rmtree(path)
path = os.path.join(fileDirname, "%s.spec" % fileBasenameNoExtension)
os.remove(path)

if __name__ == "__main__":
COMMAND = construct()
subprocess.check_call(COMMAND, cwd=fileDirname)
clean()
54 changes: 54 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "compile python via pyinstaller",
"type": "shell",
"linux": {
"command": "python ${workspaceFolder}/.vscode/compilers/pycompile.py ${fileDirname} ${fileBasename} ${workspaceFolder}"
},
"windows": {
"command": "python ${workspaceFolder}\\.vscode\\compilers\\pycompile.py ${fileDirname} ${fileBasename} ${workspaceFolder}"
},
"group": "build",
"presentation": {
"reveal": "silent",
"focus": false,
"clear": true
},
"problemMatcher": []
},
{
"label": "run python file",
"type": "shell",
"linux": {
"command": "python ${file}"
},
"windows": {
"command": "python ${file}"
},
"group": "test",
"presentation": {
"reveal": "always",
"focus": false,
"clear": true
}
},
{
"label": "test script",
"type": "shell",
"linux": {
"command": "python ${workspaceFolder}/.vscode/testers/testSite.py ${file} ${file}.test ${fileExtname} ${fileDirname} ${workspaceFolder} ${fileBasename}"
},
"windows": {
"command": "python ${workspaceFolder}/.vscode/testers/testSite.py ${file} ${file}.test ${fileExtname} ${fileDirname} ${workspaceFolder} ${fileBasename}"
},
"group": "test",
"presentation": {
"reveal": "always",
"focus": false,
"clear": true
}
}
]
}
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
Release
2 changes: 1 addition & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def select_destinationfolder():
def list_files():
# files = [f for f in os.listdir(source_entry.get()) if os.path.isfile(f)]
start_button.state(["disabled"])
start_button.update()
filelist = []
for filename in os.listdir(source_entry.get()):
if filename.startswith("sps_") and (filename.endswith(".zip")):
filelist.append(filename)
for filename in filelist:
print(filename)
lox_backup(filename, source_entry.get(), destination_entry.get())

# root window
Expand Down

0 comments on commit 5a315cc

Please sign in to comment.