Skip to content

Commit

Permalink
Merge pull request #5 from kennedy0/linux
Browse files Browse the repository at this point in the history
Linux
  • Loading branch information
kennedy0 committed Feb 6, 2021
2 parents 839251b + ada8826 commit c504be5
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.py[ci]
/dist/
/build-venv/
/build/
/PolarBear.spec
2 changes: 1 addition & 1 deletion __version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.0"
__version__ = "1.4.0"
2 changes: 0 additions & 2 deletions config/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ def get_icon():


ICON_FILE = get_icon()


27 changes: 27 additions & 0 deletions tools/archive_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import re
import platform
import sys
import tarfile
import zipfile


Expand All @@ -13,6 +15,15 @@ def create_archive(folder_path: str) -> int:
return 1

version = get_version()
if platform.system() == "Windows":
return create_archive_windows(folder_path, version)
elif platform.system() == "Linux":
return create_archive_linux(folder_path, version)
else:
raise NotImplementedError(f"OS not supported: {platform.system()}")


def create_archive_windows(folder_path: str, version: str) -> int:
zip_file = f"{folder_path}_{version}_win.zip"

if os.path.isfile(zip_file):
Expand All @@ -28,6 +39,22 @@ def create_archive(folder_path: str) -> int:
return 0


def create_archive_linux(folder_path: str, version: str) -> int:
tar_file = f"{folder_path}_{version}_linux.tar.gz"

if os.path.isfile(tar_file):
print(f"{tar_file} already exists.")
return 1

with tarfile.open(tar_file, 'w:gz') as tf:
for root, dirs, files in os.walk(folder_path):
for file in files:
full_path = os.path.join(root, file)
rel_path = os.path.relpath(full_path, folder_path)
tf.add(full_path, arcname=rel_path)
return 0


def get_version() -> str:
tools_dir = os.path.abspath(os.path.dirname(__file__))
project_dir = os.path.dirname(tools_dir)
Expand Down
47 changes: 47 additions & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
OLD_CWD=$(pwd)
TOOLS_DIR=$(dirname "$0")
PROJECT_DIR="$TOOLS_DIR/.."
RESOURCES_DIR="$PROJECT_DIR/resources"
ICON_FILE="$RESOURCES_DIR/icon.png"
DIST_FOLDER="$PROJECT_DIR/dist"
PB_BUILD="$DIST_FOLDER/PolarBear"
ARCHIVE_SCRIPT="$TOOLS_DIR/archive_build.py"

# Setup
cd $PROJECT_DIR
rm -rf "$DIST_FOLDER"

# Create venv
echo "Creating virtual environment..."
python3 -m venv build-venv
. ./build-venv/bin/activate
echo "Installing requirements..."
python3 -m pip install -r "./requirements.txt"
python3 -m pip install pyinstaller==4.2

# Build
echo "Building PolarBear..."
pyinstaller \
-y \
--onedir \
--noconsole \
--name PolarBear \
--icon=$ICON_FILE \
--add-data="$PROJECT_DIR/config/presets/*:config/presets" \
--add-data="$PROJECT_DIR/config/themes/*:config/themes" \
--add-data="$PROJECT_DIR/resources/*:resources" \
main.py

## Archive build
echo "Archiving build..."
python $ARCHIVE_SCRIPT $PB_BUILD

# Cleanup
echo Cleaning up...
rm -rf "$PROJECT_DIR/build"
rm -rf "$PROJECT_DIR/build-venv"
rm "$PROJECT_DIR/PolarBear.spec"
cd "$OLD_CWD"

echo "Build complete."
8 changes: 5 additions & 3 deletions windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def on_record_clicked(self):

# Start ffmpeg subprocess
ffmpeg_str = self.build_ffmpeg_cmd(file=file_name)
log_file = self.create_log_file(video_file_path=file_name)
log_file = self.create_log_file(video_file_path=file_name, command_string=ffmpeg_str)

if os.name == "nt":
creation_flags = subprocess.CREATE_NO_WINDOW
Expand Down Expand Up @@ -334,15 +334,17 @@ def get_output_extension(self) -> str:
return extension

@staticmethod
def create_log_file(video_file_path: str) -> TextIO:
def create_log_file(video_file_path: str, command_string: str) -> TextIO:
try:
os.makedirs(settings.LOG_PATH)
except OSError:
pass
video_file_name = os.path.basename(video_file_path)
log_file_name = datetime.datetime.now().strftime(f"%Y%m%d_%H%M%S_{video_file_name}.log")
log_file_path = os.path.join(settings.LOG_PATH, log_file_name)
return open(log_file_path, 'w')
with open(log_file_path, 'w') as fp:
fp.write(f"{command_string}\n\n")
return open(log_file_path, 'a')

def resizeEvent(self, a0: QtGui.QResizeEvent):
super().resizeEvent(a0)
Expand Down
10 changes: 9 additions & 1 deletion windows/options_window.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import copy
import os
import platform
import subprocess

from PyQt5 import QtCore, QtWidgets

Expand Down Expand Up @@ -44,7 +46,13 @@ def _init_callbacks(self):

@staticmethod
def on_open_presets_clicked():
os.startfile(settings.PRESETS_PATH)
if platform.system() == "Windows":
os.startfile(settings.PRESETS_PATH)
elif platform.system() == "Linux":
proc = subprocess.Popen(["xdg-open", settings.PRESETS_PATH])
proc.communicate()
else:
raise NotImplementedError(f"OS not supported: {platform.system()}")

def on_refresh_presets(self):
self.update_preset_widget()
Expand Down

0 comments on commit c504be5

Please sign in to comment.