mirror of
https://github.com/EDCD/EDDN.git
synced 2025-04-28 06:02:13 +03:00
setup.py: Updated to Python3 / pathlib paradigms
This commit is contained in:
parent
d6fa3fe123
commit
f9d423f4a6
83
setup.py
83
setup.py
@ -1,15 +1,17 @@
|
|||||||
"""Setup for EDDN software."""
|
"""Setup for EDDN software."""
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
import setup_env
|
|
||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
|
import setup_env
|
||||||
|
|
||||||
VERSIONFILE = "src/eddn/conf/Version.py"
|
VERSIONFILE = "src/eddn/conf/Version.py"
|
||||||
verstr = "unknown"
|
verstr = "unknown"
|
||||||
try:
|
try:
|
||||||
@ -64,9 +66,9 @@ if setup_env.EDDN_ENV == 'live':
|
|||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
# Location of start-eddn-service script and its config file
|
# Location of start-eddn-service script and its config file
|
||||||
START_SCRIPT_BIN = f'{os.environ["HOME"]}/.local/bin'
|
START_SCRIPT_BIN = pathlib.Path(f'{os.environ["HOME"]}/.local/bin')
|
||||||
# Location of web files
|
# Location of web files
|
||||||
SHARE_EDDN_FILES = f'{os.environ["HOME"]}/.local/share/eddn/{setup_env.EDDN_ENV}'
|
SHARE_EDDN_FILES = pathlib.Path(f'{os.environ["HOME"]}/.local/share/eddn/{setup_env.EDDN_ENV}')
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='eddn',
|
name='eddn',
|
||||||
@ -117,20 +119,18 @@ setup(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def open_file_perms_recursive(dirname: str) -> None:
|
def open_file_perms_recursive(dirname: pathlib.Path) -> None:
|
||||||
"""Open up file perms on the given directory and its contents."""
|
"""Open up file perms on the given directory and its contents."""
|
||||||
print(f'open_file_perms_recursive: {dirname}')
|
print(f'open_file_perms_recursive: {dirname}')
|
||||||
names = os.listdir(dirname)
|
|
||||||
for name in names:
|
for name in dirname.glob('*'):
|
||||||
n = f'{dirname}/{name}'
|
print(f'open_file_perms_recursive: {name}')
|
||||||
print(f'open_file_perms_recursive: {n}')
|
if name.is_dir():
|
||||||
if (os.path.isdir(n)):
|
name.chmod(0o755)
|
||||||
os.chmod(n, 0o755)
|
open_file_perms_recursive(name)
|
||||||
# Recurse
|
|
||||||
open_file_perms_recursive(n)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
os.chmod(n, 0o644)
|
name.chmod(0o644)
|
||||||
|
|
||||||
|
|
||||||
# Ensure the systemd-required start files are in place
|
# Ensure the systemd-required start files are in place
|
||||||
@ -138,34 +138,22 @@ print("""
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
Ensuring start script and its config file are in place...
|
Ensuring start script and its config file are in place...
|
||||||
""")
|
""")
|
||||||
old_cwd = os.getcwd()
|
|
||||||
if not os.path.isdir(START_SCRIPT_BIN):
|
|
||||||
# We're still using Python 2.7, so no pathlib
|
|
||||||
os.chdir('/')
|
|
||||||
for pc in START_SCRIPT_BIN[1:].split('/'):
|
|
||||||
try:
|
try:
|
||||||
os.mkdir(pc)
|
START_SCRIPT_BIN.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||||
|
|
||||||
except OSError:
|
except Exception as e:
|
||||||
pass
|
print(f"{START_SCRIPT_BIN} can't be created, aborting!!!\n{e!r}")
|
||||||
|
|
||||||
os.chdir(pc)
|
|
||||||
|
|
||||||
if not os.path.isdir(START_SCRIPT_BIN):
|
|
||||||
print(f"{START_SCRIPT_BIN} can't be created, aborting!!!")
|
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
os.chdir(old_cwd)
|
|
||||||
|
|
||||||
shutil.copy(
|
shutil.copy(
|
||||||
f'systemd/eddn_{setup_env.EDDN_ENV}_config',
|
f'systemd/eddn_{setup_env.EDDN_ENV}_config',
|
||||||
f'{START_SCRIPT_BIN}/eddn_{setup_env.EDDN_ENV}_config'
|
START_SCRIPT_BIN / f'eddn_{setup_env.EDDN_ENV}_config'
|
||||||
)
|
)
|
||||||
# NB: We copy to a per-environment version so that, e.g.live use won't break
|
# NB: We copy to a per-environment version so that, e.g.live use won't break
|
||||||
# due to changes in the other environments.
|
# due to changes in the other environments.
|
||||||
shutil.copy(
|
shutil.copy(
|
||||||
'systemd/start-eddn-service',
|
'systemd/start-eddn-service',
|
||||||
f'{START_SCRIPT_BIN}/start-eddn-{setup_env.EDDN_ENV}-service'
|
START_SCRIPT_BIN / f'start-eddn-{setup_env.EDDN_ENV}-service'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Ensure the service log file archiving script is in place
|
# Ensure the service log file archiving script is in place
|
||||||
@ -184,38 +172,28 @@ print(f"""
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
Ensuring {SHARE_EDDN_FILES} exists...
|
Ensuring {SHARE_EDDN_FILES} exists...
|
||||||
""")
|
""")
|
||||||
old_cwd = os.getcwd()
|
|
||||||
if not os.path.isdir(SHARE_EDDN_FILES):
|
|
||||||
# We're still using Python 2.7, so no pathlib
|
|
||||||
os.chdir('/')
|
|
||||||
for pc in SHARE_EDDN_FILES[1:].split('/'):
|
|
||||||
try:
|
try:
|
||||||
os.mkdir(pc)
|
SHARE_EDDN_FILES.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||||
|
|
||||||
except OSError:
|
except Exception as e:
|
||||||
pass
|
print(f"{SHARE_EDDN_FILES} can't be created, aborting!!!\n{e!r}")
|
||||||
|
|
||||||
os.chdir(pc)
|
|
||||||
|
|
||||||
if not os.path.isdir(SHARE_EDDN_FILES):
|
|
||||||
print(f"{SHARE_EDDN_FILES} can't be created, aborting!!!")
|
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
os.chdir(old_cwd)
|
|
||||||
print("""
|
print("""
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
Ensuring latest monitor files are in place...
|
Ensuring latest monitor files are in place...
|
||||||
""")
|
""")
|
||||||
# Copy the monitor (Web page) files
|
# Copy the monitor (Web page) files
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(f'{SHARE_EDDN_FILES}/monitor')
|
shutil.rmtree(SHARE_EDDN_FILES / 'monitor')
|
||||||
|
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
'contrib/monitor',
|
'contrib/monitor',
|
||||||
f'{SHARE_EDDN_FILES}/monitor',
|
SHARE_EDDN_FILES / 'monitor',
|
||||||
# Not in Python 2.7
|
copy_function=shutil.copyfile, # type: ignore
|
||||||
# copy_function=shutil.copyfile,
|
|
||||||
)
|
)
|
||||||
# And a copy of the schemas too
|
# And a copy of the schemas too
|
||||||
print("""
|
print("""
|
||||||
@ -223,16 +201,15 @@ print("""
|
|||||||
Ensuring latest schema files are in place for web access...
|
Ensuring latest schema files are in place for web access...
|
||||||
""")
|
""")
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(f'{SHARE_EDDN_FILES}/schemas')
|
shutil.rmtree(SHARE_EDDN_FILES / 'schemas')
|
||||||
|
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
'schemas',
|
'schemas',
|
||||||
f'{SHARE_EDDN_FILES}/schemas',
|
SHARE_EDDN_FILES / 'schemas',
|
||||||
# Not in Python 2.7
|
copy_function=shutil.copyfile, # type: ignore
|
||||||
# copy_function=shutil.copyfile,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("""
|
print("""
|
||||||
@ -243,7 +220,7 @@ os.chmod(SHARE_EDDN_FILES, 0o755)
|
|||||||
open_file_perms_recursive(SHARE_EDDN_FILES)
|
open_file_perms_recursive(SHARE_EDDN_FILES)
|
||||||
|
|
||||||
# You still need to make an override config file
|
# You still need to make an override config file
|
||||||
if not os.path.isfile(f'{SHARE_EDDN_FILES}/config.json'):
|
if not (SHARE_EDDN_FILES / 'config.json').is_file():
|
||||||
shutil.copy('docs/config-EXAMPLE.json', SHARE_EDDN_FILES)
|
shutil.copy('docs/config-EXAMPLE.json', SHARE_EDDN_FILES)
|
||||||
print(f"""
|
print(f"""
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user