Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
|
M-A Ruel
2016/04/25 19:09:45
THis file is not executable.
nodir
2016/04/25 20:27:15
Done.
| |
| 2 # Copyright 2016 The LUCI Authors. All rights reserved. | |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """CIPD-specific code is concentrated here.""" | |
| 7 | |
| 8 import re | |
| 9 | |
| 10 # Regular expressions below are copied from | |
| 11 # https://chromium.googlesource.com/infra/infra/+/468bb43/appengine/chrome_infra _packages/cipd/impl.py | |
| 12 # https://chromium.googlesource.com/infra/infra/+/468bb43/appengine/chrome_infra _packages/cas/impl.py | |
| 13 | |
| 14 PACKAGE_NAME_RE = re.compile(r'^([a-z0-9_\-]+/)*[a-z0-9_\-]+$') | |
| 15 INSTANCE_ID_RE = re.compile(r'^[0-9a-f]{40}$') | |
| 16 TAG_KEY_RE = re.compile(r'^[a-z0-9_\-]{1,400}$') | |
| 17 REF_RE = re.compile(r'^[a-z0-9_\-]{1,100}$') | |
| 18 | |
| 19 | |
| 20 def is_valid_package_name(package_name): | |
| 21 """Returns True if |package_name| is a valid CIPD package name.""" | |
| 22 return bool(PACKAGE_NAME_RE.match(package_name)) | |
| 23 | |
| 24 | |
| 25 def is_valid_version(version): | |
| 26 """Returns True if |version| is a valid CIPD package version.""" | |
| 27 return bool( | |
| 28 INSTANCE_ID_RE.match(version) or | |
| 29 TAG_KEY_RE.match(version) or | |
| 30 REF_RE.match(version) | |
| 31 ) | |
| 32 | |
| 33 | |
| 34 def is_pinned_version(version): | |
| 35 """Returns True if |version| is pinned""" | |
| 36 return bool(INSTANCE_ID_RE.match(version) or TAG_KEY_RE.match(version)) | |
| OLD | NEW |