Commits (4)
......@@ -6,7 +6,7 @@ qa:
stage: test
image: yourlabs/python
script: pip install django . && py.test -v
script: ./sh.yml test
stage: deploy
......@@ -9,7 +9,7 @@ Refer to ``djcli/tests/*.txt`` for reference output.
[jpic@hack djcli]$ djcli
[jpic@hack djcli]$ djcli
djcli: time for CLI party !
Will try to auto-detect $DJANGO_SETTINGS_MODULE by searching for settings.py
......@@ -17,8 +17,11 @@ Refer to ``djcli/tests/*.txt`` for reference output.
help Get help for a command.
chpasswd Change the password for user.
dbcheck Check all database connections.
delete Delete a model filtered with kwargs.
detail Print detail for a model.
ls Search models
run Execute a callback in Django context.
save Update or create a model.
settings Show settings from django.
setting Show settings from django.
settings Print out DJANGO_SETTINGS_MODULE.
......@@ -154,7 +154,7 @@ def detail(modelname, *args, **kwargs):
djcli cat pk=123
djcli widgets.Widget pk=123
model = _model_get(modelname)
obj = model.objects.get(**kwargs)
......@@ -165,6 +165,24 @@ def detail(modelname, *args, **kwargs):
def run(callback, *args, **kwargs):
"""Execute a callback in Django context.
Args and kwargs are forwarded to callee.
djcli run yourapp.models.somecallback
importable = cli2.Importable.factory(callback)
if importable.target is None:
raise cli2.Cli2Exception('Could not import ' + callback)
elif callable(importable.target):
return importable.target(*args, **kwargs)
return importable.target
def chpasswd(password, **kwargs):
"""Change the password for user.
......@@ -13,6 +13,9 @@ setup(
keywords='django cli',
install_requires=['cli2', 'tabulate'],
'test': ['django', 'pytest', 'pytest-cov', 'pytest-django'],
'console_scripts': [
'djcli = djcli:console_script',
#!/usr/bin/env shyml
name: install
help: |
Setup and activate a venv for a python executable
If venv=none, it will not do any venv.
If venv=user, it will use pip install --user.
script: |
if [ "${venv-}" = "user" ]; then
pip_install="pip install --user"
elif [ "${venv-}" != "none" ]; then
export python="${python-python3}"
export path="${path-.venv.$python}"
test -d $path || virtualenv --python=$python $path
set +eux; echo activating $path; source $path/bin/activate; set -eux
${pip_install-pip install} -Ue .[test]
name: test
help: Run test in a python3 venv by default.
script: shyml_install && py.test -vv --cov --strict -r fEsxXw ${@-.}
......@@ -20,6 +20,10 @@ import cli2
('delete_empty', 'delete auth.user username'),
('dbcheck_available', 'dbcheck'),
('dbcheck_available_debug', 'dbcheck --debug'),
('run_non_importable', 'run django.fake.should.fail'),
'run django.core.management.commands.loaddata.humanize /foo/bar'),
('run_noncallable', 'run django.core.checks.messages.ERROR'),
def test_djcli_empty(name, command):
command: djcli run django.core.management.commands.loaddata.humanize /foo/bar
retcode: 1
command: djcli run django.fake.should.fail
retcode: 1
Could not import django.fake.should.fail
command: djcli run django.core.checks.messages.ERROR
retcode: 1
......@@ -163,6 +163,7 @@ LANGUAGES=[('af', 'Afrikaans'),
('hr', 'Croatian'),
('hsb', 'Upper Sorbian'),
('hu', 'Hungarian'),
('hy', 'Armenian'),
('ia', 'Interlingua'),
('id', 'Indonesian'),
('io', 'Ido'),