# Path: htpc/root.py
# def do_restart():
#     arguments = sys.argv[:]
#     arguments.insert(0, sys.executable)
#     if sys.platform == 'win32':
#         arguments = ['"%s"' % arg for arg in arguments]
#     os.chdir(os.getcwd())
#     cherrypy.engine.exit()
#     os.execv(sys.executable, arguments)


import os
import urllib2
import subprocess
import re
import cherrypy
import htpc
import logging
import tarfile
import shutil
from threading import Thread
from json import loads
from htpc.root import do_restart
        self.git = htpc.settings.get('git_path', 'git')
        self.logger = logging.getLogger('htpc.updater')

    def current(self):
        """ Get hash of current Git commit """
        self.logger.debug('Getting current version.')
        output = self.git_exec('rev-parse HEAD')
        self.logger.debug('Current version: ' + output)

        if (output == '') :
            self.logger.error('Got no response for current Git version.')
            return False

        if re.match('^[a-z0-9]+$', output):
            return output


    def update(self):
        """ Do update through git """
        self.logger.info("Attempting update through Git.")
        self.UPDATING = 1

        output = self.git_exec('pull origin %s' % gitBranch)
        if not output:
            self.logger.error("Unable to update through git. Make sure that Git is located in your path and can be accessed by this application.")
        elif 'Aborting.' in output:
            self.logger.error("Update aborted.")
        else:
            # Restart HTPC Manager to make sure all new code is loaded
            self.logger.warning('Restarting HTPC Manager after update.')

# Path: htpc/root.py
# def do_restart():
#     arguments = sys.argv[:]
#     arguments.insert(0, sys.executable)
#     if sys.platform == 'win32':
#         arguments = ['"%s"' % arg for arg in arguments]
#     os.chdir(os.getcwd())
#     cherrypy.engine.exit()
#     os.execv(sys.executable, arguments)


# Path: htpc/updater.py
import os
import urllib2
import subprocess
import re
import cherrypy
import htpc
import logging
import tarfile
import shutil
from threading import Thread
from json import loads
from htpc.root import do_restart

        self.git = htpc.settings.get('git_path', 'git')
        self.logger = logging.getLogger('htpc.updater')

    def current(self):
        """ Get hash of current Git commit """
        self.logger.debug('Getting current version.')
        output = self.git_exec('rev-parse HEAD')
        self.logger.debug('Current version: ' + output)

        if (output == '') :
            self.logger.error('Got no response for current Git version.')
            return False

        if re.match('^[a-z0-9]+$', output):
            return output


    def update(self):
        """ Do update through git """
        self.logger.info("Attempting update through Git.")
        self.UPDATING = 1

        output = self.git_exec('pull origin %s' % gitBranch)
        if not output:
            self.logger.error("Unable to update through git. Make sure that Git is located in your path and can be accessed by this application.")
        elif 'Aborting.' in output:
            self.logger.error("Update aborted.")
        else:
            # Restart HTPC Manager to make sure all new code is loaded
            self.logger.warning('Restarting HTPC Manager after update.')

            do_restart()