Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag to open report.pdf after successfull compilation #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
import platform
import os
import sysconfig
import argparse
import webbrowser

DOCKER_IMAGE = "ghcr.io/fcsan-bsuir/bsuir_tex:main"
DOCKER_IMAGE = 'ghcr.io/fcsan-bsuir/bsuir_tex:main'
REPORT_PDF_PATH = os.path.join(os.getcwd(), 'src', 'report.pdf')

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--open',
action='store_true',
required=False,
default=False,
help='Open report.pdf after successfull compilation')
FLAGS = parser.parse_args()

system = platform.system()

compile_cmd = 'make -j4 -C "src" all'
Expand All @@ -16,13 +27,17 @@ def main():
docker_platform_flag = '--platform linux/amd64' if sysconfig.get_platform().split("-")[-1].lower() == 'arm64' else ''
run_docker_cmd = f'docker run {docker_platform_flag} -i --rm -v "{os.getcwd()}:/test" -w /test {DOCKER_IMAGE}'

shell_and_symbol = ";" if system == "Windows" else "&&"
shell_and_symbol = ';' if system == 'Windows' else '&&'

cmd = ' '.join([run_docker_cmd, compile_cmd, shell_and_symbol, clean_cmd])

print(f'Running command:\n{cmd}')

cmd = " ".join([run_docker_cmd, compile_cmd, shell_and_symbol, clean_cmd])
compilation_exit_code = subprocess.run(cmd, shell=True).returncode

print(f"Running command:\n{cmd}")
if compilation_exit_code == 0 and FLAGS.open:
webbrowser.open_new(rf'file://{REPORT_PDF_PATH}')

subprocess.run(cmd, shell=True)

if __name__=="__main__":
if __name__=='__main__':
main()