.. _djangoCli: ====================== Command line interface ====================== .. index:: cli, commands, scripts, command line interface You can perform several operations from the command line using Django commands, Fleio commands and BASH scripts. .. contents:: :local: .. _django-command: Django and Fleio commands ========================= For Django and Fleio commands you need enter the Fleio utils docker container and to activate the Python virtual environment first. .. _activate-virtual-environment: Activate the virtual environment -------------------------------- Connect via SSH to the machine where Fleio is installed and run: .. code-block:: bash fleio bash9 . /var/webapps/fleio/env/bin/activate List the Django and Fleio commands ================================== To see a list of available commands just run ``django help``. Note that ``django`` is a shortcut for ``python manage.py``. So you get the same effect if you run ``python manage.py help``. Here's the ``django help`` output: .. code-block:: bash $ django help Type 'manage.py help ' for help on a specific subcommand. Available subcommands: [auth] changepassword createsuperuser [authtoken] drf_create_token [billing] refresh_eu_tax_exempt [contenttypes] remove_stale_contenttypes [core] dbbackup feature_enabled fleio_edition fleio_info testdbconn [django] check compilemessages createcachetable dbshell diffsettings dumpdata flush inspectdb loaddata makemessages makemigrations migrate runserver sendtestemail shell showmigrations sqlflush sqlmigrate sqlsequencereset squashmigrations startapp startproject test testserver [django_extensions] admin_generator clean_pyc clear_cache compile_pyc create_command create_jobs create_template_tags delete_squashed_migrations describe_form drop_test_database dumpscript export_emails find_template generate_password generate_secret_key graph_models list_model_info list_signals mail_debug managestate merge_model_instances notes pipchecker print_settings print_user_for_session raise_test_exception reset_db reset_schema runjob runjobs runprofileserver runscript runserver_plus set_default_site set_fake_emails set_fake_passwords shell_plus show_template_tags show_urls sqlcreate sqldiff sqldsn sync_s3 syncdata unreferenced_files update_permissions validate_templates [rest_framework] generateschema [sessions] clearsessions .. _django-shell: Django shell ============ The Django shell is a command line environment where you can run Python commands in the context of the Fleio project, that is the settings are loaded, including things like database connection settings and the Django model classes (used to interact with the database tables). To enter the Django shell run: .. code-block:: bash fleio shell Once you're into the shell, you can can for instance list the Fleio users: .. code-block:: bash >>> AppUser.objects.all() , , , ]> >>> Just press **CTRL + D** to exit the Django shell or type in ``exit()``. Reset admin password -------------------- You can change any Fleio user password from the command line, including the admin/staff user password. Connect via SSH to the machine where Fleio is installed and :ref:`activate the virtual environment `. Then run: .. code-block:: bash django changepassword <> If you can't remember the username either, you can run a query on the Fleio database and see the list of users: .. code-block:: bash fleio mysql MariaDB [fleio]> SELECT email FROM core_appuser; +---------------+ | username | +---------------+ | demo@demo.com | | joen@doe.com | +---------------+ 2 rows in set (0.00 sec) BASH and Python scripting ========================= You can interactively browser through Fleio files or create a staff user with commands like .. code-block:: bash fleio bash Creating fleio_utils_run ... done fleio@utils:~/project$ ls binaries common common_admin enduser fleio fleiodockerutils fleiostaff locale manage.py plugins requirements.txt reseller fleio@utils:~/project$ . ../env/bin/activate (env) fleio@utils:~/project$ django createsuperuser Email: and you can run BASH commands non-interactively, directly from the host where Fleio is installed. For instance to list the contents of you ``settings.py`` file: .. code-block:: bash fleio bash cat /var/webapps/fleio/project/fleio/fleiosettings/settings.py and even run django commands one-liners that also require the Python virtual environment to by activated: .. code-block:: bash # show Django version echo ". ../env/bin/activate; django version" | fleio bash Creating fleio_utils_run ... done 4.0.7 Database (MariaDB) console ========================== You can authenticate and open the MySQL/MariaDB console with: .. code-block:: bash fleio mysql and you can get a dump of your database with: .. code-block:: bash fleio mysqldump