Beispiel #1
0
    def connection_status():
        """
        Returns internet connection status.
        """
        status = "offline"
        if is_online():
            status = "online"

        return make_response(jsonify({"status": status}))
Beispiel #2
0
 def connection_status(st):
     #stop_services(st, None)
     #print "checking connection status from launcher"
     if is_online():
         if st.server_host == "127.0.0.1":
             try:
                 restart_service(st, None)
             except Exception, e:
                 #print "%r" % e
                 pass
Beispiel #3
0
    def load_schedules():
        """
        Load schedules from db to kronos scheduler.
        Starts the backup routine for an app module if we missed a schedule.
        """
        logger.debug("in load_schedules")
        modules = app.modules

        for app_name in modules.keys():
            if app_name in ["base", "account"]:
                continue
            logger.debug("loading schedule for %s", app_name)

            settings = get_settings(app_name)
            if not settings:
                continue

            logger.debug("%r", settings["schedule"])

            def callback(app_name):
                try:
                    url = "http://%s:%s/%s/backup" % (HOST, PORT, app_name)
                    progress = get_backup_progress(app_name)

                    if not progress:
                        urllib2.urlopen(url).read()
                except Exception, e:
                    logger.debug("%r", e)

            taskname = "%s" % (app_name)

            add_schedule(taskname, settings["schedule"], callback)
            logger.debug("schedule added")
            today = datetime.datetime.today()

            if not is_online():
                logger.debug("we are offline. skipping backup on boot")
                return make_response("schedule loaded")

            archive = get_recent_archive(app_name)
            if archive:
                logger.debug("there is an archive")
                try:
                    if not backup_is_on_schedule(today, archive.archived_at, settings["schedule"]):
                        logger.debug("we missed a backup schedule. starting backup")
                        KRON.add_single_task(callback, "backup_%s" % app_name, 1, "threaded", [app_name], None)
                    else:
                        logger.debug("we are on schedule")
                except Exception, e:
                    logger.debug("error: %r" % e)
Beispiel #4
0
def backup():
    if not is_online():
        logger.debug("skipping google contacts backup. we are offline")
        return jsonify({'error': 'offline'})

    logger.debug("running backup for google_contacts_app")

    preference = get_settings("google_contacts_app")

    def make_response(payload):
        response = app.make_response(jsonify(payload))
        response.headers['cache-control'] = 'no-cache'
        return response

    if not preference:
        logger.debug('no preference found.')
        return make_response({'error': 'no preference'})

    backup_time = run_backup(preference)
    logger.debug('done google_contacts backup')

    return jsonify({'backup_time': backup_time.strftime("%Y-%m-%d %H%M")})
Beispiel #5
0
def schedule_runner(job, app_name):
    if is_online():
        job(app_name)
Beispiel #6
0
    Look for an open port then start the webservice on that port.
    """
    if hasattr(self, 'server_pid') and self.server_pid:
        try:
            try:
                urllib2.urlopen("http://%s:%s/stop" % ("127.0.0.1", self.server_port), timeout=1)
            except Exception, e:
                pass
            self.server_process.wait()
            self.server_pid = None
        except IOError, e:
            print "ignoring IOError %r" % e

    port = str(pscan())
    from settings import HOST as DOMAIN
    if not is_online():
        DOMAIN = "127.0.0.1"

    if not hasattr(self, 'server_pid') or self.server_pid is None:
        if re.search(r"python(.exe)?$", sys.executable):
            self.server_process = subprocess.Popen([sys.executable, 'server.py', port])
        else:
            if re.search(r".exe$", sys.executable):
                exe = 'server.exe'
            else:
                exe = 'server'
            #path = get_path(sys.executable)
            path = os.path.dirname(sys.executable)
            os.chdir(path)
            path = os.path.join(path, exe)
            self.server_process = subprocess.Popen([path, port])