Skip to content

Commit a5f4654

Browse files
committed
Improve distribution parsing, and fix folder and tag check for publication
1 parent 2030c15 commit a5f4654

File tree

3 files changed

+96
-43
lines changed

3 files changed

+96
-43
lines changed

prestashop_docker/generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def generate_image(self, ps_version, container_version):
9393
use_github_url = False
9494

9595
if use_github_url:
96-
if parsed_version['flavor_versions'] == 'classic':
96+
if parsed_version['distribution'] == 'classic':
9797
ps_url = self.download_url_github_classic.format(ps_version, ps_version)
9898
else:
9999
ps_url = self.download_url_github.format(ps_version, ps_version)

prestashop_docker/version_manager.py

+26-14
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,29 @@ def parse_version(self, version):
6565
'''
6666

6767
data = self.get_version_from_string(version)
68+
if data is None:
69+
raise ValueError('{} is not a valid version'.format(version))
70+
6871
if data is not None and data['ps_version'] == self.NIGHTLY:
6972
ps_version = self.NIGHTLY
7073
else:
71-
# Initial PS version(can also be a branch like 9.0.x)
7274
split_version = self.split_prestashop_version(version)
73-
if split_version is None or not (self.directory_path / split_version['version']).exists():
74-
raise ValueError('{} is not a valid version'.format(version))
75-
ps_version = split_version['version']
75+
if split_version is not None and split_version['patch'] == 'x':
76+
# Special case for branch versions (like 9.0.x)
77+
ps_version = split_version['version']
78+
else:
79+
# Other use case we get the parsed version (stripped from container details)
80+
ps_version = data['ps_version']
81+
82+
ps_version_path = self.directory_path / ps_version
83+
if not ps_version_path.exists():
84+
raise ValueError('{} directory not found for version {}'.format(ps_version_path, version))
7685

7786
if data is None or data['container_version'] is None:
7887
containers = ('fpm', 'apache',)
7988
else:
8089
containers = (data['container_version'],)
8190

82-
ps_version_path = self.directory_path / ps_version
8391
result = {}
8492
for php_version in data['php_versions']:
8593
for container in containers:
@@ -95,8 +103,8 @@ def get_version_from_string(self, version):
95103
96104
@param version: The version you want
97105
@type version: str
98-
@return: A tuple containing ('PS_VERSION', 'BRANCH_VERSION', (PHP_VERSIONS), 'CONTAINER_TYPE', 'FLAVOR_VERSION')
99-
or ('PS_VERSION', 'BRANCH_VERSION', 'PHP_VERSION', 'CONTAINER_TYPE', 'FLAVOR_VERSION')
106+
@return: A tuple containing ('PS_VERSION', 'BRANCH_VERSION', (PHP_VERSIONS), 'CONTAINER_TYPE', 'DISTRIBUTION')
107+
or ('PS_VERSION', 'BRANCH_VERSION', 'PHP_VERSION', 'CONTAINER_TYPE', 'DISTRIBUTION')
100108
@rtype: tuple
101109
'''
102110
matches = self.parse_version_from_string(version)
@@ -105,10 +113,10 @@ def get_version_from_string(self, version):
105113

106114
ps_version = matches.group('version')
107115

108-
flavor_versions = None
109-
if matches.group('flavor'):
110-
flavor_versions = matches.group('flavor')
111-
ps_version = ps_version + '-' + flavor_versions
116+
distribution = None
117+
if matches.group('distribution'):
118+
distribution = matches.group('distribution')
119+
ps_version = ps_version + '-' + distribution
112120

113121
if matches.group('php'):
114122
php_versions = (matches.group('php'),)
@@ -147,7 +155,7 @@ def get_version_from_string(self, version):
147155
'branch_version': branch_version,
148156
'php_versions': php_versions,
149157
'container_version': container_version,
150-
'flavor_versions': flavor_versions
158+
'distribution': distribution
151159
}
152160

153161
def get_last_patch_from_version(self, version):
@@ -186,19 +194,23 @@ def split_prestashop_version(self, version):
186194
@return: Return None if no patch is found otherwise an int with the patch.
187195
@rtpe: None|tuple
188196
'''
189-
regex = r"^(?P<major>(1.)?[0-9]+)\.(?P<minor>[0-9]+)\.(?P<patch>[0-9x]+)(?P<prerelease>-(alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?"
197+
198+
regex = r"^(?P<major>(1.)?[0-9]+)\.(?P<minor>[0-9]+)\.(?P<patch>[0-9x]+)(?P<prerelease>-(alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?(?:-(?P<distribution>classic))?"
199+
190200
matches = re.search(regex, version)
191201

192202
if (matches and matches.group() and matches.group('major') and matches.group('major') and matches.group('major')):
193203
# Remove the initial matched -
194204
prerelease = matches.group('prerelease')[1:] if matches.group('prerelease') else None
205+
distribution = matches.group('distribution') if matches.group('distribution') else None
195206

196207
return {
197208
'version': matches.group('major') + '.' + matches.group('minor') + '.' + matches.group('patch'),
198209
'major': matches.group('major'),
199210
'minor': matches.group('minor'),
200211
'patch': matches.group('patch'),
201212
'prerelease': prerelease,
213+
'distribution': distribution
202214
}
203215
return None
204216

@@ -210,7 +222,7 @@ def parse_version_from_string(self, version):
210222
@return: Return None if no position in the string matches the pattern otherwise a Match object.
211223
@rtpe: None|Match
212224
'''
213-
regex = r"^(?P<version>(?:[0-9]+\.){0,3}(?:[0-9]+|nightly|x)(?:-(?:alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?)(?:-(?P<flavor>classic))?(?:-(?P<php>\d+\.\d+))?(?:-(?P<container>fpm|apache))?$"
225+
regex = r"^(?P<version>(?:[0-9]+\.){0,3}(?:[0-9]+|nightly|x)(?:-(?:alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?)(?:-(?P<distribution>classic))?(?:-(?P<php>\d+\.\d+))?(?:-(?P<container>fpm|apache))?$"
214226
return re.search(regex, version)
215227

216228
def get_aliases(self):

0 commit comments

Comments
 (0)