mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Are more methods to tasks.py:
- static - update - install - key - coverage The functionality of setup.py is now included here!
This commit is contained in:
parent
f4debeac47
commit
05fae4be87
@ -1,68 +0,0 @@
|
|||||||
"""
|
|
||||||
Performs initial setup functions.
|
|
||||||
|
|
||||||
- Generates a Django SECRET_KEY file to be used by manage.py
|
|
||||||
- Copies config template file (if a config file does not already exist)
|
|
||||||
"""
|
|
||||||
|
|
||||||
import random
|
|
||||||
import string
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import argparse
|
|
||||||
from shutil import copyfile
|
|
||||||
|
|
||||||
OUTPUT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
|
|
||||||
KEY_FN = 'secret_key.txt'
|
|
||||||
CONFIG_FN = 'config.yaml'
|
|
||||||
CONFIG_TEMPLATE_FN = 'config_template.yaml'
|
|
||||||
|
|
||||||
|
|
||||||
def generate_key(length=50):
|
|
||||||
""" Generate a random string
|
|
||||||
|
|
||||||
Args:
|
|
||||||
length: Number of characters in returned string (default = 50)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Randomized secret key string
|
|
||||||
"""
|
|
||||||
|
|
||||||
options = string.digits + string.ascii_letters + string.punctuation
|
|
||||||
key = ''.join([random.choice(options) for i in range(length)])
|
|
||||||
return key
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Generate Django SECRET_KEY file')
|
|
||||||
parser.add_argument('--force', '-f', help='Override existing files', action='store_true')
|
|
||||||
parser.add_argument('--dummy', '-d', help='Dummy run (do not create any files)', action='store_true')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
# Places to store files
|
|
||||||
key_filename = os.path.join(OUTPUT_DIR, KEY_FN)
|
|
||||||
conf_template = os.path.join(OUTPUT_DIR, CONFIG_TEMPLATE_FN)
|
|
||||||
conf_filename = os.path.join(OUTPUT_DIR, CONFIG_FN)
|
|
||||||
|
|
||||||
# Generate secret key data
|
|
||||||
key_data = generate_key()
|
|
||||||
|
|
||||||
if args.dummy:
|
|
||||||
print('SECRET_KEY: {k}'.format(k=key_data))
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
if not args.force and os.path.exists(key_filename):
|
|
||||||
print("Key file already exists - '{f}'".format(f=key_filename))
|
|
||||||
else:
|
|
||||||
with open(key_filename, 'w') as key_file:
|
|
||||||
print("Generating SECRET_KEY file - '{f}'".format(f=key_filename))
|
|
||||||
key_file.write(key_data)
|
|
||||||
|
|
||||||
if not args.force and os.path.exists(conf_filename):
|
|
||||||
print("Config file already exists (skipping)")
|
|
||||||
else:
|
|
||||||
print("Copying config template to 'config.yaml'")
|
|
||||||
copyfile(conf_template, conf_filename)
|
|
25
Makefile
25
Makefile
@ -7,24 +7,6 @@ clean:
|
|||||||
rm -rf .tox
|
rm -rf .tox
|
||||||
rm -f .coverage
|
rm -f .coverage
|
||||||
|
|
||||||
update: install migrate static
|
|
||||||
|
|
||||||
# Perform database migrations (after schema changes are made)
|
|
||||||
migrate:
|
|
||||||
cd InvenTree && python3 manage.py makemigrations
|
|
||||||
cd InvenTree && python3 manage.py migrate
|
|
||||||
cd InvenTree && python3 manage.py migrate --run-syncdb
|
|
||||||
cd InvenTree && python3 manage.py check
|
|
||||||
|
|
||||||
# Collect static files into the correct locations
|
|
||||||
static:
|
|
||||||
cd InvenTree && python3 manage.py collectstatic
|
|
||||||
|
|
||||||
# Install all required packages
|
|
||||||
install:
|
|
||||||
pip3 install -U -r requirements.txt
|
|
||||||
cd InvenTree && python3 setup.py
|
|
||||||
|
|
||||||
# Create a superuser account
|
# Create a superuser account
|
||||||
superuser:
|
superuser:
|
||||||
cd InvenTree && python3 manage.py createsuperuser
|
cd InvenTree && python3 manage.py createsuperuser
|
||||||
@ -53,11 +35,6 @@ test:
|
|||||||
cd InvenTree && python3 manage.py check
|
cd InvenTree && python3 manage.py check
|
||||||
cd InvenTree && python3 manage.py test barcode build common company label order part report stock InvenTree
|
cd InvenTree && python3 manage.py test barcode build common company label order part report stock InvenTree
|
||||||
|
|
||||||
# Run code coverage
|
|
||||||
coverage:
|
|
||||||
cd InvenTree && python3 manage.py check
|
|
||||||
coverage run InvenTree/manage.py test barcode build common company label order part report stock InvenTree
|
|
||||||
coverage html
|
|
||||||
|
|
||||||
# Install packages required to generate code docs
|
# Install packages required to generate code docs
|
||||||
docreqs:
|
docreqs:
|
||||||
@ -71,5 +48,3 @@ docs:
|
|||||||
backup:
|
backup:
|
||||||
cd InvenTree && python3 manage.py dbbackup
|
cd InvenTree && python3 manage.py dbbackup
|
||||||
cd InvenTree && python3 manage.py mediabackup
|
cd InvenTree && python3 manage.py mediabackup
|
||||||
|
|
||||||
.PHONY: clean migrate superuser install mysql postgresql translate static style test coverage docreqs docs backup update
|
|
@ -17,7 +17,7 @@ django-import-export==2.0.0 # Data import / export for admin interface
|
|||||||
django-cleanup==4.0.0 # Manage deletion of old / unused uploaded files
|
django-cleanup==4.0.0 # Manage deletion of old / unused uploaded files
|
||||||
django-qr-code==1.2.0 # Generate QR codes
|
django-qr-code==1.2.0 # Generate QR codes
|
||||||
flake8==3.8.3 # PEP checking
|
flake8==3.8.3 # PEP checking
|
||||||
coverage==4.0.3 # Unit test coverage
|
coverage==5.2.1 # Unit test coverage
|
||||||
python-coveralls==2.9.1 # Coveralls linking (for Travis)
|
python-coveralls==2.9.1 # Coveralls linking (for Travis)
|
||||||
rapidfuzz==0.7.6 # Fuzzy string matching
|
rapidfuzz==0.7.6 # Fuzzy string matching
|
||||||
django-stdimage==5.1.1 # Advanced ImageField management
|
django-stdimage==5.1.1 # Advanced ImageField management
|
||||||
|
110
tasks.py
110
tasks.py
@ -1,9 +1,30 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from invoke import task
|
from invoke import task
|
||||||
|
from shutil import copyfile
|
||||||
|
|
||||||
|
import random
|
||||||
|
import string
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
def apps():
|
||||||
|
"""
|
||||||
|
Returns a list of installed apps
|
||||||
|
"""
|
||||||
|
|
||||||
|
return [
|
||||||
|
'barcode',
|
||||||
|
'build',
|
||||||
|
'common',
|
||||||
|
'company',
|
||||||
|
'label',
|
||||||
|
'order',
|
||||||
|
'part',
|
||||||
|
'report',
|
||||||
|
'stock',
|
||||||
|
'InvenTree'
|
||||||
|
]
|
||||||
|
|
||||||
def localDir():
|
def localDir():
|
||||||
"""
|
"""
|
||||||
Returns the directory of *THIS* file.
|
Returns the directory of *THIS* file.
|
||||||
@ -24,7 +45,7 @@ def managePyPath():
|
|||||||
Return the path of the manage.py file
|
Return the path of the manage.py file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return os.path.join(managePyDir, 'manage.py')
|
return os.path.join(managePyDir(), 'manage.py')
|
||||||
|
|
||||||
def manage(c, cmd):
|
def manage(c, cmd):
|
||||||
"""
|
"""
|
||||||
@ -40,6 +61,45 @@ def manage(c, cmd):
|
|||||||
cmd=cmd
|
cmd=cmd
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@task(help={'length': 'Length of secret key (default=50)'})
|
||||||
|
def key(c, length=50, force=False):
|
||||||
|
"""
|
||||||
|
Generates a SECRET_KEY file which InvenTree uses for generating security hashes
|
||||||
|
"""
|
||||||
|
|
||||||
|
SECRET_KEY_FILE = os.path.join(localDir(), 'InvenTree', 'secret_key.txt')
|
||||||
|
|
||||||
|
# If a SECRET_KEY file does not exist, generate a new one!
|
||||||
|
if force or not os.path.exists(SECRET_KEY_FILE):
|
||||||
|
print("Generating SECRET_KEY file - " + SECRET_KEY_FILE)
|
||||||
|
with open(SECRET_KEY_FILE, 'w') as key_file:
|
||||||
|
options = string.digits + string.ascii_letters + string.punctuation
|
||||||
|
|
||||||
|
key = ''.join([random.choice(options) for i in range(length)])
|
||||||
|
|
||||||
|
key_file.write(key)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("SECRET_KEY file already exists - skipping")
|
||||||
|
|
||||||
|
|
||||||
|
@task(post=[key])
|
||||||
|
def install(c):
|
||||||
|
"""
|
||||||
|
Installs required python packages, and runs initial setup functions.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Install required Python packages with PIP
|
||||||
|
#c.run('pip3 install -U -r requirements.txt')
|
||||||
|
|
||||||
|
# If a config.yaml file does not exist, copy from the template!
|
||||||
|
CONFIG_FILE = os.path.join(localDir(), 'InvenTree', 'config.yaml')
|
||||||
|
CONFIG_TEMPLATE_FILE = os.path.join(localDir(), 'InvenTree', 'config_template.yaml')
|
||||||
|
|
||||||
|
if not os.path.exists(CONFIG_FILE):
|
||||||
|
print("Config file 'config.yaml' does not exist - copying from template.")
|
||||||
|
copyfile(CONFIG_TEMPLATE_FILE, CONFIG_FILE)
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def migrate(c):
|
def migrate(c):
|
||||||
"""
|
"""
|
||||||
@ -58,6 +118,50 @@ def migrate(c):
|
|||||||
print("========================================")
|
print("========================================")
|
||||||
print("InvenTree database migrations completed!")
|
print("InvenTree database migrations completed!")
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def test(c):
|
def static(c):
|
||||||
print("hello!")
|
"""
|
||||||
|
Copies required static files to the STATIC_ROOT directory,
|
||||||
|
as per Django requirements.
|
||||||
|
"""
|
||||||
|
|
||||||
|
manage(c, "collectstatic")
|
||||||
|
|
||||||
|
|
||||||
|
@task(pre=[install, migrate, static])
|
||||||
|
def update(c):
|
||||||
|
"""
|
||||||
|
Update InvenTree installation.
|
||||||
|
|
||||||
|
This command should be invoked after source code has been updated,
|
||||||
|
e.g. downloading new code from GitHub.
|
||||||
|
|
||||||
|
The following tasks are performed, in order:
|
||||||
|
|
||||||
|
- install
|
||||||
|
- migrate
|
||||||
|
- static
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@task
|
||||||
|
def coverage(c):
|
||||||
|
"""
|
||||||
|
Run code-coverage of the InvenTree codebase,
|
||||||
|
using the 'coverage' code-analysis tools.
|
||||||
|
|
||||||
|
Generates a code coverage report (available in the htmlcov directory)
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Run sanity check on the django install
|
||||||
|
manage(c, 'check')
|
||||||
|
|
||||||
|
# Run coverage tests
|
||||||
|
c.run('coverage run {manage} test {apps}'.format(
|
||||||
|
manage=managePyPath(),
|
||||||
|
apps=' '.join(apps())
|
||||||
|
))
|
||||||
|
|
||||||
|
# Generate coverage report
|
||||||
|
c.run('coverage html')
|
Loading…
Reference in New Issue
Block a user