More restructuring.
This commit is contained in:
14
.gitignore
vendored
14
.gitignore
vendored
@@ -1,11 +1,15 @@
|
|||||||
*.pyc
|
|
||||||
.coverage
|
|
||||||
geckodriver.log
|
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
manage.py
|
manage.py
|
||||||
conf/
|
conf/
|
||||||
env/
|
pythonenv/
|
||||||
tmp/
|
tmp/
|
||||||
var/
|
var/
|
||||||
|
|
||||||
|
*.pyc
|
||||||
|
.coverage
|
||||||
|
geckodriver.log
|
||||||
|
|
||||||
|
django_test.egg-info/
|
||||||
|
dist/
|
||||||
|
|
||||||
|
|||||||
6
MANIFEST.in
Normal file
6
MANIFEST.in
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
include README.rst INSTALL.rst
|
||||||
|
include setup.py requirements.txt
|
||||||
|
recursive-include apps/base/static *
|
||||||
|
recursive-include apps/base/templates *
|
||||||
|
recursive-include bin *
|
||||||
|
recursive-include etc *
|
||||||
90
bin/setup.py
90
bin/setup.py
@@ -1,90 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
class Command(object):
|
|
||||||
settings_module_name = 'main'
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _setup_argparser():
|
|
||||||
kwargs = {
|
|
||||||
'description': 'Setup and configure the django project.',
|
|
||||||
}
|
|
||||||
parser = argparse.ArgumentParser(**kwargs)
|
|
||||||
|
|
||||||
parser.add_argument('--force',
|
|
||||||
action='store_true', dest='force',
|
|
||||||
help='Overwrite existing django settings')
|
|
||||||
return parser
|
|
||||||
|
|
||||||
def _parse_args(self, argv=None):
|
|
||||||
if argv is None:
|
|
||||||
argv = sys.argv[1:]
|
|
||||||
|
|
||||||
return self._argparser.parse_args(argv)
|
|
||||||
|
|
||||||
def _run(self, force=False):
|
|
||||||
settings_module_name = self.settings_module_name
|
|
||||||
settings_file = os.path.join(settings_module_name, 'settings.py')
|
|
||||||
|
|
||||||
if os.path.exists(settings_file):
|
|
||||||
if not force:
|
|
||||||
sys.stderr.write('Django settings file detected. Abort!\n')
|
|
||||||
return os.EX_NOPERM
|
|
||||||
|
|
||||||
if os.path.exists('manage.py') or \
|
|
||||||
os.path.exists(settings_module_name):
|
|
||||||
sys.stdout.write('Replacing django files...\n')
|
|
||||||
if os.path.exists('manage.py'):
|
|
||||||
os.unlink('manage.py')
|
|
||||||
if os.path.exists(settings_module_name):
|
|
||||||
shutil.rmtree(settings_module_name)
|
|
||||||
else:
|
|
||||||
sys.stdout.write('Installing django files...\n')
|
|
||||||
|
|
||||||
cmd = 'django-admin startproject {name} .'.format(name=settings_module_name)
|
|
||||||
exitval = os.system(cmd)
|
|
||||||
if exitval != os.EX_OK:
|
|
||||||
return exitval
|
|
||||||
|
|
||||||
sys.stdout.write('Configure django...\n')
|
|
||||||
add_settings_file = os.path.join('etc', 'django', 'additional_settings.py')
|
|
||||||
with open(settings_file, 'a') as f_out:
|
|
||||||
with open(add_settings_file) as f_in:
|
|
||||||
f_out.write(f_in.read())
|
|
||||||
|
|
||||||
sys.stdout.write('Creating directories...\n')
|
|
||||||
dirs = [
|
|
||||||
os.path.join('var', 'db'),
|
|
||||||
os.path.join('var', 'log'),
|
|
||||||
os.path.join('var', 'www', 'static'),
|
|
||||||
]
|
|
||||||
for d in dirs:
|
|
||||||
sys.stdout.write(' - %s\n' % d)
|
|
||||||
if not os.path.exists(d):
|
|
||||||
os.makedirs(d)
|
|
||||||
|
|
||||||
return os.EX_OK
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self._argparser = self._setup_argparser()
|
|
||||||
|
|
||||||
def __call__(self, argv=None):
|
|
||||||
cmd_args = self._parse_args(argv)
|
|
||||||
exitval = self._run(cmd_args.force)
|
|
||||||
return exitval
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
cmd = Command()
|
|
||||||
exitval = cmd()
|
|
||||||
sys.exit(exitval)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
127
setup.py
Normal file
127
setup.py
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
from setuptools import Command
|
||||||
|
|
||||||
|
|
||||||
|
class MyCommand(Command):
|
||||||
|
user_options = []
|
||||||
|
|
||||||
|
def initialize_options(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def finalize_options(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class CreatePythonEnvironment(MyCommand):
|
||||||
|
description = 'create a (virtual) python environment'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run():
|
||||||
|
python_bin = sys.executable if sys.executable else 'python'
|
||||||
|
python_ver = sys.version_info.major
|
||||||
|
if python_ver == 2:
|
||||||
|
# path = os.path.join('env', 'python2')
|
||||||
|
path = 'pythonenv'
|
||||||
|
# symlink_path = os.path.join('env', 'python')
|
||||||
|
symlink_path = ''
|
||||||
|
venv_module = 'virtualenv'
|
||||||
|
prompt = '(py2-django) '
|
||||||
|
elif python_ver == 3:
|
||||||
|
# path = os.path.join('env', 'python3')
|
||||||
|
path = 'pythonenv'
|
||||||
|
# symlink_path = os.path.join('env', 'python')
|
||||||
|
symlink_path = ''
|
||||||
|
venv_module = 'venv'
|
||||||
|
prompt = 'py3-django'
|
||||||
|
else:
|
||||||
|
sys.stderr.write('Python {} is not supported.\n'.format(python_ver))
|
||||||
|
sys.exit(os.EX_USAGE)
|
||||||
|
|
||||||
|
sys.stdout.write('Creating new python environment in {path}\n'.format(path=path))
|
||||||
|
cmd = ('{bin} -m {venv_module}'
|
||||||
|
' --prompt="{prompt}"'
|
||||||
|
' {path}'.format(bin=python_bin, path=path,
|
||||||
|
venv_module=venv_module, prompt=prompt))
|
||||||
|
os.system(cmd)
|
||||||
|
|
||||||
|
if symlink_path and symlink_path != path and not os.path.exists(symlink_path):
|
||||||
|
symlink_dir = os.path.dirname(symlink_path)
|
||||||
|
relpath = os.path.relpath(path, symlink_dir)
|
||||||
|
os.symlink(relpath, symlink_path)
|
||||||
|
|
||||||
|
print('')
|
||||||
|
print('Depending on your operating system or command shell,')
|
||||||
|
print('you should activate the new environment for this shell session')
|
||||||
|
print('by running ONE of the following commands:')
|
||||||
|
print('- Windows: %s' % os.path.join(path, 'Scripts', 'activate'))
|
||||||
|
print('- C Shell: source %s/bin/activate.csh' % path)
|
||||||
|
print('- All others: source %s/bin/activate' % path)
|
||||||
|
|
||||||
|
|
||||||
|
class SetupDjangoProject(MyCommand):
|
||||||
|
description = 'setup and configure the django project'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run():
|
||||||
|
# python_bin = sys.executable if sys.executable else 'python'
|
||||||
|
mgmt_script = 'manage.py'
|
||||||
|
|
||||||
|
settings_module_name = 'conf'
|
||||||
|
settings_file = os.path.join(settings_module_name, 'settings.py')
|
||||||
|
|
||||||
|
if os.path.exists(settings_file):
|
||||||
|
sys.stderr.write('Django settings file detected. Abort!\n')
|
||||||
|
return os.EX_NOPERM
|
||||||
|
|
||||||
|
if os.path.exists(mgmt_script) or os.path.exists(settings_module_name):
|
||||||
|
sys.stdout.write('Replacing django files...\n')
|
||||||
|
if os.path.exists(mgmt_script):
|
||||||
|
os.unlink(mgmt_script)
|
||||||
|
if os.path.exists(settings_module_name):
|
||||||
|
shutil.rmtree(settings_module_name)
|
||||||
|
else:
|
||||||
|
sys.stdout.write('Installing django files...\n')
|
||||||
|
|
||||||
|
cmd = 'django-admin startproject {name} .'.format(name=settings_module_name)
|
||||||
|
exitval = os.system(cmd)
|
||||||
|
if exitval != os.EX_OK:
|
||||||
|
return exitval
|
||||||
|
|
||||||
|
sys.stdout.write('Configure django...\n')
|
||||||
|
add_settings_file = os.path.join('etc', 'django', 'additional_settings.py')
|
||||||
|
with open(settings_file, 'a') as f_out:
|
||||||
|
with open(add_settings_file) as f_in:
|
||||||
|
f_out.write(f_in.read())
|
||||||
|
|
||||||
|
sys.stdout.write('Creating directories...\n')
|
||||||
|
dirs = [
|
||||||
|
os.path.join('var', 'db'),
|
||||||
|
os.path.join('var', 'log'),
|
||||||
|
os.path.join('var', 'www', 'static'),
|
||||||
|
]
|
||||||
|
for d in dirs:
|
||||||
|
sys.stdout.write(' - %s\n' % d)
|
||||||
|
if not os.path.exists(d):
|
||||||
|
os.makedirs(d)
|
||||||
|
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='django-test',
|
||||||
|
version='1.0',
|
||||||
|
description='An example django based web application.',
|
||||||
|
url='https://heinzelwelt.de',
|
||||||
|
maintainer='Jens Kleineheismann',
|
||||||
|
maintainer_email='heinzel@heinzelwelt.de',
|
||||||
|
cmdclass={
|
||||||
|
'mkpyenv': CreatePythonEnvironment,
|
||||||
|
'setup': SetupDjangoProject,
|
||||||
|
},
|
||||||
|
packages=find_packages(),
|
||||||
|
include_package_data=True,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user