Esempio n. 1
0
    def validate_confirm(self):
        if self._done:
            return True

        self._set_processing(True)
        threadit(self._register_link)
        return False
Esempio n. 2
0
    def run(self):
        self._ppid = os.getppid()
        threadit(self._check_parent_running)

        from stoqlib.net.webserver import run_server
        _event.set()
        run_server(self.port)
Esempio n. 3
0
 def __init__(self, window, store=None):
     # Create this here because CalendarView will update it.
     # It will only be shown on create_ui though
     self.date_label = Gtk.Label(label='')
     self._calendar = CalendarView(self)
     ShellApp.__init__(self, window, store=store)
     threadit(self._setup_daemon)
Esempio n. 4
0
    def validate_confirm(self):
        if self._done:
            return True

        self._set_processing(True)
        threadit(self._register_link)
        return False
Esempio n. 5
0
 def __init__(self, window, store=None):
     # Create this here because CalendarView will update it.
     # It will only be shown on create_ui though
     self.date_label = gtk.Label('')
     self._calendar = CalendarView(self)
     ShellApp.__init__(self, window, store=store)
     threadit(self._setup_daemon)
Esempio n. 6
0
def backup(backup_dir, full=False, retry=1):
    # Tell Stoq Link Admin that you're starting a backup
    user_hash = api.sysparam.get_string('USER_HASH')
    start_url = urlparse.urljoin(WebService.API_SERVER, 'api/backup/start')
    response = requests.get(start_url, params={'hash': user_hash})

    # If the server rejects the backup, don't even attempt to proceed. Log
    # which error caused the backup to fail
    if response.status_code != 200:
        raise Exception('ERROR: ' + response.content)

    cmd = [_duplicati_exe, 'backup', _webservice_url, backup_dir,
           '--log-id=' + response.content] + _get_extra_args()
    p = Process(cmd)
    threadit(_watch_fd, p.stdout)
    threadit(_watch_fd, p.stderr)
    p.wait()

    if p.returncode == 100 and retry > 0:
        # If the password has changed, duplicati will refuse to do the
        # backup, even tough we support that on our backend. Force remove
        # the cache so it will work
        duplicati_config = os.path.join(os.getenv('APPDATA'), 'Duplicati')
        shutil.rmtree(duplicati_config, ignore_errors=True)
        return backup(backup_dir, full=full, retry=retry - 1)

    if p.returncode != 0:
        raise Exception("Failed to backup the database: {}".format(p.returncode))

    # Tell Stoq Link Admin that the backup has finished
    end_url = urlparse.urljoin(WebService.API_SERVER, 'api/backup/end')
    requests.get(end_url,
                 params={'log_id': response.content, 'hash': user_hash})
def _run(cmd, *args):
    script = library.get_resource_filename('stoqserver', 'scripts',
                                           'duplicitybackup.py')
    p = Process(['python2', script, cmd] + list(args), stdout=PIPE, stderr=PIPE)
    threadit(_watch_fd, p.stdout)
    threadit(_watch_fd, p.stderr)
    p.wait()
    return p.returncode == 0
Esempio n. 8
0
def _run(cmd, *args):
    script = library.get_resource_filename('stoqserver', 'scripts',
                                           'duplicitybackup.py')
    p = Process(['python2', script, cmd] + list(args),
                stdout=PIPE,
                stderr=PIPE)
    threadit(_watch_fd, p.stdout)
    threadit(_watch_fd, p.stderr)
    p.wait()
    return p.returncode == 0
Esempio n. 9
0
def restore(restore_dir, user_hash, time=None):
    cmd = [_duplicati_exe, 'restore', _webservice_url, '*',
           '--restore-path="{}"'.format(restore_dir),
           '--log-id=-1'] + _get_extra_args(user_hash=user_hash)
    p = Process(cmd)
    threadit(_watch_fd, p.stdout)
    threadit(_watch_fd, p.stderr)
    p.wait()

    if p.returncode != 0:
        raise Exception("Failed to restore the database: {}".format(p.returncode))
Esempio n. 10
0
    def set_value_generic(self, param_name, value):
        """Update the internal cache for a parameter

        :param param_name: the parameter name
        :param value: value
        :type value: unicode
        """
        # FIXME: Find a better way of doing this after we integrate stoq.link
        # better with Stoq.
        if param_name == 'ONLINE_SERVICES':
            from stoqlib.net.server import ServerProxy
            p = ServerProxy(timeout=5)
            threadit(lambda: p.check_running() and p.call('restart'))

        self._values[param_name] = value
Esempio n. 11
0
    def set_value_generic(self, param_name, value):
        """Update the internal cache for a parameter

        :param param_name: the parameter name
        :param value: value
        :type value: unicode
        """
        # FIXME: Find a better way of doing this after we integrate stoq.link
        # better with Stoq.
        if param_name == 'ONLINE_SERVICES':
            from stoqlib.net.server import ServerProxy
            p = ServerProxy(timeout=5)
            threadit(lambda: p.check_running() and p.call('restart'))

        self._values[param_name] = value
Esempio n. 12
0
 def handle_action(self, action):
     """Ask the given resource to handle the given action"""
     self.running_action = action
     if action.threaded:
         return threadit(self._handle_action, action)
     else:
         return self._handle_action(action)
Esempio n. 13
0
File: status.py Progetto: stoq/stoq
 def handle_action(self, action):
     """Ask the given resource to handle the given action"""
     if action.threaded:
         self.running_action = action
         return threadit(self._handle_action, action)
     else:
         return self._handle_action(action)
Esempio n. 14
0
    def execute_command(self, args):
        self.feed('Executing: %s\r\n' % (' '.join(args)))
        kwargs = {}
        # On Windows you have to passin stdout/stdin = PIPE or
        # it will result in an invalid handle, see
        # * CR2012071248
        # * http://bugs.python.org/issue3905
        if self.listen_stdout or platform.system() == 'Windows':
            kwargs['stdout'] = PIPE
        if self.listen_stderr or platform.system() == 'Windows':
            kwargs['stderr'] = PIPE
        self.proc = Process(args, **kwargs)
        if self.listen_stdout:
            threadit(self._watch_fd, self.proc.stdout)
        if self.listen_stderr:
            threadit(self._watch_fd, self.proc.stderr)

        # We could probably listen to SIGCHLD here instead
        GLib.timeout_add(CHILD_TIMEOUT, self._check_child_finished)
Esempio n. 15
0
    def execute_command(self, args):
        self.feed('Executing: %s\r\n' % (' '.join(args)))
        kwargs = {}
        # On Windows you have to passin stdout/stdin = PIPE or
        # it will result in an invalid handle, see
        # * CR2012071248
        # * http://bugs.python.org/issue3905
        if self.listen_stdout or platform.system() == 'Windows':
            kwargs['stdout'] = PIPE
        if self.listen_stderr or platform.system() == 'Windows':
            kwargs['stderr'] = PIPE
        self.proc = Process(args, **kwargs)
        if self.listen_stdout:
            threadit(self._watch_fd, self.proc.stdout)
        if self.listen_stderr:
            threadit(self._watch_fd, self.proc.stderr)

        # We could probably listen to SIGCHLD here instead
        GLib.timeout_add(CHILD_TIMEOUT, self._check_child_finished)
Esempio n. 16
0
 def refresh_and_notify(self, force=False):
     """Refresh the status and notify for changes"""
     # Do not run checks if we are running tests. It breaks the whole suite
     if os.environ.get('STOQ_TESTSUIT_RUNNING', '0') == '1':
         return False
     return threadit(self._refresh_and_notify, force=force)
Esempio n. 17
0
File: status.py Progetto: stoq/stoq
 def refresh_and_notify(self, force=False):
     """Refresh the status and notify for changes"""
     # Do not run checks if we are running tests. It breaks the whole suite
     if os.environ.get("STOQ_TESTSUIT_RUNNING", "0") == "1":
         return False
     return threadit(self._refresh_and_notify, force=force)