コード例 #1
0
    def get_page(self, request):

        try:
            prefs = preferences.get_preferences()
        except OperationalError as oe:
            report_operational_error(oe)

        try:
            if prefs.data_dir is None:
                prefs.data_dir = os.path.join(getdir(), '.bitcoin')

            if prefs.backup_dir is None and prefs.data_dir is not None:
                prefs.backup_dir = os.path.join(prefs.data_dir,
                                                constants.DEFAULT_BACKUPS_DIR)

            if prefs.bin_dir is None:
                prefs.bin_dir = bitcoin_utils.get_path_of_core_apps()

            form = PreferencesForm(instance=prefs)
        except:  # 'bare except' because it catches more than "except Exception"
            log(format_exc())
            form = PreferencesForm()

        return render(request, self.form_url, {
            'form': form,
            'context': bitcoin_utils.get_blockchain_context()
        })
コード例 #2
0
    def test_access_wallet_with_bad_data_dir(self):
        '''
            Test accessing the wallet with a bad data directory.
        '''
        prefs = get_preferences()
        prefs.data_dir = '/bad/bitcoin/data/'
        prefs.bin_dir = '/tmp/bitcoin/bin/'
        prefs.backup_dir = '/tmp/bitcoin/data/backups/'
        save_preferences(prefs)

        request = self.factory.get('/bitcoin/access_wallet/')
        response = AccessWallet.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(
            b"<title>\nAccessing Bitcoin Core Wallet | Blockchain Backup\n</title>"
            in response.content)
        self.assertFalse(
            b'The Bitcoin binary directory is not valid.' in response.content)
        self.assertTrue(
            b'The Bitcoin data directory is not valid.' in response.content)
        self.assertFalse(
            b'The Bitcoin backup directory is not valid.' in response.content)
        self.assertTrue(
            b'Click <a class="btn btn-secondary" role="button" href="/bitcoin/preferences/" title="Click to change your preferences">Preferences</a> to set it.'
            in response.content)
コード例 #3
0
    def test_update_with_bad_bin_dir(self):
        '''
            Test updating with a bad bin directory.
        '''
        prefs = get_preferences()
        prefs.data_dir = '/tmp/bitcoin/data/'
        prefs.bin_dir = '/bad/bitcoin/bin/'
        prefs.backup_dir = '/tmp/bitcoin/data/backups/'
        save_preferences(prefs)

        request = self.factory.get('/bitcoin/update/')
        response = Update.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(
            b"<title>\nUpdating Bitcoin's Blockchain | Blockchain Backup\n</title>"
            in response.content)
        self.assertTrue(
            b'The Bitcoin binary directory is not valid.' in response.content)
        self.assertFalse(
            b'The Bitcoin data directory is not valid.' in response.content)
        self.assertFalse(
            b'The Bitcoin backup directory is not valid.' in response.content)
        self.assertTrue(
            b'Click <a class="btn btn-secondary" role="button" href="/bitcoin/preferences/" title="Click to change your preferences">Preferences</a> to set it.'
            in response.content)

        self.assertTrue(get_backups_enabled())
コード例 #4
0
def get_preferences():
    '''
        Get the preferences.

        >>> prefs = get_preferences()
        >>> isinstance(prefs, Preferences)
        True
    '''

    return preferences.get_preferences()
コード例 #5
0
    def test_restore_with_bad_data_dir(self):
        '''
            Test restoring with a bad data directory.
        '''
        prefs = preferences.get_preferences()
        prefs.data_dir = '/bad/bitcoin/data/'
        prefs.bin_dir = '/tmp/bitcoin/bin/'
        prefs.restore_dir = '/tmp/bitcoin/data/restores/'
        preferences.save_preferences(prefs)

        request = self.factory.get('/bitcoin/restore/')
        response = views.Restore.as_view()(request)

        self.assertEqual(response.status_code, 200)
        self.assertTrue(b"<title>\nUnable to Restore the Blockchain | Blockchain Backup\n</title>" in response.content)
        self.assertTrue(b"Unable to Restore the Blockchain" in response.content)
        self.assertTrue(b'The Bitcoin data directory is not valid. Click <a class="btn btn-secondary" role="button" href="/bitcoin/preferences/" title="Click to change your preferences">Preferences</a> to set it.' in response.content)
        self.assertFalse(b'Select backup to restore:' in response.content)
        self.assertFalse(b'<input type="submit" value="Yes, start restoring" name="yes-start-restoring-button" id="yes-start-restoring-id" alt="Yes, start restoring" class="btn btn-primary font-weight-bold " role="button"  title="Restore the blockchain now"/>' in response.content)
コード例 #6
0
def set_new_preferences(new_preferences):
    '''
        Set the preferences.

        >>> set_new_preferences(None)
    '''
    if new_preferences is None:
        while True:
            try:
                prefs = preferences.get_preferences()
                prefs.delete()
            except:
                break
    else:
        prefs = get_preferences()
        prefs.data_dir = new_preferences.data_dir
        prefs.bin_dir = new_preferences.bin_dir
        prefs.backup_schedule = new_preferences.backup_schedule
        prefs.backup_levels = new_preferences.backup_levels
        prefs.backup_dir = new_preferences.backup_dir
        prefs.extra_args = new_preferences.extra_args
        preferences.save_preferences(prefs)
コード例 #7
0
    def post_page(self, request):

        form = PreferencesForm(request.POST)
        if form.is_valid():

            data_dir = form.cleaned_data['data_dir']
            bin_dir = form.cleaned_data['bin_dir']
            backup_schedule = form.cleaned_data['backup_schedule']
            backup_levels = form.cleaned_data['backup_levels']
            backup_dir = form.cleaned_data['backup_dir']
            extra_args = form.cleaned_data['extra_args']

            prefs = preferences.get_preferences()
            prefs.data_dir = data_dir
            prefs.bin_dir = bin_dir
            prefs.backup_schedule = backup_schedule
            prefs.backup_levels = backup_levels
            prefs.backup_dir = backup_dir
            prefs.extra_args = extra_args
            preferences.save_preferences(prefs)
            log('Changed preferences.')
            messages.success(request, 'Changed preferences.')

            # send them back to the home page
            response = HttpResponseRedirect('/')

        else:
            log('form is not valid')
            log_bad_fields(form)
            messages.error(
                request,
                'Invalid preferences -- details about the errors appear below the fields.'
            )
            response = render(request, self.form_url, {
                'form': form,
            })

        return response