kopia lustrzana https://github.com/rtts/django-simplecms
The `simplecms` command is now a proper entrypoint
rodzic
07d5aaea9c
commit
e228763052
|
@ -0,0 +1,48 @@
|
||||||
|
import os, argparse, shutil, example
|
||||||
|
from pip._internal.operations import freeze as pip
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description='SimpleCMS')
|
||||||
|
parser.add_argument('project_name', nargs='?')
|
||||||
|
if project_name := parser.parse_args().project_name:
|
||||||
|
project_dir = os.path.join(os.getcwd(), project_name)
|
||||||
|
else:
|
||||||
|
project_name = os.path.basename(os.getcwd())
|
||||||
|
project_dir = os.getcwd()
|
||||||
|
if input(f'Do you want to create a new project in `{project_dir}` ?\033[1D') in 'Yy':
|
||||||
|
create_project(project_name, project_dir)
|
||||||
|
|
||||||
|
def create_project(project_name, project_dir):
|
||||||
|
os.makedirs(project_dir, exist_ok=True)
|
||||||
|
with open(os.path.join(project_dir, 'requirements.txt'), 'w') as f:
|
||||||
|
for line in pip.freeze():
|
||||||
|
|
||||||
|
# Central point of failure
|
||||||
|
if 'django_simplecms' in line:
|
||||||
|
line = 'git+https://github.com/rtts/django-simplecms'
|
||||||
|
|
||||||
|
print(line, file=f)
|
||||||
|
|
||||||
|
shutil.copytree(os.path.dirname(example.__file__), os.path.join(project_dir, project_name), dirs_exist_ok=True)
|
||||||
|
with open(os.open(os.path.join(project_dir, 'manage.py'), os.O_CREAT|os.O_WRONLY, 0o755), 'w') as f:
|
||||||
|
print('''#!/usr/bin/env python
|
||||||
|
import os, sys
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{project_name}.settings')
|
||||||
|
from django.core.management import execute_from_command_line
|
||||||
|
execute_from_command_line(sys.argv)''', file=f)
|
||||||
|
with open(os.path.join(project_dir, '.gitignore'), 'w') as f:
|
||||||
|
print('*.pyc\n__pycache__/', file=f)
|
||||||
|
|
||||||
|
print(f'''
|
||||||
|
Successfully created project "{project_name}"
|
||||||
|
|
||||||
|
Things to do next:
|
||||||
|
- create a database
|
||||||
|
- ./manage.py makemigrations
|
||||||
|
- ./manage.py migrate
|
||||||
|
- ./manage.py createsuperuser
|
||||||
|
- ./manage.py runserver
|
||||||
|
''')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -1,28 +0,0 @@
|
||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
test -z $1 && echo "Please provide a project name!" && exit 1
|
|
||||||
mkdir "$1"
|
|
||||||
cd "$1"
|
|
||||||
pip3 freeze > requirements.txt
|
|
||||||
example_dir=$(python3 -c 'import os,example;print(os.path.dirname(example.__file__))')
|
|
||||||
cp -r "$example_dir" "$1"
|
|
||||||
cp "$example_dir"/../manage.py .
|
|
||||||
sed -i "s/example/$1/" manage.py
|
|
||||||
sed -i "s/example/$1/" "$1"/wsgi.py
|
|
||||||
cat << EOF > .gitignore
|
|
||||||
*.pyc
|
|
||||||
__pycache__/
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cat <<EOF
|
|
||||||
|
|
||||||
Successfully created project "$1"!
|
|
||||||
|
|
||||||
Things to do next:
|
|
||||||
- create a database
|
|
||||||
- ./manage.py makemigrations
|
|
||||||
- ./manage.py migrate
|
|
||||||
- ./manage.py createsuperuser
|
|
||||||
- ./manage.py runserver --nostatic
|
|
||||||
|
|
||||||
EOF
|
|
6
setup.py
6
setup.py
|
@ -3,13 +3,15 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = 'django-simplecms',
|
name = 'django-simplecms',
|
||||||
version = '1.0.2',
|
version = '1.0.3',
|
||||||
url = 'https://github.com/rtts/django-simplecms',
|
url = 'https://github.com/rtts/django-simplecms',
|
||||||
author = 'Jaap Joris Vens',
|
author = 'Jaap Joris Vens',
|
||||||
author_email = 'jj@rtts.eu',
|
author_email = 'jj@rtts.eu',
|
||||||
license = 'GPL3',
|
license = 'GPL3',
|
||||||
packages = find_packages(),
|
packages = find_packages(),
|
||||||
scripts = ['cms/bin/simplecms'],
|
entry_points = {
|
||||||
|
'console_scripts': ['simplecms=cms.__main__:main'],
|
||||||
|
},
|
||||||
include_package_data = True,
|
include_package_data = True,
|
||||||
install_requires = [
|
install_requires = [
|
||||||
'django',
|
'django',
|
||||||
|
|
Ładowanie…
Reference in New Issue