コード例 #1
0
def dropbox_setup(username, stdin, stdout):
    """helper-interface to setup dropbox."""
    _stash = core.get_stash()
    Text = _stash.text_color  # alias
    stdout.write(Text("=" * 40 + "\nDropbox-setup\n" + "=" * 25 + "\n", "blue"))
    header = "This interface will help you setup the dropbox access"
    header += " for '{n}'.".format(n=Text(username, "blue"))
    abort = Text("abort", "yellow")
    choices = ("I already have an authorization-code", "I dont have an authorizaion-code", abort)
    choice = _menu(header, choices, stdin, stdout)
    if choice == 2:
        raise KeyboardInterrupt("Setup aborted.")
    elif choice == 0:
        pass
    elif choice == 1:
        stdout.write("Please read this. After reading, press enter to continue.\n")
        text1 = "To allow StaSh access to your dropbox, "
        text2 = "you will have to perform the following steps:\n"
        stdout.write(text1 + text2)
        stdout.write("  1) Create a dropbox account (if you dont have one yet)\n")
        stdout.write("  2) Upgrade your Account to a dropbox-developer account.\n")
        stdout.write("  3) Create a dropbox-app.\n")
        stdout.write("  4) Generate an access token.\n")
        stdout.write("  5) Enter the access token.\n")
        stdout.write(Text("Continue?", "yellow"))
        stdin.readline()
        while True:
            header = "Select action"
            choices = ("Register to dropbox", "Go to the developer-page", "proceed", abort)
            choice = _menu(header, choices, stdin, stdout)
            if choice == 0:
                _open_url("https://www.dropbox.com/register")
            elif choice == 1:
                _open_url("https://developer.dropbox.com")
            elif choice == 2:
                break
            elif choice == 3:
                raise KeyboardInterrupt("Setup aborted.")
    stdout.write("Enter the access token (leave empty to use clipboard):\n>")
    access_token = stdin.readline().strip()
    if len(access_token) == 0:
        access_token = clipboard.get()
        stdout.write("Using clipboard (length={l}).\n".format(l=len(access_token)))
    stdout.write("Testing token... ")
    try:
        db = dropbox.Dropbox(access_token)
        db.files_list_folder("")
    except (dropbox.exceptions.ApiError, dropbox.exceptions.BadInputError):
        sys.stdout.write(Text("Error", "red"))
        sys.stdout.write(".\nAuthorization failed! Please try again.\n")
        raise KeyboardInterrupt("Setup failed!")
    stdout.write(Text("Done", "green"))
    stdout.write(".\nSaving... ")
    save_dropbox_data(username, access_token)
    stdout.write(Text("Done", "green"))
    stdout.write(".\n")
    return True
コード例 #2
0
ファイル: mount_manager.py プロジェクト: zainhub/stash
# -*- coding: utf-8 -*-
"""This module coordinates the mount-system."""
import os

from six import string_types

from mlpatches.mount_patches import MOUNT_PATCHES
from stashutils.core import get_stash
from stashutils.fsi.base import BaseFSI
from stashutils.fsi.errors import OperationFailure
from stashutils.mount_ctrl import get_manager, set_manager

_stash = get_stash()

# Exceptions


class MountError(Exception):
    """raised when a mount failed."""
    pass


# the manager


class MountManager(object):
    """
	this class keeps track of the FSIs and their position in the filesystem.
	"""
    def __init__(self):
        self.path2fs = {}
コード例 #3
0
ファイル: local.py プロジェクト: BBOOXX/stash
"""The FSI for the local filesystem."""
import os
import shutil

from stashutils.core import get_stash
from stashutils.fsi.base import BaseFSI
from stashutils.fsi.errors import OperationFailure, IsDir, IsFile
from stashutils.fsi.errors import AlreadyExists

from mlpatches.mount_base import _org_stat, _org_listdir, _org_mkdir
from mlpatches.mount_base import _org_open, _org_remove

_stash = get_stash()


class LocalFSI(BaseFSI):
	"""A FSI for the local filesystem."""
	def __init__(self, logger=None):
		self.logger = logger
		self.path = os.getcwd()
	
	def _getabs(self, name):
		"""returns the path for name."""
		path = os.path.join(self.path, name)
		while path.startswith("/"):
			path = path[1:]
		return os.path.abspath(
			os.path.join(self.basepath, path)
			)

	def connect(self, *args):
コード例 #4
0
ファイル: dbutils.py プロジェクト: BBOOXX/stash
def _open_url(url):
	"""opens an url"""
	_stash = core.get_stash()
	_stash("webviewer {u}".format(u=url))
コード例 #5
0
ファイル: dbutils.py プロジェクト: BBOOXX/stash
def dropbox_setup(username, stdin, stdout):
	"""helper-interface to setup dropbox."""
	_stash = core.get_stash()
	Text = _stash.text_color  # alias
	stdout.write(Text("="*40+"\nDropbox-setup\n"+"="*25+"\n", "blue"))
	header = "This interface will help you setup the dropbox access"
	header += " for '{n}'.".format(n=Text(username, "blue"))
	abort = Text("abort", "yellow")
	choices = (
		"I already have an authorization-code",
		"I dont have an authorizaion-code", abort
		)
	choice = _menu(header, choices, stdin, stdout)
	if choice == 2:
		raise KeyboardInterrupt("Setup aborted.")
	elif choice == 0:
		pass
	elif choice == 1:
		stdout.write("Please read this. After reading, press enter to continue.\n")
		text1 = "To allow StaSh access to your dropbox, "
		text2 = "you will have to perform the following steps:\n"
		stdout.write(text1 + text2)
		stdout.write("  1) Create a dropbox account (if you dont have one yet)\n")
		stdout.write("  2) Upgrade your Account to a dropbox-developer account.\n")
		stdout.write("  3) Create a dropbox-app.\n")
		stdout.write("  4) Generate an access token.\n")
		stdout.write("  5) Enter the access token.\n")
		stdout.write(Text("Continue?", "yellow"))
		stdin.readline()
		while True:
			header = "Select action"
			choices = (
				"Register to dropbox",
				"Go to the developer-page",
				"proceed",
				abort)
			choice = _menu(header, choices, stdin, stdout)
			if choice == 0:
				_open_url("https://www.dropbox.com/register")
			elif choice == 1:
				_open_url("https://developer.dropbox.com")
			elif choice == 2:
				break
			elif choice == 3:
				raise KeyboardInterrupt("Setup aborted.")
	stdout.write(
		"Enter the access token (leave empty to use clipboard):\n>"
		)
	access_token = stdin.readline().strip()
	if len(access_token) == 0:
		access_token = clipboard.get()
		stdout.write("Using clipboard (length={l}).\n".format(l=len(access_token)))
	stdout.write("Testing token... ")
	try:
		db = dropbox.Dropbox(access_token)
		db.files_list_folder("")
	except (dropbox.exceptions.ApiError, dropbox.exceptions.BadInputError):
		sys.stdout.write(Text("Error", "red"))
		sys.stdout.write(".\nAuthorization failed! Please try again.\n")
		raise KeyboardInterrupt("Setup failed!")
	stdout.write(Text("Done", "green"))
	stdout.write(".\nSaving... ")
	save_dropbox_data(
		username, access_token
		)
	stdout.write(Text("Done", "green"))
	stdout.write(".\n")
	return True
コード例 #6
0
def _open_url(url):
    """opens an url"""
    _stash = core.get_stash()
    _stash("webviewer {u}".format(u=url))