Esempio n. 1
0
def start_bitcoin_qt():
    '''
        Start bitcoin-qt.

        >>> init_database()
        >>> start_bitcoin_qt()
        >>> stop_bitcoin_qt()
    '''

    bin_dir, data_dir = preferences.get_bitcoin_dirs()

    command_args = []
    cmd = os.path.join(bin_dir, bitcoin_utils.bitcoin_qt())
    command_args.append(cmd)

    data_dir = bitcoin_utils.strip_testnet_from_data_dir(data_dir=data_dir)
    command_args.append(f'-datadir={data_dir}')

    extra_args = preferences.get_extra_args()
    if len(extra_args) > 0:
        for extra_arg in extra_args:
            command_args.append(extra_arg)

    command_args.append('-daemon')

    command.background(*command_args)
    log(f'running : {command_args}')

    # give bitcoind time to start
    secs = 0
    while (not bitcoin_utils.is_bitcoin_qt_running() and secs < 5):
        sleep(1)
        secs += 1
Esempio n. 2
0
def start_fake_restore():
    '''
        Start a program which has the restore program's name,
        but just keeps itself running for a few minutes
        so we can test for the app to be running.

        >>> start_fake_restore()
        >>> bin_dir = os.path.join(virtualenv_dir(), 'bin')
        >>> sleep(15)
        >>> args = [os.path.join(bin_dir, 'killmatch'), constants.RESTORE_PROGRAM]
        >>> result = command.run(*args)
    '''

    bin_dir = os.path.join(virtualenv_dir(), 'bin')
    config_dir = os.path.join(PROJECT_PATH, 'config')
    args = [os.path.join(bin_dir, constants.RESTORE_PROGRAM), config_dir, '/tmp']
    command.background(*args)
Esempio n. 3
0
def check_for_updates(current_time=None, force=False, reason=None):
    '''
        Check to see if updates are needed.

        >>> from blockchain_backup.bitcoin.tests import utils as test_utils
        >>> test_utils.init_database()
        >>> check_for_updates()
        True
    '''

    updates_checked = False

    try:
        if current_time is None:
            current_time = now()

        next_updates_time = state.get_last_update_time() + timedelta(hours=24)
        if force or next_updates_time <= current_time:
            log('starting to check for the latest updates')

            # set the update time now so we don't restart the check too often
            state.set_last_update_time(current_time)

            command_args = []
            command_args.append('python3')
            # get the path for check_for_updates.py, regardless of virtualenv, etc.
            check_program = os.path.realpath(
                os.path.abspath(
                    os.path.join(os.path.dirname(blockchain_backup_file),
                                 'config', 'check_for_updates.py')))
            command_args.append(check_program)
            if reason is not None:
                command_args.append(reason)
            background(*command_args)

            updates_checked = True
    except:  # 'bare except' because it catches more than "except Exception"
        log(format_exc())

    return updates_checked
Esempio n. 4
0
    def interrupt(self):
        '''
            Set to true when user clicks the Stop button.

            >>> from blockchain_backup.bitcoin.tests import utils as test_utils
            >>> test_utils.init_database()
            >>> update_task = UpdateTask()
            >>> update_task.interrupt()
            >>> update_task._interrupted
            True
        '''
        self._interrupted = True
        if self.manager:
            self.manager.update_progress(self.STOPPING_UPDATE)

            # try to stop bitcoind quickly
            command_args = self.manager.get_bitcoin_cli_cmd('stop')
            try:
                background(*command_args)
            # but if it doesn't work, that's ok;
            # more robust efforts will be made elsewhere
            except:  # 'bare except' because it catches more than "except Exception"
                self.log(format_exc())