Show More
@@ -12,13 +12,50 b' Here is how to force delete a repository' | |||||
12 |
|
12 | |||
13 |
|
13 | |||
14 | .. code-block:: bash |
|
14 | .. code-block:: bash | |
|
15 | :dedent: 1 | |||
15 |
|
16 | |||
16 | # starts the ishell interactive prompt |
|
17 | # starts the ishell interactive prompt | |
17 | $ rccontrol ishell enterprise-1 |
|
18 | $ rccontrol ishell enterprise-1 | |
18 |
|
19 | |||
19 | .. code-block:: python |
|
20 | .. code-block:: python | |
|
21 | :dedent: 1 | |||
20 |
|
22 | |||
21 | In [4]: from rhodecode.model.repo import RepoModel |
|
23 | In [4]: from rhodecode.model.repo import RepoModel | |
22 | In [3]: repo = Repository.get_by_repo_name('test_repos/repo_with_prs') |
|
24 | In [3]: repo = Repository.get_by_repo_name('test_repos/repo_with_prs') | |
23 | In [5]: RepoModel().delete(repo, forks='detach', pull_requests='delete') |
|
25 | In [5]: RepoModel().delete(repo, forks='detach', pull_requests='delete') | |
24 | In [6]: Session().commit() |
|
26 | In [6]: Session().commit() | |
|
27 | ||||
|
28 | ||||
|
29 | Below is a fully automated example to force delete repositories reading from a | |||
|
30 | file where each line is a repository name. This can be executed via simple CLI command | |||
|
31 | without entering the interactive shell. | |||
|
32 | ||||
|
33 | Save the below content as a file named `repo_delete_task.py` | |||
|
34 | ||||
|
35 | ||||
|
36 | .. code-block:: python | |||
|
37 | :dedent: 1 | |||
|
38 | ||||
|
39 | from rhodecode.model.db import * | |||
|
40 | from rhodecode.model.repo import RepoModel | |||
|
41 | with open('delete_repos.txt', 'rb') as f: | |||
|
42 | # read all lines from file | |||
|
43 | repos = f.readlines() | |||
|
44 | for repo_name in repos: | |||
|
45 | repo_name = repo_name.strip() # cleanup the name just in case | |||
|
46 | repo = Repository.get_by_repo_name(repo_name) | |||
|
47 | if not repo: | |||
|
48 | raise Exception('Repo with name {} not found'.format(repo_name)) | |||
|
49 | RepoModel().delete(repo, forks='detach', pull_requests='delete') | |||
|
50 | Session().commit() | |||
|
51 | print('Removed repository {}'.format(repo_name)) | |||
|
52 | ||||
|
53 | ||||
|
54 | The code above will read the names of repositories from a file called `delete_repos.txt` | |||
|
55 | Each lines should represent a single name e.g `repo_name_1` or `repo_group/repo_name_2` | |||
|
56 | ||||
|
57 | Run this line from CLI to execute the code from the `repo_delete_task.py` file and | |||
|
58 | exit the ishell after the execution:: | |||
|
59 | ||||
|
60 | echo "%run repo_delete_task.py" | rccontrol ishell Enterprise-1 | |||
|
61 |
General Comments 0
You need to be logged in to leave comments.
Login now