]> www.vanbest.org Git - motioneye-debian/commitdiff
removed the automatic update functionality as it was buggy and
authorCalin Crisan <ccrisan@gmail.com>
Sun, 15 Mar 2015 13:05:11 +0000 (15:05 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 15 Mar 2015 13:05:11 +0000 (15:05 +0200)
unreliable

motioneye.py
settings_default.py
src/handlers.py
src/motionctl.py
src/update.py
static/js/main.js

index 089e7e096aaf64f61a6ac2b606ddf6c4d3343df8..fea033ebdd7ccd0af4868ebffaf048a95b0fd032 100755 (executable)
@@ -46,7 +46,6 @@ def _configure_settings():
     set_default_setting('LOG_PATH', os.path.join(settings.PROJECT_PATH, 'log'))
     set_default_setting('MEDIA_PATH', os.path.join(settings.PROJECT_PATH, 'media'))
     set_default_setting('MOTION_BINARY', None)
-    set_default_setting('REPO', None)
     set_default_setting('LOG_LEVEL', logging.INFO)
     set_default_setting('LISTEN', '0.0.0.0')
     set_default_setting('PORT', 8765)
index 50f708d7a46f798a892edc7413c7466393e8123b..21c42c95afc349056033a861de63b69366e16fc3 100644 (file)
@@ -26,9 +26,6 @@ MEDIA_PATH = os.path.abspath(os.path.join(PROJECT_PATH, 'media'))
 # path to motion binary (automatically detected if not set)
 MOTION_BINARY = None 
 
-# repository details for software updating
-REPO = ('ccrisan', 'motioneye')
-
 # set to logging.DEBUG for verbose output
 LOG_LEVEL = logging.INFO
 
index dc0bf95455ee58dfe26d0caeec6b372f4172899b..5fa23b1c4f5a3a27fd0d878df29124f68e418b41 100644 (file)
@@ -149,7 +149,7 @@ class MainHandler(BaseHandler):
         self.render('main.html',
                 frame=False,
                 version=motioneye.VERSION,
-                enable_update=bool(settings.REPO),
+                enable_update=False,
                 enable_reboot=settings.ENABLE_REBOOT,
                 main_sections=main_sections,
                 camera_sections=camera_sections,
index c910b93233b8d00a8e52699d8348a132aa7d325e..93eb44abd2f9065676d7a9cef844b8bcc79c59c8 100644 (file)
@@ -26,6 +26,7 @@ import time
 from tornado.httpclient import HTTPClient, AsyncHTTPClient, HTTPRequest
 
 import config
+import powerctl
 import settings
 import utils
 
@@ -166,7 +167,12 @@ def stop():
                 os.waitpid(pid, os.WNOHANG)
                 
             # the process still did not exit
-            raise Exception('could not terminate the motion process')
+            if settings.ENABLE_REBOOT:
+                logging.error('could not terminate the motion process')
+                powerctl.reboot()
+
+            else:
+                raise Exception('could not terminate the motion process')
         
         except OSError as e:
             if e.errno not in (errno.ESRCH, errno.ECHILD):
index e373906bf7c08743f7b7c47bdec7ad16b3d83a8b..43f411545f9d7b2fed78a327f9b1245b750e62a9 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 
-import datetime
-import json
 import logging
-import os.path
-import shutil
-import signal
-import subprocess
-import tempfile
-import time
-import urllib2
-
-from tornado.ioloop import IOLoop
-
-import settings
-
-
-_BITBUCKET_ROOT_URL = 'https://bitbucket.org'
-_BITBUCKET_DOWNLOAD_URL = '%(root)s/%(owner)s/%(repo)s/get/%(version)s.tar.gz'
-_BITBUCKET_LIST_TAGS_URL = '%(root)s/api/1.0/repositories/%(owner)s/%(repo)s/tags'
-
-_UPDATE_PATHS = ['src', 'static', 'templates', 'motioneye.py']
 
 
 # versions
@@ -47,28 +27,6 @@ def get_version():
 
 
 def get_all_versions():
-    url = _BITBUCKET_LIST_TAGS_URL % {
-            'root': _BITBUCKET_ROOT_URL,
-            'owner': settings.REPO[0],
-            'repo': settings.REPO[1]}
-    
-    url += '?_=' + str(int(time.time())) # prevents caching
-    
-    try:
-        logging.debug('fetching %(url)s...' % {'url': url})
-        
-        response = urllib2.urlopen(url, timeout=settings.REMOTE_REQUEST_TIMEOUT)
-        response = json.load(response)
-        versions = response.keys()
-        
-        logging.debug('available versions: %(versions)s' % {
-                'versions': ', '.join(versions)})
-        
-        return sorted(versions, cmp=compare_versions)
-
-    except Exception as e:
-        logging.error('could not get versions: %(msg)s' % {'msg': unicode(e)}, exc_info=True)
-        
     return []
 
 
@@ -99,142 +57,7 @@ def compare_versions(version1, version2):
         return 0
 
 
-# updating
-
-def download(version):
-    url = _BITBUCKET_DOWNLOAD_URL % {
-            'root': _BITBUCKET_ROOT_URL,
-            'owner': settings.REPO[0],
-            'repo': settings.REPO[1],
-            'version': version}
-    
-    url += '?_=' + str(int(time.time())) # prevents caching
-    
-    try:
-        logging.debug('downloading %(url)s...' % {'url': url})
-        
-        response = urllib2.urlopen(url, timeout=settings.REMOTE_REQUEST_TIMEOUT)
-        data = response.read()
-
-    except Exception as e:
-        logging.error('could not download update: %(msg)s' % {'msg': unicode(e)})
-        
-        raise
-    
-    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)
-        
-    except Exception as e:
-        logging.error('could not download update: %(msg)s' % {'msg': unicode(e)})
-        
-        raise
-    
-    return path
-
-
-def cleanup(path):
-    try:
-        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})
+    logging.error('updating is not implemented')
     
-    try:
-        # make sure the partition where motionEye resides is writable
-        path = os.path.abspath(settings.PROJECT_PATH)
-        if settings.ENABLE_REBOOT:
-            try:
-                df_lines = subprocess.check_output('df %s' % path, shell=True).split('\n')
-                last_line = [l for l in df_lines if l.strip()][-1]
-                mount_point = last_line.split()[-1]
-                
-                os.system('mount -o remount,rw %s' % mount_point)
-            
-            except Exception as e:
-                logging.error('failed to remount root partition rw: %s' % e, exc_info=True)
-        
-        if not os.access(path, os.W_OK):
-            raise Exception('path "%s" is not writable' % path)
-        
-        # download the archive
-        archive = download(version)
-        temp_path = os.path.dirname(archive)
-        
-        # extract the archive
-        logging.debug('extracting archive %(archive)s...' % {'archive': archive})
-        os.system('tar zxf %(archive)s -C %(path)s' % {
-                'archive': archive, 'path': temp_path})
-        
-        # kill all the subprocesses
-        try:
-            children_pids = [int(p) for p in subprocess.check_output('ps -o pid --no-headers --ppid %s' % os.getpid(), shell=True).split() if p]
-            for pid in children_pids:
-                try:
-                    os.kill(pid, signal.SIGKILL)
-                    logging.debug('killed process %d' % pid)
-                
-                except Exception as e:
-                    if getattr(e, 'errno', None) == 3: # no such process
-                        continue
-                    
-                    else:
-                        logging.error('failed to kill process %d: %s' % (pid, e))
-
-        except Exception as e:
-            logging.error('failed to kill children processes: %s' % e)
-        
-        # determine the root path of the extracted archive
-        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):
-                shutil.rmtree(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')
-        
-        if settings.ENABLE_REBOOT:
-            def call_reboot():
-                logging.info('rebooting')
-                os.system('reboot')
-                
-            IOLoop.instance().add_timeout(datetime.timedelta(seconds=2), call_reboot)
-        
-        else:
-            from tornado import autoreload
-            
-            # this will reload the interpreter
-            logging.info('reloading python interpreter...')
-            autoreload._reload()
-        
-        return True
-    
-    except Exception as e:
-        logging.error('could not perform update: %(msg)s' % {'msg': unicode(e)}, exc_info=True)
-        
-        return False
+    return False
index 16869a9f08ca7e28d26ceda1cee8b9e8b1d73ff8..6289b5f752620c221125c6f3c6e4d84e51ceae8b 100644 (file)
@@ -1920,7 +1920,7 @@ function doUpdate() {
                 showModalDialog('<div style="text-align: center;"><span>Updating. This may take a few minutes.</span><div class="modal-progress"></div></div>');
                 ajax('POST', baseUri + 'update/?version=' + data.update_version, null, function () {
                     var count = 0;
-                    function checkServerUpdate() {
+                    function checkServer() {
                         ajax('GET', baseUri + 'config/0/get/', null,
                             function () {
                                 runAlertDialog('motionEye was successfully updated!', function () {
@@ -1928,9 +1928,9 @@ function doUpdate() {
                                 });
                             },
                             function () {
-                                if (count < 25) {
+                                if (count < 60) {
                                     count += 1;
-                                    setTimeout(checkServerUpdate, 2000);
+                                    setTimeout(checkServer, 5000);
                                 }
                                 else {
                                     runAlertDialog('Update failed!', function () {
@@ -1941,7 +1941,7 @@ function doUpdate() {
                         );
                     }
                     
-                    setTimeout(checkServerUpdate, 10000);
+                    setTimeout(checkServer, 10000);
 
                 }, function (e) { /* error */
                     runAlertDialog('The update process has failed!', function () {