Exemple #1
0
def get_data_dir(create=False):
    UNIX_DIR_VAR = 'XDG_DATA_DIRS'
    UNIX_DIR_FALLBACK = '~/.config'
    WINDOWS_DIR_VAR = 'APPDATA'
    WINDOWS_DIR_FALLBACK = '~\\AppData\\Roaming'
    MAC_DIR = '~/Library/Application Support'
    base_dir = None
    if platform.system() == 'Darwin':
        if Path(UNIX_DIR_FALLBACK).exists:
            base_dir = UNIX_DIR_FALLBACK
        else:
            base_dir = MAC_DIR
    elif platform.system() == 'Windows':
        if WINDOWS_DIR_VAR in os.environ:
            base_dir = os.environ[WINDOWS_DIR_VAR]
        else:
            base_dir = WINDOWS_DIR_FALLBACK
    else:
        if UNIX_DIR_VAR in os.environ:
            base_dir = os.environ[UNIX_DIR_VAR]
        else:
            base_dir = UNIX_DIR_FALLBACK
    app_path = Path(base_dir)/'spreads'
    if create and not app_path.exists():
        app_path.mkdir()
    return unicode(app_path)
Exemple #2
0
def get_data_dir(create=False):
    """ Return (and optionally create) the user's default data directory.

    :param create:  Create the data directory if it doesn't exist
    :type create:   bool
    :return:        Path to the default data directory
    :rtype:         unicode
    """
    unix_dir_var = 'XDG_DATA_HOME'
    unix_dir_fallback = '~/.config'
    windows_dir_var = 'APPDATA'
    windows_dir_fallback = '~\\AppData\\Roaming'
    mac_dir = '~/Library/Application Support'
    base_dir = None
    if is_os('darwin'):
        if Path(unix_dir_fallback).exists:
            base_dir = unix_dir_fallback
        else:
            base_dir = mac_dir
    elif is_os('windows'):
        if windows_dir_var in os.environ:
            base_dir = os.environ[windows_dir_var]
        else:
            base_dir = windows_dir_fallback
    else:
        if unix_dir_var in os.environ:
            base_dir = os.environ[unix_dir_var]
        else:
            base_dir = unix_dir_fallback
    app_path = Path(base_dir) / 'spreads'
    if create and not app_path.exists():
        app_path.mkdir()
    return unicode(app_path)
Exemple #3
0
def get_data_dir(create=False):
    UNIX_DIR_VAR = 'XDG_DATA_DIRS'
    UNIX_DIR_FALLBACK = '~/.config'
    WINDOWS_DIR_VAR = 'APPDATA'
    WINDOWS_DIR_FALLBACK = '~\\AppData\\Roaming'
    MAC_DIR = '~/Library/Application Support'
    base_dir = None
    if platform.system() == 'Darwin':
        if Path(UNIX_DIR_FALLBACK).exists:
            base_dir = UNIX_DIR_FALLBACK
        else:
            base_dir = MAC_DIR
    elif platform.system() == 'Windows':
        if WINDOWS_DIR_VAR in os.environ:
            base_dir = os.environ[WINDOWS_DIR_VAR]
        else:
            base_dir = WINDOWS_DIR_FALLBACK
    else:
        if UNIX_DIR_VAR in os.environ:
            base_dir = os.environ[UNIX_DIR_VAR]
        else:
            base_dir = UNIX_DIR_FALLBACK
    app_path = Path(base_dir) / 'spreads'
    if create and not app_path.exists():
        app_path.mkdir()
    return unicode(app_path)
Exemple #4
0
def build_msi(bitness=32):
    egg_path = Path('spreads.egg-info')
    if egg_path.exists():
        shutil.rmtree(unicode(egg_path))
    build_path = Path('build')
    if not build_path.exists():
        build_path.mkdir()
    pkg_dir = build_path / 'pynsist_pkgs'
    if pkg_dir.exists():
        shutil.rmtree(unicode(pkg_dir))
    pkg_dir.mkdir()
    for pkg in BINARY_PACKAGES.itervalues():
        arch = 'win32' if bitness == 32 else 'win-amd64'
        extract_native_pkg(pkg.format(arch=arch), pkg_dir)

    for pkg in (x.project_name for x in SOURCE_PACKAGES
                if x.project_name is not None):
        copy_info(pkg, pkg_dir)

    icon = os.path.abspath("spreads.ico")
    extra_files = [(unicode(
        (Path('win_deps') / 'extra' /
         x.format(arch='.amd64' if bitness == 64 else '')).absolute()), None)
                   for x in EXTRA_FILES]
    nsi_template = os.path.abspath("template.nsi")

    # NOTE: We need to remove the working directory from sys.path to force
    # pynsist to copy all of our modules, including 'spreads' and 'spreadsplug'
    # from the site-packages. Additionally, we need to change into the
    # build directory.
    if os.getcwd() in sys.path:
        sys.path.remove(os.getcwd())
    os.chdir(unicode(build_path))
    builder = InstallerBuilder(
        appname="spreads",
        version=spreads.__version__,
        packages=[x.module_name for x in SOURCE_PACKAGES],
        extra_files=extra_files,
        py_version="2.7.6",
        py_bitness=bitness,
        build_dir='msi{0}'.format(bitness),
        installer_name=None,
        nsi_template=nsi_template,
        icon=icon,
        shortcuts={
            'Configure spreads': {
                'entry_point': 'spreads.main:run_config_windows',
                'icon': icon,
                'console': False
            },
            'Spreads Web Service': {
                'entry_point': 'spreads.main:run_service_windows',
                'icon': icon,
                'console': False
            }
        })
    builder.run()
    os.chdir('..')
def build_msi(bitness=32):
    egg_path = Path('spreads.egg-info')
    if egg_path.exists():
        shutil.rmtree(unicode(egg_path))
    build_path = Path('build')
    if not build_path.exists():
        build_path.mkdir()
    pkg_dir = build_path/'pynsist_pkgs'
    if pkg_dir.exists():
        shutil.rmtree(unicode(pkg_dir))
    pkg_dir.mkdir()
    for pkg in BINARY_PACKAGES.itervalues():
        arch = 'win32' if bitness == 32 else 'win-amd64'
        extract_native_pkg(pkg.format(arch=arch), pkg_dir)

    for pkg in (x.project_name for x in SOURCE_PACKAGES
                if x.project_name is not None):
        copy_info(pkg, pkg_dir)

    icon = os.path.abspath("spreads.ico")
    extra_files = [(unicode((Path('win_deps') / 'extra' /
                             x.format(arch='.amd64' if bitness == 64 else ''))
                            .absolute()), None) for x in EXTRA_FILES]
    nsi_template = os.path.abspath("template.nsi")

    # NOTE: We need to remove the working directory from sys.path to force
    # pynsist to copy all of our modules, including 'spreads' and 'spreadsplug'
    # from the site-packages. Additionally, we need to change into the
    # build directory.
    if os.getcwd() in sys.path:
        sys.path.remove(os.getcwd())
    os.chdir(unicode(build_path))
    builder = InstallerBuilder(
        appname="spreads",
        version=spreads.__version__,
        packages=[x.module_name for x in SOURCE_PACKAGES],
        extra_files=extra_files,
        py_version="2.7.6",
        py_bitness=bitness,
        build_dir='msi{0}'.format(bitness),
        installer_name=None,
        nsi_template=nsi_template,
        icon=icon,
        shortcuts={
            'Configure spreads': {
                'entry_point': 'spreads.main:run_config_windows',
                'icon': icon,
                'console': False},
            'Spreads Web Service': {
                'entry_point': 'spreads.main:run_service_windows',
                'icon': icon,
                'console': False}
        }
    )
    builder.run()
    os.chdir('..')
Exemple #6
0
def transfer_to_stick(wf_id, base_path):
    workflow = Workflow.find_by_id(base_path, wf_id)
    stick = find_stick()
    files = list(workflow.path.rglob('*'))
    num_files = len(files)
    # Filter out problematic characters
    clean_name = (workflow.path.name.replace(':', '_').replace('/', '_'))
    workflow.status['step'] = 'transfer'
    try:
        if IS_WIN:
            target_path = Path(stick) / clean_name
        else:
            mount = stick.get_dbus_method(
                "FilesystemMount",
                dbus_interface="org.freedesktop.UDisks.Device")
            mount_point = mount('', [])
            target_path = Path(mount_point) / clean_name
        if target_path.exists():
            shutil.rmtree(unicode(target_path))
        target_path.mkdir()
        signals['transfer:started'].send(workflow)
        for num, path in enumerate(files, 1):
            signals['transfer:progressed'].send(workflow,
                                                progress=(num / num_files) *
                                                0.79,
                                                status=path.name)
            workflow.status['step_done'] = (num / num_files) * 0.79
            target = target_path / path.relative_to(workflow.path)
            if path.is_dir():
                target.mkdir()
            else:
                shutil.copyfile(unicode(path), unicode(target))
    finally:
        if 'mount_point' in locals():
            signals['transfer:progressed'].send(workflow,
                                                progress=0.8,
                                                status="Syncing...")
            workflow.status['step_done'] = 0.8
            unmount = stick.get_dbus_method(
                "FilesystemUnmount",
                dbus_interface="org.freedesktop.UDisks.Device")
            unmount([], timeout=1e6)  # dbus-python doesn't know an infinite
            # timeout... unmounting sometimes takes a
            # long time, since the device has to be
            # synced.
        signals['transfer:completed'].send(workflow)
        workflow.status['step'] = None
Exemple #7
0
def transfer_to_stick(wf_id, base_path):
    workflow = Workflow.find_by_id(base_path, wf_id)
    stick = find_stick()
    files = list(workflow.path.rglob('*'))
    num_files = len(files)
    # Filter out problematic characters
    clean_name = (workflow.path.name.replace(':', '_')
                                    .replace('/', '_'))
    workflow.status['step'] = 'transfer'
    try:
        if IS_WIN:
            target_path = Path(stick)/clean_name
        else:
            mount = stick.get_dbus_method(
                "FilesystemMount",
                dbus_interface="org.freedesktop.UDisks.Device")
            mount_point = mount('', [])
            target_path = Path(mount_point)/clean_name
        if target_path.exists():
            shutil.rmtree(unicode(target_path))
        target_path.mkdir()
        signals['transfer:started'].send(workflow)
        for num, path in enumerate(files, 1):
            signals['transfer:progressed'].send(
                workflow, progress=(num/num_files)*0.79, status=path.name)
            workflow.status['step_done'] = (num/num_files)*0.79
            target = target_path/path.relative_to(workflow.path)
            if path.is_dir():
                target.mkdir()
            else:
                shutil.copyfile(unicode(path), unicode(target))
    finally:
        if 'mount_point' in locals():
            signals['transfer:progressed'].send(workflow, progress=0.8,
                                                status="Syncing...")
            workflow.status['step_done'] = 0.8
            unmount = stick.get_dbus_method(
                "FilesystemUnmount",
                dbus_interface="org.freedesktop.UDisks.Device")
            unmount([], timeout=1e6)  # dbus-python doesn't know an infinite
                                      # timeout... unmounting sometimes takes a
                                      # long time, since the device has to be
                                      # synced.
        signals['transfer:completed'].send(workflow)
        workflow.status['step'] = None