|
| 1 | +# Introduction |
| 2 | +This guide details how to use the custom `manage.py` shell commands. All |
| 3 | +commands can be invoked using the shell command format: |
| 4 | + |
| 5 | +```shell script |
| 6 | +python manage.py <command name> --settings=settings.<your settings module> |
| 7 | +``` |
| 8 | + |
| 9 | +You can omit the settings argument to use the default settings module (the |
| 10 | +module imported in `mavedb/settings.py`). |
| 11 | + |
| 12 | +## Django-reversion |
| 13 | +[Django-reversion](https://django-reversion.readthedocs.io/en/stable/) has been |
| 14 | +integrated with the site. This is a well maintained model versioning application |
| 15 | +that keeps a history of each instance in the database for models that have been |
| 16 | +registered. There are two key commands to run when deploying: |
| 17 | + |
| 18 | +```python manage.py migrate |
| 19 | +python manage.py createinitialrevisions |
| 20 | +``` |
| 21 | + |
| 22 | +To delete the recorded history for a particular model: |
| 23 | + |
| 24 | +```bash |
| 25 | +python manage.py deleterevisions <appname.modelname> --keep=[int] --days=[int] |
| 26 | +``` |
| 27 | + |
| 28 | +This will keep anything from last *n* `days` or `keep` at least *n* history |
| 29 | +items. |
| 30 | + |
| 31 | +# Custom Commands |
| 32 | + |
| 33 | +## createlicences |
| 34 | +This command expects the file `data/main/licenes.json` and folder |
| 35 | +`data/main/licence_legal_code` containing the licence text for your licences. |
| 36 | +The `licences.json` file should follow the format below: |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "licences": [ |
| 41 | + { |
| 42 | + "short_name": "CC0", |
| 43 | + "long_name": "CC0 (Public domain)", |
| 44 | + "legal_code": { |
| 45 | + "file": true, |
| 46 | + "value": "CC0.txt" |
| 47 | + }, |
| 48 | + "logo": "cc-zero.svg", |
| 49 | + "link": "https://creativecommons.org/publicdomain/zero/1.0/", |
| 50 | + "version": "1.0" |
| 51 | + }, |
| 52 | + { |
| 53 | + "short_name": "Other - See Data Usage Guidelines", |
| 54 | + "long_name": "Other - See Data Usage Guidelines", |
| 55 | + "legal_code": { |
| 56 | + "file": false, |
| 57 | + "value": "See Data Usage Guidelines" |
| 58 | + }, |
| 59 | + "logo": "", |
| 60 | + "link": "", |
| 61 | + "version": "1.0" |
| 62 | + } |
| 63 | + ] |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +This file specifies a list of licences to create/update. This command has no |
| 68 | +arguments. Existing licences matching `short_name` in the json file will be |
| 69 | +updated. |
| 70 | + |
| 71 | + |
| 72 | +## createreferences |
| 73 | +This command expects the file `data/genome/reference_genomes.json` The |
| 74 | +`reference_genomes.json` file should follow the format below: |
| 75 | + |
| 76 | +```json |
| 77 | +[ |
| 78 | + { |
| 79 | + "assembly_identifier": { |
| 80 | + "dbname": "GenomeAssembly", |
| 81 | + "dbversion": null, |
| 82 | + "identifier": "GCF_000001405.10", |
| 83 | + "url": "http://www.ncbi.nlm.nih.gov/assembly/GCF_000001405.10" |
| 84 | + }, |
| 85 | + "short_name": "hg16", |
| 86 | + "organism_name": "Homo sapiens" |
| 87 | + }, |
| 88 | + { |
| 89 | + "assembly_identifier": null, |
| 90 | + "short_name": "Synthetic", |
| 91 | + "organism_name": "Synthetic sequence" |
| 92 | + } |
| 93 | +] |
| 94 | +``` |
| 95 | + |
| 96 | +This file specifies a list of reference genomes to create/update. This command |
| 97 | +has no arguments. Only entries with a `short_name` that does not exist will be |
| 98 | +created. Existing instances will not be updated since other models rely on the |
| 99 | +`ReferenceGenome` table. |
| 100 | + |
| 101 | +## savereferences |
| 102 | +This command will serialize the `ReferenceGenome` models into |
| 103 | +`data/genome/reference_genomes.json`. It will overwrite any existing file. This |
| 104 | +command accepts no arguments. |
| 105 | + |
| 106 | +## updatesiteinfo |
| 107 | +Invoke this command to updat the `SiteInformation` singleton row. It expects |
| 108 | +the file `data/main/site_info.json` to exist with the following format: |
| 109 | + |
| 110 | +```json |
| 111 | +{ |
| 112 | + "branch": "", |
| 113 | + "md_about": "about.md", |
| 114 | + "md_citation": "", |
| 115 | + "md_documentation": "userdocs.md", |
| 116 | + "md_privacy": "", |
| 117 | + "md_terms": "", |
| 118 | + "md_usage_guide": "", |
| 119 | + "version": "1.6.3-beta" |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +You can specify markdown files on fields with the `md_` prefix (must be saved |
| 124 | +in the same directory as the JSON file) to set as the field text. This command |
| 125 | +accepts no arguments. |
| 126 | + |
| 127 | +## savesiteinfo |
| 128 | +This command will serialize the `SiteInformation` singleton into |
| 129 | +`data/main/site_info.json`. It will overwrite any existing file. This command |
| 130 | +accepts no arguments. |
| 131 | + |
| 132 | +## geterror |
| 133 | +This command displays a detailed celery error for a given `task_id` and `username`. |
| 134 | +The `username` specifies the submitting user's ORCID. This command must be |
| 135 | +invoked as: |
| 136 | + |
| 137 | +```shell script |
| 138 | +python manage.py geterror --task_id=<task-uuid> --username=<ORCID> |
| 139 | +``` |
| 140 | + |
| 141 | +## renamegroups |
| 142 | +This command renames the contributor groups for all `ScoreSets`, `ExperimentSets` |
| 143 | +and `Experiments`. It was used to correct a naming bug in production so it should |
| 144 | +not be necessary to run this again. This command accepts no arguments. |
| 145 | + |
| 146 | +## renumber |
| 147 | +This command renumbers the `Variants` in a `ScoreSet` starting from 1. It was |
| 148 | +used to correct a numbering bug in production so it should not be necessary to |
| 149 | +run this again. This command must be invoked as: |
| 150 | + |
| 151 | +```shell script |
| 152 | +python manage.py renumber --urns=<space separated urns> --all |
| 153 | +``` |
| 154 | + |
| 155 | +Specify a list of space-separated urns to correct, or alternatively set the |
| 156 | +boolean flag `--all` to correct all `ScoreSets`. |
| 157 | + |
| 158 | +## savesitestats |
| 159 | +Export a gzipped tarball containing site page view statistics. Specify an |
| 160 | +absolute save path with the `--path` argument. |
| 161 | + |
| 162 | +## setprivate |
| 163 | +Set a `ScoreSet`, `Experiment` or `ExperimentSet` as private. It is recommended |
| 164 | +that it is used only on `ScoreSet` models. Settings parent models as private |
| 165 | +will not alter child models. This could create strange behaviour such as not |
| 166 | +being able to view the parent of a public child. Invoke the command as: |
| 167 | + |
| 168 | +```shell script |
| 169 | +python manage.py setprivate --urn=<model-urn> |
| 170 | +``` |
| 171 | + |
| 172 | +## setstate |
| 173 | +Set a the celery state of a `ScoreSet`. Invoke the command as: |
| 174 | + |
| 175 | +```shell script |
| 176 | +python manage.py setprivate --urn=<model-urn> --state=<state text> |
| 177 | +``` |
| 178 | + |
| 179 | +The `state` argument will accept the values `processing`, `failed` or `success`. |
| 180 | + |
| 181 | +## createnews |
| 182 | +Create a news item for the landing page. Invoke the command as: |
| 183 | + |
| 184 | +```shell script |
| 185 | +python manage.py createnews --message=<string message> --level=<string level> |
| 186 | +``` |
| 187 | + |
| 188 | +The `message` argument can specify a string message or a markdown file. The |
| 189 | +`level` argument can take the values `Critical`, `Important`, `Information`, |
| 190 | +`Happy holidays` or `April fools`. |
| 191 | + |
| 192 | +## createtestentries |
| 193 | +For development purposes to seed the database with test entries. Also creates |
| 194 | +test users with the password `1234qwer` and username `user-<number>` where |
| 195 | +number ranges from 1 to 40. |
| 196 | + |
| 197 | +## createdefaultsecrets |
| 198 | +Creates a default secrets json file. Used by settings module to create a secrets |
| 199 | +file if one does not exist. This should not be called directly. |
| 200 | + |
| 201 | +## cleanusers |
| 202 | +Deletes accounts with malicious looking usernames. Pass `--commit` to commit changes, otherwise |
| 203 | +it is run in dry mode and will only list accounts that will be deleted. Pass a list of comma separated |
| 204 | +usernames via `--exclude` to ignore these associated accounts. |
0 commit comments