Add project version history information
This commit is contained in:
parent
4a4e05a72b
commit
6eaf4ae967
2 changed files with 34 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
|||
import gzip
|
||||
import os
|
||||
import simplejson
|
||||
|
||||
|
@ -58,8 +59,11 @@ class Sprite(ScratchObj):
|
|||
return [ScratchMediaObj(x) for x in self._d['sounds']]
|
||||
|
||||
|
||||
class _Project(ScratchObj):
|
||||
def __init__(self, project_id, load_versions=False):
|
||||
class Project(ScratchObj):
|
||||
def __init__(self, project_id):
|
||||
self.project_id = project_id
|
||||
self._versions_cache = []
|
||||
|
||||
filepath = \
|
||||
os.path.join(calculate_project_dirpath(PROJECT_DIR_PREFIX,
|
||||
project_id), 'LATEST')
|
||||
|
@ -68,6 +72,28 @@ class _Project(ScratchObj):
|
|||
|
||||
ScratchObj.__init__(self, d)
|
||||
|
||||
@property
|
||||
def versions(self):
|
||||
if len(self._versions_cache):
|
||||
return self._versions_cache
|
||||
|
||||
dirname = calculate_project_dirpath(VERSION_DIR_PREFIX,
|
||||
self.project_id)
|
||||
|
||||
files = os.listdir(dirname)
|
||||
files.sort()
|
||||
|
||||
for filename in files:
|
||||
filepath = os.path.join(dirname, filename)
|
||||
with gzip.open(filepath, 'rb') as fp:
|
||||
d = simplejson.loads(fp.read())
|
||||
|
||||
self._versions_cache.append({'timestamp' : int(filename.replace('.gz', '')),
|
||||
'revision' : ProjectRevision(d)})
|
||||
|
||||
return self._versions_cache
|
||||
|
||||
|
||||
@property
|
||||
def info(self):
|
||||
return namedtuple('ProjectInfo',
|
||||
|
@ -86,3 +112,8 @@ class _Project(ScratchObj):
|
|||
@property
|
||||
def sprites(self):
|
||||
return [Sprite(x) for x in self._d['children']]
|
||||
|
||||
|
||||
class ProjectRevision(Project):
|
||||
def __init__(self, project_dict):
|
||||
ScratchObj.__init__(self, project_dict)
|
||||
|
|
Reference in a new issue