mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 20:40:17 +02:00
Merge pull request #913 from Adarnof/sso_registration
Determine paths to commands using shutil
This commit is contained in:
commit
c4979a22dd
@ -1,79 +1,57 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
import sys
|
import shutil
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from django.core.management import ManagementUtility
|
from django.core.management import call_command
|
||||||
|
from django.core.management.commands.startproject import Command as StartProject
|
||||||
|
|
||||||
|
|
||||||
def create_project(parser, options, args):
|
def create_project(parser, options, args):
|
||||||
# Validate args
|
# Validate args
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
parser.error("Please specify a name for your Alliance Auth installation")
|
parser.error("Please specify a name for your Alliance Auth installation.")
|
||||||
elif len(args) > 3:
|
elif len(args) > 3:
|
||||||
parser.error("Too many arguments")
|
parser.error("Too many arguments.")
|
||||||
|
|
||||||
project_name = args[1]
|
|
||||||
try:
|
|
||||||
dest_dir = args[2]
|
|
||||||
except IndexError:
|
|
||||||
dest_dir = None
|
|
||||||
|
|
||||||
# Make sure given name is not already in use by another python package/module.
|
|
||||||
try:
|
|
||||||
__import__(project_name)
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
parser.error("'%s' conflicts with the name of an existing "
|
|
||||||
"Python module and cannot be used as a project "
|
|
||||||
"name. Please try another name." % project_name)
|
|
||||||
|
|
||||||
print("Creating an Alliance Auth project called %(project_name)s" % {'project_name': project_name}) # noqa
|
|
||||||
|
|
||||||
# Create the project from the Alliance Auth template using startapp
|
|
||||||
|
|
||||||
# First find the path to Alliance Auth
|
# First find the path to Alliance Auth
|
||||||
import allianceauth
|
import allianceauth
|
||||||
allianceauth_path = os.path.dirname(allianceauth.__file__)
|
allianceauth_path = os.path.dirname(allianceauth.__file__)
|
||||||
template_path = os.path.join(allianceauth_path, 'project_template')
|
template_path = os.path.join(allianceauth_path, 'project_template')
|
||||||
|
|
||||||
# Call django-admin startproject
|
# Determine locations of commands to render supervisor cond
|
||||||
utility_args = ['django-admin.py',
|
command_options = {
|
||||||
'startproject',
|
'template': template_path,
|
||||||
'--template=' + template_path,
|
'python': shutil.which('python'),
|
||||||
'--pythonpath=' + '/'.join(sys.executable.split('/')[:-1]),
|
'gunicorn': shutil.which('gunicorn'),
|
||||||
'--ext=conf',
|
'celery': shutil.which('celery'),
|
||||||
project_name]
|
'extensions': ['py', 'conf'],
|
||||||
|
}
|
||||||
|
|
||||||
if dest_dir:
|
# Strip 'start' out of the arguments, leaving project name (and optionally destination dir)
|
||||||
utility_args.append(dest_dir)
|
args = args[1:]
|
||||||
|
|
||||||
utility = ManagementUtility(utility_args)
|
# Call the command with extra context
|
||||||
utility.execute()
|
call_command(StartProject(), *args, **command_options)
|
||||||
|
|
||||||
print("Success! %(project_name)s has been created" % {'project_name': project_name}) # noqa
|
print("Success! %(project_name)s has been created." % {'project_name': args[0]}) # noqa
|
||||||
|
|
||||||
|
|
||||||
def update_settings(parser, options, args):
|
def update_settings(parser, options, args):
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
parser.error("Please specify the path to your Alliance Auth installation")
|
parser.error("Please specify the path to your Alliance Auth installation.")
|
||||||
elif len(args) > 2:
|
elif len(args) > 2:
|
||||||
parser.error("Too many arguments")
|
parser.error("Too many arguments.")
|
||||||
|
|
||||||
project_path = args[1]
|
project_path = args[1]
|
||||||
|
project_name = os.path.split(project_path)[-1]
|
||||||
|
|
||||||
# find the target settings/base.py file, handing both the project and app as valid paths
|
# find the target settings/base.py file, handing both the project and app as valid paths
|
||||||
try:
|
# first check if given path is to the app
|
||||||
# given path is to the app
|
|
||||||
settings_path = os.path.join(project_path, 'settings/base.py')
|
settings_path = os.path.join(project_path, 'settings/base.py')
|
||||||
assert os.path.exists(settings_path)
|
if not os.path.exists(settings_path):
|
||||||
except AssertionError:
|
# next check if given path is to the project, so the app is within it
|
||||||
try:
|
settings_path = os.path.join(project_path, project_name, 'settings/base.py')
|
||||||
# given path is to the project, so find the app within it
|
if not os.path.exists(settings_path):
|
||||||
dirname = os.path.split(project_path)[-1]
|
|
||||||
settings_path = os.path.join(project_path, dirname, 'settings/base.py')
|
|
||||||
assert os.path.exists(settings_path)
|
|
||||||
except AssertionError:
|
|
||||||
parser.error("Unable to locate the Alliance Auth project at %s" % project_path)
|
parser.error("Unable to locate the Alliance Auth project at %s" % project_path)
|
||||||
|
|
||||||
# first find the path to the Alliance Auth template settings
|
# first find the path to the Alliance Auth template settings
|
||||||
@ -83,11 +61,10 @@ def update_settings(parser, options, args):
|
|||||||
template_settings_path = os.path.join(template_path, 'project_name/settings/base.py')
|
template_settings_path = os.path.join(template_path, 'project_name/settings/base.py')
|
||||||
|
|
||||||
# overwrite the local project's base settings
|
# overwrite the local project's base settings
|
||||||
print("Updating the settings at %s with the template at %s" % (settings_path, template_settings_path))
|
|
||||||
with open(template_settings_path, 'r') as template, open(settings_path, 'w') as target:
|
with open(template_settings_path, 'r') as template, open(settings_path, 'w') as target:
|
||||||
target.write(template.read())
|
target.write(template.read())
|
||||||
|
|
||||||
print("Successfully updated Alliance Auth settings.")
|
print("Successfully updated %(project_name)s settings." % {'project_name': project_name})
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = {
|
COMMANDS = {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[program:beat]
|
[program:beat]
|
||||||
command={{ pythonpath}}/celery -A {{ project_name }} beat
|
command={{ celery }} -A {{ project_name }} beat
|
||||||
directory={{ project_directory }}
|
directory={{ project_directory }}
|
||||||
user=allianceserver
|
user=allianceserver
|
||||||
stdout_logfile={{ project_directory }}/log/beat.log
|
stdout_logfile={{ project_directory }}/log/beat.log
|
||||||
@ -10,7 +10,7 @@ startsecs=10
|
|||||||
priority=998
|
priority=998
|
||||||
|
|
||||||
[program:worker]
|
[program:worker]
|
||||||
command={{ pythonpath}}/celery -A {{ project_name }} worker
|
command={{ celery }} -A {{ project_name }} worker
|
||||||
directory={{ project_directory }}
|
directory={{ project_directory }}
|
||||||
user=allianceserver
|
user=allianceserver
|
||||||
numprocs=1
|
numprocs=1
|
||||||
@ -26,7 +26,7 @@ priority=998
|
|||||||
[program:gunicorn]
|
[program:gunicorn]
|
||||||
user = allianceserver
|
user = allianceserver
|
||||||
directory={{ project_directory }}
|
directory={{ project_directory }}
|
||||||
command={{ pythonpath}}/gunicorn {{ project_name}}.wsgi --workers=3 --timeout 120
|
command={{ gunicorn }} {{ project_name }}.wsgi --workers=3 --timeout 120
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=true
|
autorestart=true
|
||||||
stopsignal=INT
|
stopsignal=INT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user