-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsetup.py
executable file
·46 lines (34 loc) · 1.08 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
from __future__ import annotations
import os
import sys
from pathlib import Path
from subprocess import run, STDOUT
from setuptools import setup
MODULE_NAME = 'fact_helper_file'
MODULE_DIR = Path(__file__).parent / MODULE_NAME
MIME_DIR = MODULE_DIR / 'mime'
BIN_DIR = MODULE_DIR / 'bin'
class OperateInDirectory:
def __init__(self, target_directory: str | Path):
self._current_working_dir = None
self._target_directory = target_directory
def __enter__(self):
self._current_working_dir = Path.cwd()
os.chdir(self._target_directory)
def __exit__(self, *_):
os.chdir(self._current_working_dir)
BIN_DIR.mkdir(exist_ok=True)
with OperateInDirectory(MIME_DIR):
process = run(
'(cat custom_* > custommime)'
' && file -C -m custommime'
' && mv -f custommime.mgc ../bin/'
' && rm custommime',
shell=True,
stderr=STDOUT,
)
if process.returncode != 0:
sys.stderr.write(f'Failed to properly compile magic file\n{process.stdout}\n')
sys.exit(1)
setup()