import motionctl
import remote
import template
+import update
import v4l2ctl
# TODO implement me
self.finish_json()
+
+
+class UpdateHandler(BaseHandler):
+ @BaseHandler.auth(admin=True)
+ def get(self):
+ logging.debug('listing versions')
+
+ stable = self.get_argument('stable', default='false') == 'true'
+
+ versions = update.get_all_versions(stable=stable)
+
+ self.finish_json(versions)
+
+ @BaseHandler.auth(admin=True)
+ def post(self):
+ version = self.get_argument('version')
+
+ logging.debug('performing update to version %(version)s' % {'version': version})
+
+ result = update.perform_update(version)
+
+ return self.finish_json(result)
(r'^/snapshot/(?P<camera_id>\d+)/(?P<op>download)/(?P<filename>.+)/?$', handlers.SnapshotHandler),
(r'^/movie/(?P<camera_id>\d+)/(?P<op>list)/?$', handlers.MovieHandler),
(r'^/movie/(?P<camera_id>\d+)/(?P<op>download)/(?P<filename>.+)/?$', handlers.MovieHandler),
+ (r'^/update/?$', handlers.UpdateHandler),
],
debug=False, # also disables autoreloading
log_function=log_request,
if stable:
versions = [v for v in versions if v.count('.') == 1]
+ versions.sort()
+
+ return ['master'] # TODO
return versions
except Exception as e:
'version': version}
try:
+ logging.debug('downloading %(url)s...' % {'url': url})
+
response = urllib2.urlopen(url, timeout=settings.REMOTE_REQUEST_TIMEOUT)
data = response.read()
path = tempfile.mkdtemp()
path = os.path.join(path, version + '.tar.gz')
+ logging.debug('writing archive to %(path)s...' % {'path': path})
+
try:
with open(path, 'w') as f:
f.write(data)
def cleanup(path):
try:
- os.remove(path)
+ shutil.rmtree(path)
except Exception as e:
logging.error('could cleanup update directory: %(msg)s' % {'msg': unicode(e)})
def perform_update(version):
+ logging.info('updating to version %(version)s...' % {'version': version})
+
try:
# download the archive
archive = download(version)
temp_path = os.path.dirname(archive)
# extract the archive
- if os.system('tar zxf %(archive)s -C %(path)s' % {
- 'archive': archive, 'path': temp_path}):
+ logging.debug('extracting archive %(archive)s...' % {'archive': archive})
+ os.system('tar zxf %(archive)s -C %(path)s' % {
+ 'archive': archive, 'path': temp_path})
- raise Exception('archive extraction failed')
-
# determine the root path of the extracted archive
- root_path = [f for f in os.listdir(temp_path) if os.path.isdir(f)][0]
+ root_name = [f for f in os.listdir(temp_path) if os.path.isdir(os.path.join(temp_path, f))][0]
+ root_path = os.path.join(temp_path, root_name)
for p in _UPDATE_PATHS:
src = os.path.join(root_path, p)
dst = os.path.join(settings.PROJECT_PATH, p)
+ logging.debug('copying %(src)s over %(dst)s...' % {'src': src, 'dst': dst})
+
if os.path.isdir(dst):
- os.remove(dst)
+ shutil.rmtree(dst)
- shutil.copytree(src, dst)
+ if os.path.isdir(src):
+ shutil.copytree(src, dst)
+
+ else:
+ shutil.copy(src, dst)
# remove the temporary update directory
+ logging.debug('removing %(path)s...' % {'path': temp_path})
cleanup(temp_path)
+ logging.info('updating done')
+
return True
except Exception as e: