1
0
mirror of https://github.com/gryf/wicd.git synced 2026-03-06 01:05:45 +01:00

Get rid of generated wpath in favor of json stored data

This commit is contained in:
2020-08-27 20:06:49 +02:00
parent 0abb165702
commit faf1aaab17

155
setup.py
View File

@@ -20,7 +20,9 @@
# #
from glob import glob from glob import glob
import os import os
import json
import re import re
import configparser
import shutil import shutil
import subprocess import subprocess
from distutils import log from distutils import log
@@ -30,6 +32,8 @@ import setuptools
from setuptools.command import install as _install from setuptools.command import install as _install
import wicd import wicd
from wicd import config
from wicd.config import DEFAULTS as RUNTIME_OPTS
VERSION_NUM = wicd.__version__ VERSION_NUM = wicd.__version__
@@ -65,17 +69,37 @@ empty_file = 'other/.empty_on_purpose'
# change to the directory setup.py is contained in # change to the directory setup.py is contained in
os.chdir(os.path.abspath(os.path.split(__file__)[0])) os.chdir(os.path.abspath(os.path.split(__file__)[0]))
BUILD_OPTS = {'bin': '/usr/bin/',
'dbus': '/etc/dbus-1/system.d/',
'dbus_service': '/usr/share/dbus-1/system-services/',
'distro': None,
'docdir': '/usr/share/doc/wicd/',
'logrotate': '/etc/logrotate.d/',
'mandir': '/usr/share/man/',
'scripts': '/etc/wicd/scripts/',
'systemd': '/lib/systemd/system/',
'resume': '/etc/acpi/resume.d/',
'suspend': '/etc/acpi/suspend.d/',
'pmutils': '/usr/lib/pm-utils/sleep.d/',
'no_install_init': False,
'no_install_man': False,
'no_install_i18n': False,
'no_install_i18n_man': False,
'no_install_acpi': False,
'no_install_pmutils': False,
'no_install_docs': False,
'distro_detect_failed': False,
'init': '',
'initfile': '',
'initfilename': ''}
class build(_build.build): class build(_build.build):
sub_commands = _build.build.sub_commands + [('compile_translations', None)] sub_commands = _build.build.sub_commands + [('compile_translations', None)]
def run(self): def run(self):
try: if not os.path.exists('wpath.json'):
import wpath
except ImportError:
self.run_command('configure') self.run_command('configure')
import wpath
# raise Exception, 'Please run "./setup.py configure" first.'
_build.build.run(self) _build.build.run(self)
@@ -83,10 +107,6 @@ class configure(setuptools.Command):
description = "configure the paths that Wicd will be installed to" description = "configure the paths that Wicd will be installed to"
user_options = [ user_options = [
('lib=', None, 'set the lib directory'),
('share=', None, 'set the share directory'),
('etc=', None, 'set the etc directory'),
('scripts=', None, 'set the global scripts directory'),
('encryption=', None, 'set the encryption template directory'), ('encryption=', None, 'set the encryption template directory'),
('bin=', None, 'set the bin directory'), ('bin=', None, 'set the bin directory'),
('sbin=', None, 'set the sbin directory'), ('sbin=', None, 'set the sbin directory'),
@@ -132,38 +152,10 @@ class configure(setuptools.Command):
'documentation')] 'documentation')]
def initialize_options(self): def initialize_options(self):
self.lib = '/usr/lib/wicd/' for key, val in BUILD_OPTS.items():
self.share = '/usr/share/wicd/' setattr(self, key, val)
self.etc = '/etc/wicd/' for key, val in RUNTIME_OPTS.items():
self.scripts = self.etc + "scripts/" setattr(self, key, val)
self.encryption = self.etc + 'encryption/templates/'
self.bin = '/usr/bin/'
self.sbin = '/usr/sbin/'
self.varlib = '/var/lib/wicd/'
self.networks = self.varlib + 'configurations/'
self.log = '/var/log/wicd/'
self.resume = '/etc/acpi/resume.d/'
self.suspend = '/etc/acpi/suspend.d/'
self.pmutils = '/usr/lib/pm-utils/sleep.d/'
self.dbus = '/etc/dbus-1/system.d/'
self.dbus_service = '/usr/share/dbus-1/system-services/'
self.systemd = '/lib/systemd/system/'
self.logrotate = '/etc/logrotate.d/'
self.translations = '/usr/share/locale/'
self.docdir = '/usr/share/doc/wicd/'
self.mandir = '/usr/share/man/'
self.distro = 'auto'
self.no_install_init = False
self.no_install_man = False
self.no_install_i18n = False
self.no_install_i18n_man = False
self.no_install_acpi = False
self.no_install_pmutils = False
self.no_install_docs = False
# Determine the default init file location on several different distros
self.distro_detect_failed = False
self.detected_distro = 'FAIL' self.detected_distro = 'FAIL'
for fname, distro in DISTROS.items(): for fname, distro in DISTROS.items():
@@ -252,30 +244,12 @@ class configure(setuptools.Command):
def finalize_options(self): def finalize_options(self):
self.distro_check() self.distro_check()
if self.distro_detect_failed and not self.no_install_init and \ if (self.distro_detect_failed and not self.no_install_init and
'FAIL' in [self.init, self.initfile]: 'FAIL' in [self.init, self.initfile]):
log.error('ERROR: Failed to detect distro. Configure cannot ' log.error('ERROR: Failed to detect distro. Configure cannot '
'continue.\nPlease specify --init and --initfile to ' 'continue.\nPlease specify --init and --initfile to '
'continue with configuration.') # raise? 'continue with configuration.') # raise?
# loop through the argument definitions in user_options
for argument in self.user_options:
# argument name is the first item in the user_options list
# sans the = sign at the end
argument_name = argument[0][:-1]
# select the first one, which is the name of the option
value = getattr(self, argument_name.replace('-', '_'))
# if the option is not python (which is not a directory)
if not argument[0][:-1] == "python":
# see if it ends with a /
if not str(value).endswith("/"):
# if it doesn't, slap one on
setattr(self, argument_name, str(value) + "/")
else:
# as stated above, the python entry defines the beginning
# of the files section
return
def run(self): def run(self):
values = list() values = list()
for argument in self.user_options: for argument in self.user_options:
@@ -310,9 +284,9 @@ class configure(setuptools.Command):
str(value)) str(value))
# other things to replace that aren't arguments # other things to replace that aren't arguments
line = line.replace('%VERSION%', str(VERSION_NUM)) line = line.replace('%VERSION%', VERSION_NUM)
line = line.replace('%REVNO%', str(REVISION_NUM)) line = line.replace('%REVNO%', REVISION_NUM)
line = line.replace('%CURSES_REVNO%', str(CURSES_REVNO)) line = line.replace('%CURSES_REVNO%', CURSES_REVNO)
item_out.write(line) item_out.write(line)
@@ -320,6 +294,35 @@ class configure(setuptools.Command):
item_in.close() item_in.close()
shutil.copymode(original_name, final_name) shutil.copymode(original_name, final_name)
# create wpath.json and changed options for wicd.conf
opts = {}
for key in BUILD_OPTS:
opts[key] = getattr(self, key)
conf = {}
for key, val in RUNTIME_OPTS.items():
opts[key] = getattr(self, key)
if opts[key] != val:
conf[key] = opts[key]
with open('wpath.json', 'w') as fobj:
json.dump(opts, fobj)
# write changed paths used in runtime as the config file.
if conf:
parser = configparser.ConfigParser()
parser.add_section('wicd')
for key, val in conf.items():
parser.set('wicd', key, str(val))
with open('data/etc/wicd.conf', 'w') as fobj:
parser.write(fobj)
else:
try:
os.unlink('data/etc/wicd.conf')
except FileNotFoundError:
pass
class clear_generated(setuptools.Command): class clear_generated(setuptools.Command):
description = 'clears out files generated by configure' description = 'clears out files generated by configure'
@@ -351,12 +354,14 @@ class clear_generated(setuptools.Command):
class install(_install.install): class install(_install.install):
def run(self): def run(self):
try: try:
import wpath with open('wpath.json') as fobj:
except ImportError: wpath = config.Config(json.load(fobj))
except FileNotFoundError:
self.run_command('build') self.run_command('build')
import wpath with open('wpath.json') as fobj:
wpath = config.Config(json.load(fobj))
print("Using init file", wpath.init, wpath.initfile)
data.extend([ data.extend([
(wpath.dbus, ['other/wicd.conf']), (wpath.dbus, ['other/wicd.conf']),
(wpath.dbus_service, ['other/org.wicd.daemon.service']), (wpath.dbus_service, ['other/org.wicd.daemon.service']),
@@ -445,6 +450,11 @@ class install(_install.install):
['translations/' + language + ['translations/' + language +
'/LC_MESSAGES/wicd.mo'])) '/LC_MESSAGES/wicd.mo']))
for dir_ in (os.listdir('data')):
path = os.path.join('data', dir_)
for fname in os.listdir(path):
data.append((wpath[dir_], [os.path.join(path, fname)]))
_install.install.run(self) _install.install.run(self)
@@ -514,11 +524,12 @@ class compile_translations(setuptools.Command):
def run(self): def run(self):
try: try:
import wpath with open('wpath.json') as fobj:
except ImportError: wpath = config.Config(json.load(fobj))
# if there's no wpath.py, then run configure+build except FileNotFoundError:
self.run_command('build') self.run_command('build')
import wpath with open('wpath.json') as fobj:
wpath = config.Config(json.load(fobj))
if not wpath.no_install_i18n: if not wpath.no_install_i18n:
if os.path.exists('translations'): if os.path.exists('translations'):