def __init__(self, interpreter, program, args=None): if args is None: args = [] self.args = [] if interpreter: self.args.append(interpreter) libpath = external_resource( os.path.dirname(program), '%s.resources.external' % calling_package()) if interpreter.startswith('perl') or interpreter.startswith( 'ruby'): self.args.append('-I%s' % libpath) elif interpreter.startswith('java'): self.args.extend(['-cp', libpath]) if ' ' in program: raise ValueError('Transform name %r cannot have spaces.' % program) else: self.args.append( external_resource(program, '%s.resources.external' % calling_package())) if isinstance(args, basestring): self.args = re.split(r'\s+', args) else: self.args.extend(args)
def __init__(self, transform_name, transform_args=None, interpreter=None, is_resource=True): if transform_args is None: transform_args = [] self._extra_external_args = [] if interpreter is not None: self._extra_external_args.append(interpreter) libpath = external_resource( os.path.dirname(transform_name), '%s.resources.external' % calling_package() ) if interpreter.startswith('perl') or interpreter.startswith('ruby'): self._extra_external_args.extend(['-I', libpath]) elif interpreter.startswith('java'): self._extra_external_args.extend(['-cp', libpath]) if ' ' in transform_name: raise ValueError('Transform name %s cannot have spaces.' % repr(transform_name)) elif not is_resource: self._extra_external_args.append(transform_name) else: self._extra_external_args.append( external_resource( transform_name, '%s.resources.external' % calling_package() ) ) if isinstance(transform_args, basestring): self._extra_external_args = re.split(r'\s+', transform_args) else: self._extra_external_args.extend(transform_args)
def __init__(self, interpreter, program, args=None): if args is None: args = [] self.args = [] if interpreter: self.args.append(interpreter) libpath = external_resource( os.path.dirname(program), '%s.resources.external' % calling_package() ) if interpreter.startswith('perl') or interpreter.startswith('ruby'): self.args.append('-I%s' % libpath) elif interpreter.startswith('java'): self.args.extend(['-cp', libpath]) if ' ' in program: raise ValueError('Transform name %r cannot have spaces.' % program) else: self.args.append( external_resource( program, '%s.resources.external' % calling_package() ) ) if isinstance(args, basestring): self.args = re.split(r'\s+', args) else: self.args.extend(args)
def __init__(self, transform_name, transform_args=None, interpreter=None, is_resource=True): if transform_args is None: transform_args = [] self._extra_external_args = [] if interpreter is not None: self._extra_external_args.append(interpreter) libpath = external_resource( os.path.dirname(transform_name), '%s.resources.external' % calling_package()) if interpreter.startswith('perl') or interpreter.startswith( 'ruby'): self._extra_external_args.extend(['-I', libpath]) elif interpreter.startswith('java'): self._extra_external_args.extend(['-cp', libpath]) if ' ' in transform_name: raise ValueError('Transform name %s cannot have spaces.' % repr(transform_name)) elif not is_resource: self._extra_external_args.append(transform_name) else: self._extra_external_args.append( external_resource(transform_name, '%s.resources.external' % calling_package())) if isinstance(transform_args, basestring): self._extra_external_args = re.split(r'\s+', transform_args) else: self._extra_external_args.extend(transform_args)
def __init__(self, interpreter, program, args=None): if args is None: args = [] self.args = [] self.env = os.environ.copy() if interpreter: self.args.append(interpreter) lib_path = external_resource( os.path.dirname(program), '%s.resources.external' % calling_package()) if interpreter.startswith('perl') or interpreter.startswith( 'ruby'): self.args.append('-I%s' % lib_path) elif interpreter.startswith('java'): self.args.extend(['-cp', lib_path]) elif interpreter.startswith('python'): self.env['PYTHONPATH'] = ':'.join( [self.env['PYTHONPATH'], lib_path]) if ' ' in program: raise ValueError('Transform name %r cannot have spaces.' % program) else: self.args.append(external_resource(program)) if isinstance(args, string_types): self.args.extend(re.split(r'\s+', args)) else: self.args.extend(args)
def __init__(self, transform_name, transform_args=None, interpreter=None, is_resource=True): if transform_args is None: transform_args = [] self._extra_external_args = [] if interpreter is not None: self._extra_external_args.append(interpreter) libpath = external_resource(os.path.dirname(transform_name), "%s.resources.external" % calling_package()) if interpreter.startswith("perl") or interpreter.startswith("ruby"): self._extra_external_args.extend(["-I", libpath]) elif interpreter.startswith("java"): self._extra_external_args.extend(["-cp", libpath]) if " " in transform_name: raise ValueError("Transform name %s cannot have spaces." % repr(transform_name)) elif not is_resource: self._extra_external_args.append(transform_name) else: self._extra_external_args.append( external_resource(transform_name, "%s.resources.external" % calling_package()) ) if isinstance(transform_args, basestring): self._extra_external_args = re.split(r"\s+", transform_args) else: self._extra_external_args.extend(transform_args)
def external_resource(name, package=None): """ Returns the absolute path to the external resource requested. If a package is not explicitly specified then the calling package name is used. :param name: path relative to package path of the external resource. :param package: package name in dotted format. :return: the absolute path to the external resource. """ if not package: package = '%s.resources.external' % calling_package() return resource_filename(package, name)
def icon_resource(name, package=None): """ Returns the absolute URI path to an image. If a package is not explicitly specified then the calling package name is used. :param name: path relative to package path of the image resource. :param package: package name in dotted format. :return: the file URI path to the image resource (i.e. file:///foo/bar/image.png). """ if not package: package = '%s.resources.images' % calling_package() name = resource_filename(package, name) if not name.startswith('/'): return 'file://%s' % abspath(name) return 'file://%s' % name
def image_resources(package=None, directory='resources'): """ Returns all images under the directory relative to a package path. If no directory or package is specified then the resources module of the calling package will be used. Images are recursively discovered. :param package: package name in dotted format. :param directory: path relative to package path of the resources directory. :return: a list of images under the specified resources path. """ if not package: package = calling_package() package_dir = '.'.join([package, directory]) images = [] for i in resource_listdir(package, directory): if i.startswith('__') or i.endswith('.egg-info'): continue fname = resource_filename(package_dir, i) if resource_isdir(package_dir, i): images.extend(image_resources(package_dir, i)) elif what(fname): images.append(fname) return images