예제 #1
0
def _getNewFilePath(downloadTo, filename):
    """
    Get the absolute file name.
    :param downloadTo: the location where downloads are saved
    :param filename: the new filename

    :returns: a filepath
    """
    return filepath.FilePath(filepath.joinpath(downloadTo, filename))
예제 #2
0
def generate_sub_packages(path_file):
    """Generate directories and __init__.py scripts for subpackages
    """

    modules_dirs = filepath.FilePath(path_file.path.rsplit('/', 1)[0])
    modules_dirs.makedirs()
    for directory in [f for f in modules_dirs.walk() if f.isdir()]:
        fp = filepath.FilePath(filepath.joinpath(f.path, '__init__.py'))
        if not fp.exists():
            fp.touch()
예제 #3
0
    def parseArgs(self, name=None):
        """Parse command arguments
        """

        if name is None:
            self['name'] = name
            return

        regex = re.compile(r'[^._a-zA-Z0-9]')
        name = regex.sub('', name)
        path, name = commons.process_path_name(name)

        self['filename'] = filepath.joinpath(path.lower(), name.lower())
        self['name'] = CamelCase(name.replace('_', ' ')).camelize(True)
예제 #4
0
    def parseArgs(self, name=None):
        """Parse command arguments
        """

        if name is None:
            self['name'] = name
            return

        regex = re.compile(r'[^._a-zA-Z0-9]')
        name = regex.sub('', name)
        path, name = commons.process_path_name(name)

        self['filename'] = filepath.joinpath(path.lower(), name.lower())
        self['name'] = CamelCase(name.replace('_', ' ')).camelize(True)
예제 #5
0
def createFileDirs(downloadTo, newPath):
    """
    Make the directories that live between downloadTo and newPath. This only
    createsFiles and returns no information.

    :param downloadTo: where downloads are saved
    :param newPath: where the new file will be saved

    :returns: None
    """
    toCreate = filepath.FilePath(filepath.joinpath(downloadTo, newPath))
    parentDir = toCreate.parent()
    if not parentDir.exists():
        parentDir.makedirs()
예제 #6
0
    def _load_from_package(self, package=''):
        """Load modules from the given package
        """

        try:
            for f in filepath.listdir(package):
                filename = filepath.joinpath(package, f)
                fp = filepath.FilePath(filename)
                if fp.isdir():
                    self._load_from_package(filename)
                    continue
                if self.pattern.search(filename) is not None:
                    if self.is_valid_file(filename):
                        self.load(filename)
        except OSError:
            pass
예제 #7
0
    def _modulize_path(self, path):
        """Return a modularied version of the given path
        """

        path = filepath.joinpath(
            self._module_store, path.split(self._module_store + '/')[1])
        if self._package is not None:
            # seems like this is a package
            retval = '{}{}'.format(
                self._package,
                path.rsplit(self._package, 1)[1]
            ).replace('/', '.')
        else:
            retval = path.replace('/', '.')

        return retval
예제 #8
0
    def _load_from_package(self, package=''):
        """Load modules from the given package
        """

        try:
            for f in filepath.listdir(package):
                filename = filepath.joinpath(package, f)
                fp = filepath.FilePath(filename)
                if fp.isdir():
                    self._load_from_package(filename)
                    continue
                if self.pattern.search(filename) is not None:
                    if self.is_valid_file(filename):
                        self.load(filename)
        except OSError:
            pass
예제 #9
0
    def _modulize_path(self, path):
        """Return a modularied version of the given path
        """

        path = filepath.joinpath(
            self._module_store, path.split(self._module_store + '/')[1])
        if self._package is not None:
            # seems like this is a package
            retval = '{}{}'.format(
                self._package,
                path.rsplit(self._package, 1)[1]
            ).replace('/', '.')
        else:
            retval = path.replace('/', '.')

        return retval
예제 #10
0
    def __prepare_file(self, valid):
        # we need to delete binary files from previous tests because we get
        # invalid magic method error on buildbot and PyPy
        binary = filepath.FilePath(
            filepath.joinpath(tempfile.gettempdir(),
                              'fabric_deployer_test.dco'))
        if binary.exists():
            binary.remove()
        del binary

        tmpdir = tempfile.gettempdir()
        content = '''{}
from fabric.api import local


def host_type():
    local('whoami')
        '''.format('# -*- mamba-deployer: fabric -*-' if valid is True else '')
        with open(tmpdir + sep + 'fabric_deployer_test.dc', 'w') as fd:
            fd.write(content)
예제 #11
0
    def __prepare_file(self, valid):
        # we need to delete binary files from previous tests because we get
        # invalid magic method error on buildbot and PyPy
        binary = filepath.FilePath(filepath.joinpath(
            tempfile.gettempdir(),
            'fabric_deployer_test.dco'
        ))
        if binary.exists():
            binary.remove()
        del binary

        tmpdir = tempfile.gettempdir()
        content = '''{}
from fabric.api import local


def host_type():
    local('whoami')
        '''.format('# -*- mamba-deployer: fabric -*-' if valid is True else '')
        with open(tmpdir + sep + 'fabric_deployer_test.dc', 'w') as fd:
            fd.write(content)