mirror of
https://github.com/EDCD/EDDN.git
synced 2025-06-14 14:22:18 +03:00
setup.py: General python3, flake8, mypy
This commit is contained in:
parent
3df5c52d53
commit
0641bf3f24
94
setup.py
94
setup.py
@ -1,3 +1,4 @@
|
|||||||
|
"""Setup for EDDN software."""
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -6,6 +7,9 @@ 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
|
||||||
|
|
||||||
VERSIONFILE = "src/eddn/conf/Version.py"
|
VERSIONFILE = "src/eddn/conf/Version.py"
|
||||||
verstr = "unknown"
|
verstr = "unknown"
|
||||||
try:
|
try:
|
||||||
@ -14,12 +18,12 @@ try:
|
|||||||
mo = re.search(VSRE, verstrline, re.M)
|
mo = re.search(VSRE, verstrline, re.M)
|
||||||
if mo:
|
if mo:
|
||||||
verstr = mo.group(1)
|
verstr = mo.group(1)
|
||||||
|
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
print "unable to find version in %s" % (VERSIONFILE,)
|
print(f'unable to find version in {VERSIONFILE}')
|
||||||
raise RuntimeError("if %s exists, it is required to be well-formed" % (VERSIONFILE,))
|
raise RuntimeError(f'if {VERSIONFILE} exists, it is required to be well-formed')
|
||||||
|
|
||||||
# Read environment-specific settings
|
# Read environment-specific settings
|
||||||
import setup_env
|
|
||||||
|
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
@ -60,9 +64,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='%s/.local/bin' % ( os.environ['HOME'] )
|
START_SCRIPT_BIN = f'{os.environ["HOME"]}/.local/bin'
|
||||||
# Location of web files
|
# Location of web files
|
||||||
SHARE_EDDN_FILES='%s/.local/share/eddn/%s' % ( os.environ['HOME'], setup_env.EDDN_ENV )
|
SHARE_EDDN_FILES = f'{os.environ["HOME"]}/.local/share/eddn/{setup_env.EDDN_ENV}'
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='eddn',
|
name='eddn',
|
||||||
@ -79,7 +83,7 @@ setup(
|
|||||||
'src',
|
'src',
|
||||||
exclude=["*.tests"]
|
exclude=["*.tests"]
|
||||||
),
|
),
|
||||||
package_dir = {'':'src'},
|
package_dir={'': 'src'},
|
||||||
|
|
||||||
# This includes them for the running code, but that doesn't help
|
# This includes them for the running code, but that doesn't help
|
||||||
# serve them up for reference.
|
# serve them up for reference.
|
||||||
@ -112,26 +116,28 @@ setup(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def open_file_perms_recursive(dirname):
|
|
||||||
|
def open_file_perms_recursive(dirname: str) -> None:
|
||||||
"""Open up file perms on the given directory and its contents."""
|
"""Open up file perms on the given directory and its contents."""
|
||||||
print 'open_file_perms_recursive: %s' % ( dirname )
|
print(f'open_file_perms_recursive: {dirname}')
|
||||||
names = os.listdir(dirname)
|
names = os.listdir(dirname)
|
||||||
for name in names:
|
for name in names:
|
||||||
n = '%s/%s' % ( dirname, name )
|
n = f'{dirname}/{name}'
|
||||||
print 'open_file_perms_recursive: %s' % ( n )
|
print(f'open_file_perms_recursive: {n}')
|
||||||
if (os.path.isdir(n)):
|
if (os.path.isdir(n)):
|
||||||
os.chmod(n, 0755)
|
os.chmod(n, 0o755)
|
||||||
# Recurse
|
# Recurse
|
||||||
open_file_perms_recursive(n)
|
open_file_perms_recursive(n)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
os.chmod(n, 0644)
|
os.chmod(n, 0o644)
|
||||||
|
|
||||||
|
|
||||||
# Ensure the systemd-required start files are in place
|
# Ensure the systemd-required start files are in place
|
||||||
print """
|
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()
|
old_cwd = os.getcwd()
|
||||||
if not os.path.isdir(START_SCRIPT_BIN):
|
if not os.path.isdir(START_SCRIPT_BIN):
|
||||||
# We're still using Python 2.7, so no pathlib
|
# We're still using Python 2.7, so no pathlib
|
||||||
@ -146,28 +152,38 @@ if not os.path.isdir(START_SCRIPT_BIN):
|
|||||||
os.chdir(pc)
|
os.chdir(pc)
|
||||||
|
|
||||||
if not os.path.isdir(START_SCRIPT_BIN):
|
if not os.path.isdir(START_SCRIPT_BIN):
|
||||||
print "%s can't be created, aborting!!!" % (START_SCRIPT_BIN)
|
print(f"{START_SCRIPT_BIN} can't be created, aborting!!!")
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
|
|
||||||
shutil.copy(
|
shutil.copy(
|
||||||
'systemd/eddn_%s_config' % ( setup_env.EDDN_ENV),
|
f'systemd/eddn_{setup_env.EDDN_ENV}_config',
|
||||||
'%s/eddn_%s_config' % ( START_SCRIPT_BIN, setup_env.EDDN_ENV )
|
f'{START_SCRIPT_BIN}/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',
|
||||||
'%s/start-eddn-%s-service' % ( START_SCRIPT_BIN, setup_env.EDDN_ENV )
|
f'{START_SCRIPT_BIN}/start-eddn-{setup_env.EDDN_ENV}-service'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure the service log file archiving script is in place
|
||||||
|
print("""
|
||||||
|
******************************************************************************
|
||||||
|
Ensuring the service log file archiving script is in place
|
||||||
|
""")
|
||||||
|
shutil.copy(
|
||||||
|
'contrib/eddn-logs-archive',
|
||||||
|
START_SCRIPT_BIN
|
||||||
)
|
)
|
||||||
|
|
||||||
# Ensure the latest monitor files are in place
|
# Ensure the latest monitor files are in place
|
||||||
old_umask = os.umask(022)
|
old_umask = os.umask(0o22)
|
||||||
print """
|
print(f"""
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
Ensuring %s exists...
|
Ensuring {SHARE_EDDN_FILES} exists...
|
||||||
""" % ( SHARE_EDDN_FILES )
|
""")
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
if not os.path.isdir(SHARE_EDDN_FILES):
|
if not os.path.isdir(SHARE_EDDN_FILES):
|
||||||
# We're still using Python 2.7, so no pathlib
|
# We're still using Python 2.7, so no pathlib
|
||||||
@ -182,61 +198,63 @@ if not os.path.isdir(SHARE_EDDN_FILES):
|
|||||||
os.chdir(pc)
|
os.chdir(pc)
|
||||||
|
|
||||||
if not os.path.isdir(SHARE_EDDN_FILES):
|
if not os.path.isdir(SHARE_EDDN_FILES):
|
||||||
print "%s can't be created, aborting!!!" % (SHARE_EDDN_FILES)
|
print(f"{SHARE_EDDN_FILES} can't be created, aborting!!!")
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
os.chdir(old_cwd)
|
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('%s/monitor' % ( SHARE_EDDN_FILES ))
|
shutil.rmtree(f'{SHARE_EDDN_FILES}/monitor')
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
'contrib/monitor',
|
'contrib/monitor',
|
||||||
'%s/monitor' % ( SHARE_EDDN_FILES ),
|
f'{SHARE_EDDN_FILES}/monitor',
|
||||||
# Not in Python 2.7
|
# Not in Python 2.7
|
||||||
# copy_function=shutil.copyfile,
|
# copy_function=shutil.copyfile,
|
||||||
)
|
)
|
||||||
# And a copy of the schemas too
|
# And a copy of the schemas too
|
||||||
print """
|
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('%s/schemas' % ( SHARE_EDDN_FILES ))
|
shutil.rmtree(f'{SHARE_EDDN_FILES}/schemas')
|
||||||
|
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
'schemas',
|
'schemas',
|
||||||
'%s/schemas' % ( SHARE_EDDN_FILES ),
|
f'{SHARE_EDDN_FILES}/schemas',
|
||||||
# Not in Python 2.7
|
# Not in Python 2.7
|
||||||
# copy_function=shutil.copyfile,
|
# copy_function=shutil.copyfile,
|
||||||
)
|
)
|
||||||
|
|
||||||
print """
|
print("""
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
Opening up permissions on monitor and schema files...
|
Opening up permissions on monitor and schema files...
|
||||||
"""
|
""")
|
||||||
os.chmod(SHARE_EDDN_FILES, 0755)
|
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('%s/config.json' % ( SHARE_EDDN_FILES )):
|
if not os.path.isfile(f'{SHARE_EDDN_FILES}/config.json'):
|
||||||
shutil.copy('docs/config-EXAMPLE.json', SHARE_EDDN_FILES)
|
shutil.copy('docs/config-EXAMPLE.json', SHARE_EDDN_FILES)
|
||||||
print """
|
print(f"""
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
There was no config.json file in place, so docs/config-EXAMPLE.json was
|
There was no config.json file in place, so docs/config-EXAMPLE.json was
|
||||||
copied into:
|
copied into:
|
||||||
|
|
||||||
%s
|
{SHARE_EDDN_FILES}
|
||||||
|
|
||||||
Please review, edit and rename this file to 'config.json' so that this
|
Please review, edit and rename this file to 'config.json' so that this
|
||||||
software will actually work.
|
software will actually work.
|
||||||
See docs/Running-this-software.md for guidance.
|
See docs/Running-this-software.md for guidance.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
""" % ( SHARE_EDDN_FILES )
|
""")
|
||||||
os.umask(old_umask)
|
os.umask(old_umask)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user