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('..')
def create(cls, location, metadata=None, config=None): """ Create a new Workflow. :param location: Base directory that the workflow should be created in :type location: unicode or :py:class:`pathlib.Path` :param metadata: Initial metadata for workflow. Must at least contain a `title` item. :type metadata: dict :param config: Initial configuration for workflow :type config: dict or :py:class:`spreads.config.Configuration` :return: The new instance :rtype: :py:class:`Workflow` """ if not isinstance(location, Path): location = Path(location) if metadata is None or 'title' not in metadata: raise ValidationError( metadata={'title': 'Please specify at least a title'}) path = Path(location/util.slugify(metadata['title'])) if path.exists(): raise ValidationError( name="A workflow with that title already exists") wf = cls(path=path, config=config, metadata=metadata) return wf
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)
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)
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)
def create(cls, location, metadata=None, config=None): if not isinstance(location, Path): location = Path(location) if metadata is None or not 'title' in metadata: raise ValidationError( metadata={'title': 'Please specify at least a title'}) path = Path(location/util.slugify(metadata['title'])) if path.exists(): raise ValidationError( name="A workflow with that title already exists") wf = cls(path=path, config=config, metadata=metadata) return wf
def copy_info(pkg, pkg_dir): try: dist = pkg_resources.get_distribution(pkg) except pkg_resources.DistributionNotFound: raise IOError("No distribution could be found for {0}!".format(pkg)) if dist.location == os.getcwd(): egg_name = dist.project_name else: egg_name = dist.egg_name() egg_path = Path(dist.location) / (egg_name + ".egg-info") dist_path = Path(dist.location) / (dist.project_name + "-" + dist.version + ".dist-info") if egg_path.exists(): src_path = egg_path elif dist_path.exists(): src_path = dist_path else: raise IOError("No egg-info or dist-info could be found for {0}!".format(pkg)) if src_path.is_dir(): shutil.copytree(unicode(src_path), unicode(pkg_dir / src_path.name)) else: shutil.copy2(unicode(src_path), unicode(pkg_dir / src_path.name))
def copy_info(pkg, pkg_dir): try: dist = pkg_resources.get_distribution(pkg) except pkg_resources.DistributionNotFound: raise IOError("No distribution could be found for {0}!".format(pkg)) if dist.location == os.getcwd(): egg_name = dist.project_name else: egg_name = dist.egg_name() egg_path = Path(dist.location) / (egg_name + ".egg-info") dist_path = Path(dist.location) / (dist.project_name + "-" + dist.version + ".dist-info") if egg_path.exists(): src_path = egg_path elif dist_path.exists(): src_path = dist_path else: raise IOError( "No egg-info or dist-info could be found for {0}!".format(pkg)) if src_path.is_dir(): shutil.copytree(unicode(src_path), unicode(pkg_dir / src_path.name)) else: shutil.copy2(unicode(src_path), unicode(pkg_dir / src_path.name))
def yield_devices(cls, config): """ Search for usable devices, yield one at a time :param config: spreads configuration :type config: spreads.confit.ConfigView """ SPECIAL_CASES = { # noqa # (idVendor, idProduct): SpecialClass (0x4a9, 0x31ef): QualityFix, # not r47, but has the same bug (0x4a9, 0x3218): QualityFix, (0x4a9, 0x3223): A3300, (0x4a9, 0x3224): QualityFix, (0x4a9, 0x3225): QualityFix, (0x4a9, 0x3226): QualityFix, (0x4a9, 0x3227): QualityFix, (0x4a9, 0x3228): QualityFix, (0x4a9, 0x3229): QualityFix, (0x4a9, 0x322a): QualityFix, (0x4a9, 0x322b): QualityFix, (0x4a9, 0x322c): QualityFix, } # Check if we can find the chdkptp executable chdkptp_path = Path(config["chdkptp_path"].get(unicode)) if not chdkptp_path.exists() or not (chdkptp_path / 'chdkptp').exists(): raise MissingDependencyException( "Could not find executable `chdkptp`. Please make sure that " "the `chdkptp_path` setting in your `chdkcamera` " "configuration points to " "a directory containing chdkptp " "and its libraries. Current setting is `{0}`".format( chdkptp_path)) # only match ptp devices in find_all def is_ptp(dev): for cfg in dev: if usb.util.find_descriptor(cfg, bInterfaceClass=6, bInterfaceSubClass=1): return True for dev in usb.core.find(find_all=True, custom_match=is_ptp): ids = (dev.idVendor, dev.idProduct) if ids in SPECIAL_CASES: yield SPECIAL_CASES[ids](config, dev) else: yield cls(config, dev)
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
def yield_devices(cls, config): """ Search for usable devices, yield one at a time :param config: spreads configuration :type config: spreads.confit.ConfigView """ SPECIAL_CASES = { # (idVendor, idProduct): SpecialClass (0x4a9, 0x31ef): QualityFix, # not r47, but has the same bug (0x4a9, 0x3218): QualityFix, (0x4a9, 0x3223): QualityFix, (0x4a9, 0x3224): QualityFix, (0x4a9, 0x3225): QualityFix, (0x4a9, 0x3226): QualityFix, (0x4a9, 0x3227): QualityFix, (0x4a9, 0x3228): QualityFix, (0x4a9, 0x3229): QualityFix, (0x4a9, 0x322a): A2200, (0x4a9, 0x322b): QualityFix, (0x4a9, 0x322c): QualityFix, } # Check if we can find the chdkptp executable chdkptp_path = Path(config["chdkptp_path"].get(unicode)) if not chdkptp_path.exists() or not (chdkptp_path/'chdkptp').exists(): raise MissingDependencyException( "Could not find executable `chdkptp`. Please make sure that " "the `chdkptp_path` setting in your `chdkcamera` " "configuration points to " "a directory containing chdkptp " "and its libraries. Current setting is `{0}`" .format(chdkptp_path) ) # only match ptp devices in find_all def is_ptp(dev): for cfg in dev: if usb.util.find_descriptor(cfg, bInterfaceClass=6, bInterfaceSubClass=1): return True for dev in usb.core.find(find_all=True, custom_match=is_ptp): ids = (dev.idVendor, dev.idProduct) if ids in SPECIAL_CASES: yield SPECIAL_CASES[ids](config, dev) else: yield cls(config, dev)
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
def open_connection(): db_path = Path(app.config['database']) if not db_path.exists(): initialize_database() return sqlite3.connect(unicode(db_path))