This commit is contained in:
@@ -36,6 +36,18 @@ class Program(object): # pylint: disable=too-few-public-methods
|
||||
|
||||
return self._argparser.parse_args(argv)
|
||||
|
||||
@staticmethod
|
||||
def _append_to_settings(project_dir, code, comment):
|
||||
settings_dir = os.path.join(project_dir, DJANGO_SETTINGS_MODULE_NAME)
|
||||
settings_file = os.path.join(settings_dir, 'settings.py')
|
||||
settings_file_py2cache = settings_file + 'c'
|
||||
|
||||
text = '\n' + comment + '\n' + code + '\n'
|
||||
with open(settings_file, 'a') as f:
|
||||
f.write(text)
|
||||
if os.path.isfile(settings_file_py2cache):
|
||||
os.unlink(settings_file_py2cache) # pragma: no cover
|
||||
|
||||
@staticmethod
|
||||
def _install_django_files(project_dir, overwrite=False):
|
||||
if os.path.exists(project_dir):
|
||||
@@ -52,8 +64,7 @@ class Program(object): # pylint: disable=too-few-public-methods
|
||||
exitval = os.system(cmd)
|
||||
return exitval
|
||||
|
||||
@staticmethod
|
||||
def _add_installed_apps_from_app(project_dir, app):
|
||||
def _add_installed_apps_from_app(self, project_dir, app):
|
||||
settings_dir = os.path.join(project_dir, DJANGO_SETTINGS_MODULE_NAME)
|
||||
|
||||
settings_from_app = importlib.import_module('{}.django_settings'.format(app))
|
||||
@@ -77,18 +88,15 @@ class Program(object): # pylint: disable=too-few-public-methods
|
||||
|
||||
if missing_apps:
|
||||
sys.stdout.write('{app}: adding {apps} to INSTALLED_APPS\n'.format(app=app, apps=missing_apps))
|
||||
comment = '### {app}: added apps with django-deploy at {timestamp}'
|
||||
code = 'INSTALLED_APPS += [\n'
|
||||
for add_app in missing_apps:
|
||||
code += ' \'{}\',\n'.format(add_app)
|
||||
code += ']\n'
|
||||
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
comment = '### {app}: added apps with django-deploy at {timestamp}'.format(app=app,
|
||||
timestamp=timestamp)
|
||||
|
||||
append_text = '\n' + comment + '\n' + code + '\n'
|
||||
settings_file = os.path.join(settings_dir, 'settings.py')
|
||||
with open(settings_file, 'a') as f:
|
||||
now = datetime.datetime.now()
|
||||
timestamp = now.strftime('%Y-%m-%d %H:%M:%S')
|
||||
f.write(append_text.format(app=app, timestamp=timestamp))
|
||||
self._append_to_settings(project_dir, code, comment)
|
||||
else:
|
||||
sys.stdout.write('{app}: INSTALLED_APPS is fine\n'.format(app=app))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user