|
a/scripts/project-import.py |
|
b/scripts/project-import.py |
|
... |
|
... |
50 |
class ProjectNameType():
|
50 |
class ProjectNameType():
|
51 |
def deserialize(self, node, cstruct):
|
51 |
def deserialize(self, node, cstruct):
|
52 |
if cstruct is col.null:
|
52 |
if cstruct is col.null:
|
53 |
return col.null
|
53 |
return col.null
|
54 |
name = cstruct
|
54 |
name = cstruct
|
55 |
shortname = re.sub("[^A-Za-z0-9]", "", name).lower()
|
55 |
shortname = re.sub("[^A-Za-z0-9 ]", "", name).lower()
|
56 |
length = len(shortname)
|
56 |
shortname = re.sub(" ", "-", shortname)
|
57 |
if length < 3 or length > 15:
|
|
|
58 |
raise col.Invalid(node,
|
|
|
59 |
'Project shortname "%s" must be between 3 and 15 '
|
|
|
60 |
'characters.' % shortname)
|
|
|
61 |
return ProjectName(name, shortname)
|
57 |
return ProjectName(name, shortname)
|
62 |
|
58 |
|
63 |
class ProjectShortnameType():
|
59 |
class ProjectShortnameType():
|
64 |
def deserialize(self, node, cstruct):
|
60 |
def deserialize(self, node, cstruct):
|
65 |
if cstruct is col.null:
|
61 |
if cstruct is col.null:
|
|
... |
|
... |
108 |
labels = Labels(missing=[])
|
104 |
labels = Labels(missing=[])
|
109 |
external_homepage = col.SchemaNode(col.Str(), missing='')
|
105 |
external_homepage = col.SchemaNode(col.Str(), missing='')
|
110 |
trove_audiences = TroveAudiences(validator=col.Length(max=6), missing=[])
|
106 |
trove_audiences = TroveAudiences(validator=col.Length(max=6), missing=[])
|
111 |
trove_licenses = TroveLicenses(validator=col.Length(max=6), missing=[])
|
107 |
trove_licenses = TroveLicenses(validator=col.Length(max=6), missing=[])
|
112 |
|
108 |
|
|
|
109 |
def valid_shortname(project):
|
|
|
110 |
if project.shortname:
|
|
|
111 |
# already validated in ProjectShortnameType validator
|
|
|
112 |
return True
|
|
|
113 |
elif 3 <= len(project.name.shortname) <= 15:
|
|
|
114 |
return True
|
|
|
115 |
else:
|
|
|
116 |
return 'Project shortname "%s" must be between 3 and 15 characters' \
|
|
|
117 |
% project.name.shortname
|
|
|
118 |
|
113 |
class Projects(col.SequenceSchema):
|
119 |
class Projects(col.SequenceSchema):
|
114 |
project = Project()
|
120 |
project = Project(validator=col.Function(valid_shortname))
|
115 |
|
121 |
|
116 |
class Object(object):
|
122 |
class Object(object):
|
117 |
def __init__(self, d):
|
123 |
def __init__(self, d):
|
118 |
self.__dict__.update(d)
|
124 |
self.__dict__.update(d)
|
119 |
|
125 |
|