endi.scripts package¶
Submodules¶
endi.scripts.endi_admin module¶
Command to add an admin to enDI
- class endi.scripts.endi_admin.AbstractCommand¶
Bases :
objectDocstring will be used as CLI doc
- classmethod add_arguments(parser: ArgumentParser) None¶
Adds arguments to the subcmd parser
no-op if no special arguments is used for the subcmd
- Paramètres:
parser – the sub-command parser already added to main CMD subparsers
- name = None¶
- class endi.scripts.endi_admin.EndiAdminCommandsRegistry¶
Bases :
object- BASE_COMMANDS = [<class 'endi.scripts.endi_admin.UserAddcommand'>, <class 'endi.scripts.endi_admin.TestMailCommand'>, <class 'endi.scripts.endi_admin.SyncdbCommand'>, <class 'endi.scripts.endi_admin.ResizeHeadersCommand'>, <class 'endi.scripts.endi_admin.SendNotificationCommand'>]¶
- EXTRA_COMMANDS = []¶
- classmethod get_argument_parser()¶
- class endi.scripts.endi_admin.ResizeHeadersCommand¶
Bases :
AbstractCommandbulk resize company header files to limit pdf size
- classmethod add_arguments(parser) None¶
Adds arguments to the subcmd parser
no-op if no special arguments is used for the subcmd
- Paramètres:
parser – the sub-command parser already added to main CMD subparsers
- name = 'resize_headers'¶
- class endi.scripts.endi_admin.SendNotificationCommand¶
Bases :
AbstractCommandenvoie une notification à des utilisateurs TODO : envoie avec un délai (pas encore implémenté dans le script)
- classmethod add_arguments(parser) None¶
Adds arguments to the subcmd parser
no-op if no special arguments is used for the subcmd
- Paramètres:
parser – the sub-command parser already added to main CMD subparsers
- name = 'notify'¶
- class endi.scripts.endi_admin.SyncdbCommand¶
Bases :
AbstractCommandPopulate the database with the initial datas
- classmethod add_arguments(parser) None¶
Adds arguments to the subcmd parser
no-op if no special arguments is used for the subcmd
- Paramètres:
parser – the sub-command parser already added to main CMD subparsers
- name = 'syncdb'¶
- class endi.scripts.endi_admin.TestMailCommand¶
Bases :
AbstractCommandTest tool for mail sending
- classmethod add_arguments(parser) None¶
Adds arguments to the subcmd parser
no-op if no special arguments is used for the subcmd
- Paramètres:
parser – the sub-command parser already added to main CMD subparsers
- name = 'testmail'¶
- class endi.scripts.endi_admin.UserAddcommand¶
Bases :
AbstractCommandAdd a user in the database
- classmethod add_arguments(parser) None¶
Adds arguments to the subcmd parser
no-op if no special arguments is used for the subcmd
- Paramètres:
parser – the sub-command parser already added to main CMD subparsers
- name = 'useradd'¶
- endi.scripts.endi_admin.admin_entry_point()¶
endi.scripts.endi_anonymize module¶
Script used to anonymize the content of the current database ( remove names, customer personnal infos, personnal datas …)
- class endi.scripts.endi_anonymize.Anonymizer(logger)¶
Bases :
object- run()¶
- endi.scripts.endi_anonymize.anonymize_entry_point()¶
- endi.scripts.endi_anonymize.list_command(args, env)¶
List available methods
- endi.scripts.endi_anonymize.run_command(args, env)¶
Run command, run one or more anonymization method
- endi.scripts.endi_anonymize.set_if_present(obj, field_name, value)¶
endi.scripts.endi_cache module¶
- endi.scripts.endi_cache.cache_entry_point()¶
- endi.scripts.endi_cache.get_parser() ArgumentParser¶
- endi.scripts.endi_cache.purge_pdf_files_command(arguments, env)¶
Purge cached pdf files older than a given number of days
- endi.scripts.endi_cache.refresh_task_amount_command(arguments, env)¶
Refresh the task amount cache
Refresh only the tasks after a given date.
- endi.scripts.endi_cache.refresh_task_pdf_command(arguments, env)¶
Refresh task’s pdf cached files
- endi.scripts.endi_cache.sync_progress_task_amounts_command(arguments, env)¶
Sync amounts on progress invoicing tasks (all or given)
Possibly restricting to a certain task by id.
- endi.scripts.endi_cache.sync_sale_product_amount_command(arguments, env)¶
Refresh sale catalog amounts
endi.scripts.endi_clean module¶
- endi.scripts.endi_clean.clean_business_command(arguments, env)¶
Clean business instances (without tasks associated to it)
- endi.scripts.endi_clean.clean_entry_point()¶
enDI cleaning tools Usage:
endi-clean <config_uri> business endi-clean <config_uri> catalog_and_price_cache
- Options:
-h –help Show this screen.
- endi.scripts.endi_clean.clean_price_study_and_sale_product_totals(arguments, env)¶
Synchronize all the cached totals of all elements of the Sale product catalog and the price study
endi.scripts.endi_company_export module¶
- class endi.scripts.endi_company_export.DatabaseCleaner(company, logger)¶
Bases :
objectClass used to clean the database and remove all informations not concerning the given company
- add_admin(env)¶
- run()¶
- endi.scripts.endi_company_export.company_export_command(arguments, env)¶
Entry point for the company export tools
- endi.scripts.endi_company_export.company_export_entry_point()¶
Company export utilitiy tool
Clean the databases configured in the config_uri file and the files directory
- Usage:
endi-company-export <config_uri> company CID
- Arguments:
CID Company object id
- Options:
-h –help Show this screen
endi.scripts.endi_custom module¶
- endi.scripts.endi_custom.custom_entry_point()¶
Script custom utilisé en production avant/après migration
- Usage:
endi-custom <config_uri> load_edp_from_json [–filepath=<filepath>] endi-custom <config_uri> run_notify_on_existing [–type=<type>]
o load_edp_from_json : Charge des edps depuis un fichier json o run_notify_on_existing : Génère des notifications pour les éléments existants
- Options:
-h –help Show this screen –filepath=<filepath> Chemin vers le fichier à importer –type=<type> Type d’activité à notifier (activity / userdatas)
- endi.scripts.endi_custom.load_edp_from_json_command(args, env)¶
- endi.scripts.endi_custom.run_notify_on_existing(args, env)¶
endi.scripts.endi_export module¶
- endi.scripts.endi_export.export_entry_point()¶
Export utilitiy tool, stream csv datas in stdout Usage:
endi-export <config_uri> userdatas [–fields=<fields>] [–where=<where>] endi-export <config_uri> invoices_pdf [–destdir=<destdir>] [–where=<where>] endi-export <config_uri> stats
- Options:
-h –help Show this screen –fields=<fields> Export the comma separated list of fields –where=<where> Query parameters in json format descrbing statistic options –destdir=<destdir> The directory where we output the datas
o userdatas : Export userdatas as csv format o invoices_pdf : Export Invoices and CancelInvoices in pdf format o stats : Export anonymized UserDatas to /tmp in xls format
Streams the output in stdout
endi-export app.ini userdatas –fields=coordonnees_address,coordonnees_zipcode,coordonnees_city, coordonnees_sex,coordonnees_birthday,statut_social_status, coordonnees_study_level,parcours_date_info_coll,parcours_prescripteur, parcours_convention_cape,activity_typologie,sortie_date,sortie_motif –where=”[{« key »: »created_at », »method »: »dr », »type »: »date », « search1 »: »1999-01-01 », »search2 »: »2016-12-31 »}]” > /tmp/toto.csv
endi-export
- endi.scripts.endi_export.export_stats_command(args, env)¶
CPE stats export for 2019
endi-export app.ini stats
- endi.scripts.endi_export.export_userdatas_command(args, env)¶
Export userdatas as csv format
Streams the output in stdout
endi-export app.ini userdatas –fields=coordonnees_address,coordonnees_zipcode,coordonnees_city, coordonnees_sex,coordonnees_birthday,statut_social_status, coordonnees_study_level,parcours_date_info_coll,parcours_prescripteur, parcours_convention_cape,activity_typologie,sortie_date,sortie_motif –where=”[{« key »: »created_at », »method »: »dr », »type »: »date », « search1 »: »1999-01-01 », »search2 »: »2016-12-31 »}]” > /tmp/toto.csv
- Paramètres:
app
- endi.scripts.endi_export.invoices_pdf_command(args, env)¶
export pdf of the documents matching the given parameters
endi.scripts.endi_load_demo_data module¶
- class endi.scripts.endi_load_demo_data.DumpFetcher¶
Bases :
objectEnsure existence and validity of reference dump (and fix it if needed).
- COMPRESSED_DUMP_FILENAME = 'endi-anonymous-6.7.sql.bz2'¶
- COMPRESSED_DUMP_URL = 'https://upload.majerti.fr/endi-anonymous-6.7.sql.bz2'¶
- DUMP_FILENAME = 'endi-anonymous-6.7.sql'¶
- DUMP_SHA256SUM = '70bf1631b7c392532a6d1da8e779158577e6b9d97ef43c65c27146d8d0631e90'¶
- classmethod checksum_ok()¶
- classmethod fetch_reference_dump(insecure_fetch=False)¶
- classmethod needs_download()¶
- endi.scripts.endi_load_demo_data.load_demo_data_entry_point()¶
Download (if required) and load reference dump into database. Usage:
endi-load-demo-data <config_uri>
Requires those tools installed : bunzip2, wget, sha256sum, mysql. Writes downloaded files in current dir
- endi.scripts.endi_load_demo_data.load_dump(dump_path)¶
endi.scripts.endi_migrate module¶
Migration related command line scripts for enDI
- class endi.scripts.endi_migrate.PackageEnvironment(pkg, sql_url=None)¶
Bases :
objectpackage environment Here we use one but it could be usefull when handling plugins” migrations
- property pkg_name¶
- run_env(fn, **kw)¶
run alembic’s context
- property version_table¶
Return the name of the table hosting alembic’s current revision
- class endi.scripts.endi_migrate.ScriptDirectoryWithDefaultEnvPy(dir, file_template='%(rev)s_%(slug)s', truncate_slug_length=40, version_locations=None, sourceless=False, output_encoding='utf-8', timezone=None, hook_config=None)¶
Bases :
ScriptDirectoryWrapper for the ScriptDirectory object enforce the env.py script
- property env_py_location¶
- run_env()¶
Run the script environment.
This basically runs the
env.pyscript present in the migration environment. It is called exclusively by the command functions inalembic.command.
- endi.scripts.endi_migrate.downgrade_command(pkg, revision)¶
downgrade the content of DEFAULT_LOCATION
- endi.scripts.endi_migrate.fetch_command(pkg, revision=None)¶
fetch a revision without migrating
- endi.scripts.endi_migrate.fetch_head_command(pkg='endi')¶
fetch the latest revision
- endi.scripts.endi_migrate.get_location(pkg_name)¶
Return the location of the alembic stuff in : separated format
- Type renvoyé:
- endi.scripts.endi_migrate.get_script_directory(pkg_name)¶
Build the script directory that should be used for migrations
- endi.scripts.endi_migrate.list_command(pkg)¶
list all available revisions
- endi.scripts.endi_migrate.merge_command(pkg, rev1=None, rev2=None)¶
- endi.scripts.endi_migrate.migrate_entry_point()¶
Migrate enDI’s database Usage:
migrate <config_uri> list [–pkg=<pkg>] migrate <config_uri> upgrade [–rev=<rev>] [–pkg=<pkg>] migrate <config_uri> fetch [–rev=<rev>] [–pkg=<pkg>] migrate <config_uri> revision [–m=<message>] [–empty] [–pkg=<pkg>] migrate <config_uri> downgrade [–rev=<rev>] [–pkg=<pkg>] migrate <config_uri> merge [–rev1=<rev>] [–rev2=<rev>] [–pkg=<pkg>]
o list : all the revisions o upgrade : upgrade the app to the latest revision o revision : create a migration file with the given message (trying to detect changes, unless –empty is used) o fetch : set the revision o downgrade : downgrade the database o merge : create a merge revision between two diverging revisions (you might ommit –rev*, they will get autodected)
- Options:
-h –help Show this screen.
- endi.scripts.endi_migrate.revision_command(pkg, message, empty=False)¶
- endi.scripts.endi_migrate.upgrade_command(pkg, revision, sql_url=None)¶
upgrade the content of the database at sql_url
endi.scripts.utils module¶
script utility, allows the use of the app’s context (database, models …) from within command line calls
- endi.scripts.utils.argparse_command(func, argparser: ArgumentParser, pyramid_env=None)¶
Wrap command line scripts, using argparse builtin module
- endi.scripts.utils.command(func, doc)¶
Usefull function to wrap command line scripts using docopt lib
/!if starting to use this commande, you may want to use argparse_command() instead. (docopt is deprecated).
If at any time, this commande becomes unused, remove it, and remove docopt from requirements.
- endi.scripts.utils.get_argument_value(arguments, key, default=None)¶
Return the value for an argument named key in arguments or default
- endi.scripts.utils.get_value(arguments, key, default=None)¶
Return the value of an option named key in arguments or default