glpkg 1.1.0__py3-none-any.whl → 1.2.0__py3-none-any.whl

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.
gitlab/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from gitlab.packages import Packages
2
2
 
3
- __version__ = "1.1.0"
3
+ __version__ = "1.2.0"
gitlab/cli_handler.py CHANGED
@@ -1,6 +1,8 @@
1
1
  import argparse
2
2
  import netrc
3
3
  import os
4
+ import sys
5
+ import urllib
4
6
  from gitlab import Packages, __version__
5
7
 
6
8
 
@@ -33,7 +35,20 @@ class CLIHandler:
33
35
  return 0
34
36
 
35
37
  def do_it(self) -> int:
36
- return self.args.action(self.args)
38
+ ret = 1
39
+ try:
40
+ ret = self.args.action(self.args)
41
+ except urllib.error.HTTPError as e:
42
+ # GitLab API returns 404 when a resource is not found
43
+ # but also when the user has no access to the resource
44
+ print("Oops! Something did go wrong.", file=sys.stderr)
45
+ print(e, file=sys.stderr)
46
+ print(
47
+ "Note that Error 404 may also indicate authentication issues with GitLab API.",
48
+ file=sys.stderr,
49
+ )
50
+ print("Check your arguments and credentials.", file=sys.stderr)
51
+ return ret
37
52
 
38
53
  def _register_common_arguments(self, parser) -> None:
39
54
  group = parser.add_mutually_exclusive_group()
@@ -73,6 +88,19 @@ class CLIHandler:
73
88
  def _register_download_parser(self, parser):
74
89
  self._register_common_arguments(parser)
75
90
  parser.add_argument("-v", "--version", type=str, help="The package version.")
91
+ parser.add_argument(
92
+ "-f",
93
+ "--file",
94
+ type=str,
95
+ help="The file to download from the package. If not defined, all files are downloaded.",
96
+ )
97
+ parser.add_argument(
98
+ "-d",
99
+ "--destination",
100
+ default="",
101
+ type=str,
102
+ help="The path where the file(s) are downloaded. If not defined, the current working directory is used.",
103
+ )
76
104
  parser.set_defaults(action=self._download_handler)
77
105
 
78
106
  def _args(self, args):
@@ -101,12 +129,17 @@ class CLIHandler:
101
129
  ret = 1
102
130
  host, project, name, token_user, token = self._args(args)
103
131
  version = args.version
132
+ destination = args.destination
104
133
  gitlab = Packages(host, token_user, token)
105
134
  package_id = gitlab.get_package_id(project, name, version)
106
135
  if package_id:
107
- files = gitlab.list_files(project, package_id)
136
+ files = []
137
+ if args.file:
138
+ files.append(args.file)
139
+ else:
140
+ files = gitlab.list_files(project, package_id)
108
141
  for file in files:
109
- ret = gitlab.download_file(project, name, version, file)
142
+ ret = gitlab.download_file(project, name, version, file, destination)
110
143
  if ret:
111
144
  print("Failed to download file " + file)
112
145
  break
gitlab/packages.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from http.client import HTTPMessage
2
2
  import json
3
3
  import logging
4
+ import os
4
5
  from urllib import request, parse
5
6
 
6
7
  logger = logging.getLogger(__name__)
@@ -118,10 +119,15 @@ class Packages:
118
119
  return id
119
120
 
120
121
  def download_file(
121
- self, project: str, package_name: str, package_version: str, file: str
122
+ self,
123
+ project: str,
124
+ package_name: str,
125
+ package_version: str,
126
+ filename: str,
127
+ destination: str = "",
122
128
  ) -> int:
123
129
  ret = 1
124
- logger.debug("Downloading file " + file)
130
+ logger.debug("Downloading file " + filename)
125
131
  url = (
126
132
  self.project_api_url(project)
127
133
  + "packages/generic/"
@@ -129,11 +135,18 @@ class Packages:
129
135
  + "/"
130
136
  + parse.quote_plus(package_version)
131
137
  + "/"
132
- + parse.quote(str(file))
138
+ + parse.quote(filename)
133
139
  )
134
140
  status, data, _ = self._request(url)
135
141
  if status == 200:
136
- with open(str(file), "wb") as file:
142
+ path = os.path.join(destination, filename)
143
+ parent = os.path.dirname(path)
144
+ if parent:
145
+ # Create missing directories if needed
146
+ # In case path has no parent, current
147
+ # workind directory is used
148
+ os.makedirs(os.path.dirname(path), exist_ok=True)
149
+ with open(path, "wb") as file:
137
150
  file.write(data)
138
151
  ret = 0
139
152
  return ret
@@ -1,25 +1,19 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: glpkg
3
- Version: 1.1.0
3
+ Version: 1.2.0
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
7
7
  Project-URL: Repository, https://gitlab.com/bugproduction/glpkg.git
8
8
  Keywords: GitLab,packages,registry,generic
9
+ Requires-Python: >=3.9
9
10
  Description-Content-Type: text/markdown
10
11
  License-File: LICENSE.md
11
- Provides-Extra: dev
12
- Requires-Dist: black; extra == "dev"
13
- Requires-Dist: build; extra == "dev"
14
- Requires-Dist: pytest; extra == "dev"
15
- Requires-Dist: pytest-cov; extra == "dev"
16
- Requires-Dist: setuptools; extra == "dev"
17
- Requires-Dist: twine; extra == "dev"
18
12
  Dynamic: license-file
19
13
 
20
- # glpkg - GitLab Generic Package registry tools
14
+ # glpkg - GitLab Generic Package tools
21
15
 
22
- glpkg is a tool that makes it easy to work with [GitLab generic package registry](https://docs.gitlab.com/user/packages/generic_packages/).
16
+ glpkg is a tool that makes it easy to work with [GitLab generic packages](https://docs.gitlab.com/user/packages/generic_packages/).
23
17
 
24
18
 
25
19
  ## Installation
@@ -47,7 +41,11 @@ By default, the used GitLab host is gitlab.com. If you use a self-hosted GitLab,
47
41
 
48
42
  To authenticate with the package registry in any of the commands below, use `--token readapitoken123` argument where the `readapitoken123` is a [personal](https://docs.gitlab.com/user/profile/personal_access_tokens/#create-a-personal-access-token) or [project](https://docs.gitlab.com/user/project/settings/project_access_tokens/#create-a-project-access-token) access token, with read API scope. In case the package registry is public, you can omit this argument.
49
43
 
50
- The above arguments are omitted in the examples below to focus on the functions. Add the arguments to change the host or to authenticate with the registry.
44
+ Alternatively you can use a token stored in your `.netrc` file by setting `--netrc` argument.
45
+
46
+ > If you use the tool in GitLab CI, read [below](#Use-in-GitLab-pipelines) on how to use the `CI_JOB_TOKEN`.
47
+
48
+ The arguments related to the GitLab host or authentication (`--token`, `--netrc`, and `--ci`) are omitted in the examples below to focus on the commands.
51
49
 
52
50
  In general, run `glpkg --help` when needed.
53
51
 
@@ -74,7 +72,7 @@ mypackagename 2.0
74
72
 
75
73
  ### Download generic package
76
74
 
77
- To download everything from a specific generic package, run
75
+ To download all files from a specific version of a generic package, run
78
76
 
79
77
  ```bash
80
78
  glpkg download --project 12345 --name mypackagename --version 1.0
@@ -85,7 +83,13 @@ Where:
85
83
  - `mypackagename` is the name of the generic package
86
84
  - `1.0` is the version of the generic package from which the files are downloaded
87
85
 
88
- The files will be downloaded in the current working directory. Any pre-existing files will be overridden without warning.
86
+ By default the files will be downloaded in the current working directory. To download the files to another directory, add argument `--destination` to the command. In all cases, as long as you have permissions to the destination directory, any pre-existing files will be overridden without warning.
87
+
88
+ To download only a specific file from the package, add `--file` argument.
89
+
90
+ ```bash
91
+ glpkg download --project 12345 --name mypackagename --version 1.5 --file the_only_one --destination /temp
92
+ ```
89
93
 
90
94
  > If a package has multiple files with the same filename, the tool can only download the newest file. This is a restriction of GitLab API.
91
95
 
@@ -107,7 +111,7 @@ Where:
107
111
 
108
112
  ### Use in GitLab pipelines
109
113
 
110
- If you use the tool in a GitLab pipeline, using `--ci` argument 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 and to use a personal or project access token instead of CI_JOB_TOKEN.
114
+ 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`.
111
115
 
112
116
  In other words, you don't need to give the `--host`, `--project`, or `--token` arguments if you are interacting with the package registry of the project where the pipeline is running. Example: uploading `my-file.txt` to generic package `mypackagename` version `1.0` in the project package registry in CI:
113
117
 
@@ -0,0 +1,10 @@
1
+ gitlab/__init__.py,sha256=U83zG_KkowpY9GMPLmmySx5fyNx52nojUJkfIpzMo5o,60
2
+ gitlab/__main__.py,sha256=88VNY5Qrmn8g0rNcnjKNdN746--0chHsKBMH3PD3Nao,177
3
+ gitlab/cli_handler.py,sha256=RKEEcbxFCFkT8sbYDlMXuQPM4wvCb0okBiFfUXXlJtg,7314
4
+ gitlab/packages.py,sha256=8w5bc5I03dEqkMcLydqtgQ9UN2SJWw7MlkjnJXp6fmA,6099
5
+ glpkg-1.2.0.dist-info/licenses/LICENSE.md,sha256=josGXvZq628dNS0Iru58-DPE7dRpDXzjJxKKT35103g,1065
6
+ glpkg-1.2.0.dist-info/METADATA,sha256=cVhMx6Gt_Nx1RkXNeetlu8f7__dkO5y1c2jOncFlZT8,5841
7
+ glpkg-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ glpkg-1.2.0.dist-info/entry_points.txt,sha256=xHPZwx2oShYDZ3AyH7WSIvuhFMssy7QLlQk-JAbje_w,46
9
+ glpkg-1.2.0.dist-info/top_level.txt,sha256=MvIaP8p_Oaf4gO_hXmHkX-5y2deHLp1pe6tJR3ukQ6o,7
10
+ glpkg-1.2.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- gitlab/__init__.py,sha256=EsSFZxYgGAL2i0sL5zkoz71JP7XbsWdg_jv_uOqrrXE,60
2
- gitlab/__main__.py,sha256=88VNY5Qrmn8g0rNcnjKNdN746--0chHsKBMH3PD3Nao,177
3
- gitlab/cli_handler.py,sha256=6B22RXAtOzVL-mpm7U3OPX1_SSrepQk12cwTG0TI3eU,6102
4
- gitlab/packages.py,sha256=l9tFEUsHMWF0vtv5ouVB4nvmWrJ4KDaS6f5e1lpjNyk,5683
5
- glpkg-1.1.0.dist-info/licenses/LICENSE.md,sha256=josGXvZq628dNS0Iru58-DPE7dRpDXzjJxKKT35103g,1065
6
- glpkg-1.1.0.dist-info/METADATA,sha256=65URv9IMuUo1XnmqKolpuJ12nkjcFKJg8rKMz4XeUIQ,5500
7
- glpkg-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- glpkg-1.1.0.dist-info/entry_points.txt,sha256=xHPZwx2oShYDZ3AyH7WSIvuhFMssy7QLlQk-JAbje_w,46
9
- glpkg-1.1.0.dist-info/top_level.txt,sha256=MvIaP8p_Oaf4gO_hXmHkX-5y2deHLp1pe6tJR3ukQ6o,7
10
- glpkg-1.1.0.dist-info/RECORD,,
File without changes