OLD | NEW |
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import copy | 5 import copy |
6 import json | 6 import json |
7 import tarfile | 7 import tarfile |
8 | 8 |
9 from google.appengine.api import memcache | 9 from google.appengine.api import memcache |
10 from google.appengine.ext import db | 10 from google.appengine.ext import db |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 version = VersionProperty(required=True) | 28 version = VersionProperty(required=True) |
29 """The version of the package.""" | 29 """The version of the package.""" |
30 | 30 |
31 pubspec = PubspecProperty(required=True, indexed=False) | 31 pubspec = PubspecProperty(required=True, indexed=False) |
32 """The package version's pubspec file.""" | 32 """The package version's pubspec file.""" |
33 | 33 |
34 readme = ReadmeProperty() | 34 readme = ReadmeProperty() |
35 """The README file.""" | 35 """The README file.""" |
36 | 36 |
| 37 readmeFilename = db.StringProperty(indexed=False) |
| 38 """The README filename.""" |
| 39 |
| 40 readmeContent = db.TextProperty() |
| 41 """The README file as a string.""" |
| 42 |
37 changelog = ReadmeProperty() | 43 changelog = ReadmeProperty() |
38 """The CHANGELOG file.""" | 44 """The CHANGELOG file.""" |
39 | 45 |
| 46 changelogFilename = db.StringProperty(indexed=False) |
| 47 """The CHANGELOG filename.""" |
| 48 |
| 49 changelogContent = db.TextProperty() |
| 50 """The CHANGELOG file as a string.""" |
| 51 |
40 libraries = db.ListProperty(str) | 52 libraries = db.ListProperty(str) |
41 """All libraries that can be imported from this package version.""" | 53 """All libraries that can be imported from this package version.""" |
42 | 54 |
43 package = db.ReferenceProperty(Package, | 55 package = db.ReferenceProperty(Package, |
44 required=True, | 56 required=True, |
45 collection_name = "version_set") | 57 collection_name = "version_set") |
46 """The Package model for this package version.""" | 58 """The Package model for this package version.""" |
47 | 59 |
48 # The following properties are not parsed from the package archive. They | 60 # The following properties are not parsed from the package archive. They |
49 # need to be manually copied over to new PackageVersions in | 61 # need to be manually copied over to new PackageVersions in |
50 # handlers.PackageVersions._reload_version. | 62 # handlers.PackageVersions._reload_version. |
51 | 63 |
52 created = db.DateTimeProperty(auto_now_add=True) | 64 created = db.DateTimeProperty(auto_now_add=True) |
53 """When this package version was created.""" | 65 """When this package version was created.""" |
54 | 66 |
55 downloads = db.IntegerProperty(required=True, default=0) | 67 downloads = db.IntegerProperty(required=True, default=0) |
56 """The number of times this package version has been downloaded.""" | 68 """The number of times this package version has been downloaded.""" |
57 | 69 |
58 sort_order = db.IntegerProperty(default=-1) | 70 sort_order = db.IntegerProperty(default=-1) |
59 """The sort order for this version. | 71 """The sort order for this version. |
60 | 72 |
61 Lower numbers indicate earlier versions.""" | 73 Lower numbers indicate earlier versions.""" |
62 | 74 |
63 uploader = db.UserProperty(required=True) | 75 uploader = db.UserProperty(required=True) |
64 """The user who uploaded this package version.""" | 76 """The user who uploaded this package version.""" |
65 | 77 |
| 78 uploaderEmail = db.StringProperty() |
| 79 """The user email who uploaded this package version.""" |
| 80 |
| 81 def temp_synchronize_uploader_to_uploaderemail_and_pickles(self): |
| 82 """ Will synchronize properties. |
| 83 |
| 84 uploader/readme/changelog -> uploaderEmail/readmeString/changelogString |
| 85 """ |
| 86 if self.uploader is None: |
| 87 self.uploaderEmail = None |
| 88 else: |
| 89 self.uploaderEmail = self.uploader.email() |
| 90 |
| 91 if self.readme: |
| 92 self.readmeFilename = self.readme.filename |
| 93 self.readmeContent = db.Text(self.readme.text, encoding="utf-8") |
| 94 |
| 95 if self.changelog: |
| 96 self.changelogFilename = self.changelog.filename |
| 97 self.changelogContent = db.Text(self.changelog.text, encoding="utf-8") |
| 98 |
66 @classmethod | 99 @classmethod |
67 def new(cls, **kwargs): | 100 def new(cls, **kwargs): |
68 """Construct a new package version. | 101 """Construct a new package version. |
69 | 102 |
70 Unlike __init__, this infers some properties from others. In particular: | 103 Unlike __init__, this infers some properties from others. In particular: |
71 | 104 |
72 - The version is inferred from the pubspec. | 105 - The version is inferred from the pubspec. |
73 - The key name is set to the version. | 106 - The key name is set to the version. |
74 - The parent entity is set to the package. | 107 - The parent entity is set to the package. |
75 """ | 108 """ |
76 | 109 |
77 if 'pubspec' in kwargs and 'version' not in kwargs: | 110 if 'pubspec' in kwargs and 'version' not in kwargs: |
78 kwargs['version'] = kwargs['pubspec'].required('version') | 111 kwargs['version'] = kwargs['pubspec'].required('version') |
79 | 112 |
80 if 'version' in kwargs and \ | 113 if 'version' in kwargs and \ |
81 not isinstance(kwargs['version'], SemanticVersion): | 114 not isinstance(kwargs['version'], SemanticVersion): |
82 kwargs['version'] = SemanticVersion(kwargs['version']) | 115 kwargs['version'] = SemanticVersion(kwargs['version']) |
83 | 116 |
84 if not 'key_name' in kwargs and not 'key' in kwargs: | 117 if not 'key_name' in kwargs and not 'key' in kwargs: |
85 kwargs['key_name'] = str(kwargs['version'].canonical) | 118 kwargs['key_name'] = str(kwargs['version'].canonical) |
86 | 119 |
87 if not 'parent' in kwargs: | 120 if not 'parent' in kwargs: |
88 kwargs['parent'] = kwargs['package'] | 121 kwargs['parent'] = kwargs['package'] |
89 | 122 |
90 version = cls(**kwargs) | 123 version = cls(**kwargs) |
91 version._validate_fields_match_pubspec() | 124 version._validate_fields_match_pubspec() |
92 return version | 125 return version |
93 | 126 |
| 127 # TODO(kustermann): When we have string emails, this needs to be changed |
| 128 # to read uploaderEmails instead of uploaders. |
94 @classmethod | 129 @classmethod |
95 def from_archive(cls, file, uploader): | 130 def from_archive(cls, file, uploader): |
96 """Load a package version from a .tar.gz archive. | 131 """Load a package version from a .tar.gz archive. |
97 | 132 |
98 If the package specified in the archive already exists, it will be | 133 If the package specified in the archive already exists, it will be |
99 loaded and assigned as the package version's package. If it doesn't, a | 134 loaded and assigned as the package version's package. If it doesn't, a |
100 new package will be created. | 135 new package will be created. |
101 | 136 |
102 Arguments: | 137 Arguments: |
103 file: An open file object containing a .tar.gz archive. | 138 file: An open file object containing a .tar.gz archive. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 'Version "%s" in pubspec doesn\'t match version "%s"' % | 282 'Version "%s" in pubspec doesn\'t match version "%s"' % |
248 (version_in_pubspec._key(), self.version._key())) | 283 (version_in_pubspec._key(), self.version._key())) |
249 @property | 284 @property |
250 def url(self): | 285 def url(self): |
251 """The API URL for this package version.""" | 286 """The API URL for this package version.""" |
252 return models.url(controller='api.versions', | 287 return models.url(controller='api.versions', |
253 action='show', | 288 action='show', |
254 package_id=self.package.name, | 289 package_id=self.package.name, |
255 id=str(self.version)) | 290 id=str(self.version)) |
256 | 291 |
| 292 # TODO(kustermann): When we have string emails, this needs to be changed |
| 293 # to read uploaderEmails instead of uploaders. |
257 def as_dict(self, full=False): | 294 def as_dict(self, full=False): |
258 """Returns the dictionary representation of this package version. | 295 """Returns the dictionary representation of this package version. |
259 | 296 |
260 This is used to represent the package in API responses. Normally this | 297 This is used to represent the package in API responses. Normally this |
261 just includes URLs and the pubspec, but if full is True, it will include | 298 just includes URLs and the pubspec, but if full is True, it will include |
262 all available information about the package version. | 299 all available information about the package version. |
263 """ | 300 """ |
264 | 301 |
265 value = { | 302 value = { |
266 'version': str(self.version), | 303 'version': str(self.version), |
(...skipping 12 matching lines...) Expand all Loading... |
279 | 316 |
280 if full: | 317 if full: |
281 value.update({ | 318 value.update({ |
282 'created': self.created.isoformat(), | 319 'created': self.created.isoformat(), |
283 'downloads': self.downloads, | 320 'downloads': self.downloads, |
284 'libraries': self.libraries, | 321 'libraries': self.libraries, |
285 'uploader': self.uploader.email() | 322 'uploader': self.uploader.email() |
286 }) | 323 }) |
287 | 324 |
288 return value | 325 return value |
OLD | NEW |