Commit 7b20cfc0 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Change application.properties location compatible for windows + setup.py

parent b2860602
import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
from pip.req import parse_requirements from pip.req import parse_requirements
...@@ -6,15 +7,31 @@ install_reqs = parse_requirements('requirements.txt', session='hack') ...@@ -6,15 +7,31 @@ install_reqs = parse_requirements('requirements.txt', session='hack')
# e.g. ['django==1.5.1', 'mezzanine==1.4.6'] # e.g. ['django==1.5.1', 'mezzanine==1.4.6']
reqs = [str(ir.req) for ir in install_reqs] reqs = [str(ir.req) for ir in install_reqs]
setup( if os.name == "posix":
name='dgenies',
version='0.9', setup(
packages=find_packages('src'), name='dgenies',
package_dir={'dgenies': 'src/dgenies'}, version='0.9',
include_package_data=True, packages=find_packages('src'),
zip_safe=False, package_dir={'dgenies': 'src/dgenies'},
install_requires=reqs, include_package_data=True,
data_files=[('/etc/dgenies', ['application.properties']), zip_safe=False,
('/var/www/dgenies', ['dgenies.wsgi'])], install_requires=reqs,
scripts=['src/bin/dgenies'], data_files=[('/etc/dgenies', ['application.properties']),
) ('/var/www/dgenies', ['dgenies.wsgi'])],
scripts=['src/bin/dgenies'],
)
else:
setup(
name='dgenies',
version='0.9',
packages=find_packages('src'),
package_dir={'dgenies': 'src/dgenies'},
include_package_data=True,
zip_safe=False,
install_requires=reqs,
data_files=[('.dgenies', ['application.properties'])],
scripts=['src/bin/dgenies'],
)
import os import os
import re import re
import inspect import inspect
from pathlib import Path
from configparser import RawConfigParser, NoOptionError, NoSectionError from configparser import RawConfigParser, NoOptionError, NoSectionError
from dgenies.lib.decorators import Singleton from dgenies.lib.decorators import Singleton
...@@ -11,9 +12,6 @@ class AppConfigReader: ...@@ -11,9 +12,6 @@ class AppConfigReader:
Store all configs Store all configs
""" """
config_file = "/etc/dgenies/application.properties"
config_file_local = config_file + ".local"
def __init__(self): def __init__(self):
""" """
All "get_*" functions results are stored in the "self.*" corresponding attribute All "get_*" functions results are stored in the "self.*" corresponding attribute
...@@ -21,17 +19,19 @@ class AppConfigReader: ...@@ -21,17 +19,19 @@ class AppConfigReader:
""" """
self.app_dir = os.path.dirname(inspect.getfile(self.__class__)) self.app_dir = os.path.dirname(inspect.getfile(self.__class__))
config_file = [] config_file = []
if os.path.exists(self.config_file): config_file_search = [os.path.join(os.path.abspath(os.sep), "dgenies", "application.properties"),
config_file.append(self.config_file) "/etc/dgenies/application.properties",
if os.path.exists(self.config_file_local): "/etc/dgenies/application.properties.local",
config_file.append(self.config_file_local) os.path.join(str(Path.home()), ".dgenies", "application.properties")]
if len(config_file) > 0:
self.config_file = config_file for my_config_file in config_file_search:
else: if os.path.exists(my_config_file):
config_file.append(my_config_file)
if len(config_file) == 0:
raise FileNotFoundError("ERROR: application.properties not found. Please copy the example file and " raise FileNotFoundError("ERROR: application.properties not found. Please copy the example file and "
"check properties are correct for you!") "check properties are correct for you!")
self.reader = RawConfigParser() self.reader = RawConfigParser()
self.reader.read(self.config_file) self.reader.read(config_file)
for attr in dir(self): for attr in dir(self):
attr_o = getattr(self, attr) attr_o = getattr(self, attr)
if attr.startswith("_get_") and callable(attr_o): if attr.startswith("_get_") and callable(attr_o):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment