glpkg 1.3.0__tar.gz → 1.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {glpkg-1.3.0/src/glpkg.egg-info → glpkg-1.4.1}/PKG-INFO +33 -9
- {glpkg-1.3.0 → glpkg-1.4.1}/README.md +32 -8
- {glpkg-1.3.0 → glpkg-1.4.1}/src/gitlab/__init__.py +1 -1
- {glpkg-1.3.0 → glpkg-1.4.1}/src/gitlab/__main__.py +0 -5
- {glpkg-1.3.0 → glpkg-1.4.1}/src/gitlab/cli_handler.py +67 -9
- glpkg-1.4.1/src/gitlab/packages.py +623 -0
- {glpkg-1.3.0 → glpkg-1.4.1/src/glpkg.egg-info}/PKG-INFO +33 -9
- {glpkg-1.3.0 → glpkg-1.4.1}/test/test_packages.py +66 -29
- glpkg-1.3.0/src/gitlab/packages.py +0 -457
- {glpkg-1.3.0 → glpkg-1.4.1}/LICENSE.md +0 -0
- {glpkg-1.3.0 → glpkg-1.4.1}/pyproject.toml +0 -0
- {glpkg-1.3.0 → glpkg-1.4.1}/setup.cfg +0 -0
- {glpkg-1.3.0 → glpkg-1.4.1}/src/glpkg.egg-info/SOURCES.txt +0 -0
- {glpkg-1.3.0 → glpkg-1.4.1}/src/glpkg.egg-info/dependency_links.txt +0 -0
- {glpkg-1.3.0 → glpkg-1.4.1}/src/glpkg.egg-info/entry_points.txt +0 -0
- {glpkg-1.3.0 → glpkg-1.4.1}/src/glpkg.egg-info/top_level.txt +0 -0
- {glpkg-1.3.0 → glpkg-1.4.1}/test/test_cli_handler.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: glpkg
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.1
|
|
4
4
|
Summary: Tool to make GitLab generic package registry operations easy.
|
|
5
5
|
Author-email: bugproduction <bugproduction@outlook.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,6 +15,7 @@ Dynamic: license-file
|
|
|
15
15
|
|
|
16
16
|
glpkg is a tool that makes it easy to work with [GitLab generic packages](https://docs.gitlab.com/user/packages/generic_packages/).
|
|
17
17
|
|
|
18
|
+
Generic package registries of GitLab projects are supported. Group registries are not, as the GitLab REST API for groups is very limited.
|
|
18
19
|
|
|
19
20
|
## Installation
|
|
20
21
|
|
|
@@ -26,7 +27,6 @@ pip install glpkg
|
|
|
26
27
|
|
|
27
28
|
To check the installation and version, run:
|
|
28
29
|
|
|
29
|
-
|
|
30
30
|
```bash
|
|
31
31
|
glpkg --version
|
|
32
32
|
```
|
|
@@ -117,6 +117,37 @@ glpkg upload --project 12345 --name mypackagename --version 1.0 --source upload
|
|
|
117
117
|
|
|
118
118
|
Note: a file in `upload` folder will be uploaded to the root of the package. If you want to upload the file to a `dir` folder in the package, make a structure in the upload folder, like `upload/dir/`.
|
|
119
119
|
|
|
120
|
+
### Delete a file from a generic package
|
|
121
|
+
|
|
122
|
+
To delete a file from a specific generic package, run
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
glpkg delete --project 12345 --name mypackagename --version 1.0 --file my-file.txt
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Where
|
|
129
|
+
- `12345` is your projects ID ([Find the Project ID](https://docs.gitlab.com/user/project/working_with_projects/#find-the-project-id)) or the path of the project (like `namespace/project`)
|
|
130
|
+
- `mypackagename` is the name of the generic package
|
|
131
|
+
- `1.0` is the version of the generic package from the file is deleted
|
|
132
|
+
- `my-file.txt` is the file that is deleted. Only relative paths are supported. Note that the package may contain multiple files with same name. In this case, one file of them is deleted.
|
|
133
|
+
|
|
134
|
+
The token that is used to delete files must have at least Maintainer role in the project.
|
|
135
|
+
|
|
136
|
+
### Delete a package version
|
|
137
|
+
|
|
138
|
+
To delete a specific generic package version, run
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
glpkg delete --project 12345 --name mypackagename --version 1.0
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Where
|
|
145
|
+
- `12345` is your projects ID ([Find the Project ID](https://docs.gitlab.com/user/project/working_with_projects/#find-the-project-id)) or the path of the project (like `namespace/project`)
|
|
146
|
+
- `mypackagename` is the name of the generic package
|
|
147
|
+
- `1.0` is the version of the generic package that is deleted
|
|
148
|
+
|
|
149
|
+
The token that is used to delete packages must have at least Maintainer role in the project.
|
|
150
|
+
|
|
120
151
|
### Use in GitLab pipelines
|
|
121
152
|
|
|
122
153
|
If you use the tool in a GitLab pipeline, setting argument `--ci` uses [GitLab predefined variables](https://docs.gitlab.com/ci/variables/predefined_variables/) to configure the tool. In this case `CI_SERVER_HOST`, `CI_PROJECT_ID`, and `CI_JOB_TOKEN` environment variables are used. The `--project`, and `--token` arguments can still be used to override the project ID or to use a personal or project access token instead of `CI_JOB_TOKEN`.
|
|
@@ -128,10 +159,3 @@ glpkg upload --ci --name mypackagename --version 1.0 --file my-file.txt
|
|
|
128
159
|
```
|
|
129
160
|
|
|
130
161
|
To use the `CI_JOB_TOKEN` with package registry of another projects, add `--project <otherproject ID>` argument. Remember that you may need to add [permissions for the CI_JOB_TOKEN](https://docs.gitlab.com/ci/jobs/ci_job_token/#control-job-token-access-to-your-project) in the other project.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
## Limitations
|
|
134
|
-
|
|
135
|
-
The tool is not perfect (yet) and has limitations. The following limitations are known, but more can exist:
|
|
136
|
-
|
|
137
|
-
- Only project registries are supported for now.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
glpkg is a tool that makes it easy to work with [GitLab generic packages](https://docs.gitlab.com/user/packages/generic_packages/).
|
|
4
4
|
|
|
5
|
+
Generic package registries of GitLab projects are supported. Group registries are not, as the GitLab REST API for groups is very limited.
|
|
5
6
|
|
|
6
7
|
## Installation
|
|
7
8
|
|
|
@@ -13,7 +14,6 @@ pip install glpkg
|
|
|
13
14
|
|
|
14
15
|
To check the installation and version, run:
|
|
15
16
|
|
|
16
|
-
|
|
17
17
|
```bash
|
|
18
18
|
glpkg --version
|
|
19
19
|
```
|
|
@@ -104,6 +104,37 @@ glpkg upload --project 12345 --name mypackagename --version 1.0 --source upload
|
|
|
104
104
|
|
|
105
105
|
Note: a file in `upload` folder will be uploaded to the root of the package. If you want to upload the file to a `dir` folder in the package, make a structure in the upload folder, like `upload/dir/`.
|
|
106
106
|
|
|
107
|
+
### Delete a file from a generic package
|
|
108
|
+
|
|
109
|
+
To delete a file from a specific generic package, run
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
glpkg delete --project 12345 --name mypackagename --version 1.0 --file my-file.txt
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Where
|
|
116
|
+
- `12345` is your projects ID ([Find the Project ID](https://docs.gitlab.com/user/project/working_with_projects/#find-the-project-id)) or the path of the project (like `namespace/project`)
|
|
117
|
+
- `mypackagename` is the name of the generic package
|
|
118
|
+
- `1.0` is the version of the generic package from the file is deleted
|
|
119
|
+
- `my-file.txt` is the file that is deleted. Only relative paths are supported. Note that the package may contain multiple files with same name. In this case, one file of them is deleted.
|
|
120
|
+
|
|
121
|
+
The token that is used to delete files must have at least Maintainer role in the project.
|
|
122
|
+
|
|
123
|
+
### Delete a package version
|
|
124
|
+
|
|
125
|
+
To delete a specific generic package version, run
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
glpkg delete --project 12345 --name mypackagename --version 1.0
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Where
|
|
132
|
+
- `12345` is your projects ID ([Find the Project ID](https://docs.gitlab.com/user/project/working_with_projects/#find-the-project-id)) or the path of the project (like `namespace/project`)
|
|
133
|
+
- `mypackagename` is the name of the generic package
|
|
134
|
+
- `1.0` is the version of the generic package that is deleted
|
|
135
|
+
|
|
136
|
+
The token that is used to delete packages must have at least Maintainer role in the project.
|
|
137
|
+
|
|
107
138
|
### Use in GitLab pipelines
|
|
108
139
|
|
|
109
140
|
If you use the tool in a GitLab pipeline, setting argument `--ci` uses [GitLab predefined variables](https://docs.gitlab.com/ci/variables/predefined_variables/) to configure the tool. In this case `CI_SERVER_HOST`, `CI_PROJECT_ID`, and `CI_JOB_TOKEN` environment variables are used. The `--project`, and `--token` arguments can still be used to override the project ID or to use a personal or project access token instead of `CI_JOB_TOKEN`.
|
|
@@ -115,10 +146,3 @@ glpkg upload --ci --name mypackagename --version 1.0 --file my-file.txt
|
|
|
115
146
|
```
|
|
116
147
|
|
|
117
148
|
To use the `CI_JOB_TOKEN` with package registry of another projects, add `--project <otherproject ID>` argument. Remember that you may need to add [permissions for the CI_JOB_TOKEN](https://docs.gitlab.com/ci/jobs/ci_job_token/#control-job-token-access-to-your-project) in the other project.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
## Limitations
|
|
121
|
-
|
|
122
|
-
The tool is not perfect (yet) and has limitations. The following limitations are known, but more can exist:
|
|
123
|
-
|
|
124
|
-
- Only project registries are supported for now.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""GitLab packages main module"""
|
|
2
2
|
|
|
3
|
-
import logging
|
|
4
3
|
import sys
|
|
5
4
|
|
|
6
5
|
from gitlab.cli_handler import CLIHandler
|
|
@@ -17,10 +16,6 @@ def cli() -> int:
|
|
|
17
16
|
int
|
|
18
17
|
Zero when everything is fine, non-zero otherwise.
|
|
19
18
|
"""
|
|
20
|
-
logging.basicConfig(
|
|
21
|
-
level=logging.DEBUG,
|
|
22
|
-
handlers=[logging.FileHandler("glpkg.log")], # , logging.StreamHandler()],
|
|
23
|
-
)
|
|
24
19
|
handler = CLIHandler()
|
|
25
20
|
return handler.do_it()
|
|
26
21
|
|
|
@@ -40,6 +40,13 @@ class CLIHandler:
|
|
|
40
40
|
name="upload", description="Uploads file to a specific package version."
|
|
41
41
|
)
|
|
42
42
|
self._register_upload_parser(upload_parser)
|
|
43
|
+
delete_parser = subparsers.add_parser(
|
|
44
|
+
name="delete",
|
|
45
|
+
description="Deletes a specific package version or a specific file from "
|
|
46
|
+
"a specific package version, depending whether the --file argument is "
|
|
47
|
+
"set or not.",
|
|
48
|
+
)
|
|
49
|
+
self._register_delete_parser(delete_parser)
|
|
43
50
|
self.args = parser.parse_args()
|
|
44
51
|
|
|
45
52
|
def _print_version(self, _args: argparse.Namespace) -> int:
|
|
@@ -240,16 +247,16 @@ class CLIHandler:
|
|
|
240
247
|
host, project, name, token_user, token = self._args(args)
|
|
241
248
|
version = args.version
|
|
242
249
|
destination = args.destination
|
|
243
|
-
|
|
244
|
-
package_id =
|
|
250
|
+
packages = Packages(host, token_user, token)
|
|
251
|
+
package_id = packages.get_id(project, name, version)
|
|
245
252
|
if package_id:
|
|
246
253
|
files = []
|
|
247
254
|
if args.file:
|
|
248
255
|
files.append(args.file)
|
|
249
256
|
else:
|
|
250
|
-
files =
|
|
257
|
+
files = packages.get_files(project, package_id).keys()
|
|
251
258
|
for file in files:
|
|
252
|
-
ret =
|
|
259
|
+
ret = packages.download_file(project, name, version, file, destination)
|
|
253
260
|
if ret:
|
|
254
261
|
print("Failed to download file " + file)
|
|
255
262
|
break
|
|
@@ -287,10 +294,10 @@ class CLIHandler:
|
|
|
287
294
|
Zero if everything goes well, non-zero otherwise
|
|
288
295
|
"""
|
|
289
296
|
host, project, name, token_user, token = self._args(args)
|
|
290
|
-
|
|
291
|
-
|
|
297
|
+
packages = Packages(host, token_user, token)
|
|
298
|
+
package_list = packages.get_versions(project, name)
|
|
292
299
|
print("Name" + "\t\t" + "Version")
|
|
293
|
-
for package in
|
|
300
|
+
for package in package_list:
|
|
294
301
|
print(package["name"] + "\t" + package["version"])
|
|
295
302
|
|
|
296
303
|
def _register_upload_parser(self, parser: argparse.ArgumentParser):
|
|
@@ -356,6 +363,57 @@ class CLIHandler:
|
|
|
356
363
|
print("File " + file + " does not exist!")
|
|
357
364
|
ret = 1
|
|
358
365
|
if not ret:
|
|
359
|
-
|
|
360
|
-
ret =
|
|
366
|
+
packages = Packages(host, token_user, token)
|
|
367
|
+
ret = packages.upload_file(project, name, version, file, source)
|
|
368
|
+
return ret
|
|
369
|
+
|
|
370
|
+
def _register_delete_parser(self, parser: argparse.ArgumentParser):
|
|
371
|
+
"""
|
|
372
|
+
Registers the delete command related arguments to the parser:
|
|
373
|
+
- version
|
|
374
|
+
- file
|
|
375
|
+
- action
|
|
376
|
+
|
|
377
|
+
Additionally, registers the common args.
|
|
378
|
+
|
|
379
|
+
Parameters
|
|
380
|
+
----------
|
|
381
|
+
parser:
|
|
382
|
+
The argparser where to register the upload arguments.
|
|
383
|
+
"""
|
|
384
|
+
self._register_common_arguments(parser)
|
|
385
|
+
parser.add_argument("-v", "--version", type=str, help="The package version.")
|
|
386
|
+
parser.add_argument(
|
|
387
|
+
"-f",
|
|
388
|
+
"--file",
|
|
389
|
+
type=str,
|
|
390
|
+
help="The file to be deleted, for example my_file.txt. Note that "
|
|
391
|
+
"only relative paths (to the package root) are supported. If undefined, "
|
|
392
|
+
"the package version is deleted.",
|
|
393
|
+
)
|
|
394
|
+
parser.set_defaults(action=self._delete)
|
|
395
|
+
|
|
396
|
+
def _delete(self, args: argparse.Namespace) -> int:
|
|
397
|
+
"""
|
|
398
|
+
Deletes a file from a GitLab generic package
|
|
399
|
+
|
|
400
|
+
Parameters
|
|
401
|
+
----------
|
|
402
|
+
args : argparse.Namespace
|
|
403
|
+
The arguments from command line
|
|
404
|
+
|
|
405
|
+
Returns
|
|
406
|
+
-------
|
|
407
|
+
int
|
|
408
|
+
Zero if everything went fine, non-zero otherwise.
|
|
409
|
+
"""
|
|
410
|
+
ret = 0
|
|
411
|
+
host, project, name, token_user, token = self._args(args)
|
|
412
|
+
version = args.version
|
|
413
|
+
file = args.file
|
|
414
|
+
packages = Packages(host, token_user, token)
|
|
415
|
+
if file:
|
|
416
|
+
ret = packages.delete_file(project, name, version, file)
|
|
417
|
+
else:
|
|
418
|
+
ret = packages.delete_package(project, name, version)
|
|
361
419
|
return ret
|