Python os.path.rstrip() Examples

The following are code examples for showing how to use os.path.rstrip(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: vergeml   Author: vergeml   File:    MIT License 7 votes vote down vote up
def scan(self, path, exclude=[]) -> List[str]:
        """Scan path for matching files.

        :param path: the path to scan
        :param exclude: a list of directories to exclude

        :return: a list of sorted filenames
        res = []
        path = path.rstrip("/").rstrip("\\")
        for pat in self.input_patterns:
            res.extend(glob.glob(path + os.sep + pat, recursive=True))

        res = list(filter(lambda p: os.path.isfile(p), res))

        if exclude:
            def excluded(path):
                for e in exclude:
                    if path.startswith(e):
                        return True
                return False

            res = list(filter(lambda p: not excluded(p), res))

        return sorted(res) 
Example 2
Project: simLAB   Author: kamwar   File:    GNU General Public License v2.0 6 votes vote down vote up
def findFileOrDirectory(self, path):
        path = self.getFilePath(path)
        if not path:
            return None, None
        xmlPath = self.simXml.getXmlPath(path)
        node = self.simXml.find(xmlPath)
        if node == None:
            if path[-1] != "/":
                #try to select direcotry
                path += "/"
                xmlPath = self.simXml.getXmlPath(path)
                node = self.simXml.find(xmlPath)
                #try to select file
                path = path.rstrip("/")
                xmlPath = self.simXml.getXmlPath(path)
                node = self.simXml.find(xmlPath)
            if node == None:
                logging.error("Failed to select: %s" %xmlPath)
                return None, None
        return node, xmlPath 
Example 3
Project: isomer   Author: isomeric   File:    GNU Affero General Public License v3.0 6 votes vote down vote up
def get_path(location: str, subfolder: str, ensure: bool = False):
    """Return a normalized path for the running instance and environment

    :param location str Either cache, local or lib - all reside in /var
    :param subfolder str Subfolder inside location
    :param ensure bool Create folder, if it doesn't exist and this parameter is True

    if PREFIX not in (None, ""):
        path = os.path.join(PREFIX, locations[location].lstrip("/") % INSTANCE)
        path = locations[location] % INSTANCE

    if ENVIRONMENT is not None:
        path = os.path.join(path, str(ENVIRONMENT))

    path = os.path.join(path, subfolder)
    path = path.rstrip("/")

    if ensure and not os.path.exists(path):

    return path 
Example 4
Project: TOUCAN   Author: toucan-project   File:    MIT License 5 votes vote down vote up
def parse_deploy_cached(canary):
    """Parse the deploy cache file and return a list."""

    deploy = []

    Deployment = apps.get_model('canary_files.Deployment')
    items = Deployment.objects.filter(canary=canary)

    for item in items:

        suffix, path = item.canary_string.split(':')
        deploy.append((suffix, path.rstrip()))

    return deploy 
Example 5
Project: meuh-python   Author: johnnoone   File:    MIT License 5 votes vote down vote up
def ensure_dir(path):
    """Ensure that path exists.
    path = path.rstrip('/')
    if not os.path.exists(path):
        os.makedirs(path)"created %s", path)
        return True
    return False 
Example 6
Project: node-gn   Author: Shouqun   File:    MIT License 5 votes vote down vote up
def parse_got_revision(gclient_output, got_revision_mapping):
  """Translate git gclient revision mapping to build properties."""
  properties = {}
  solutions_output = {
      # Make sure path always ends with a single slash.
      '%s/' % path.rstrip('/') : solution_output for path, solution_output
      in gclient_output['solutions'].iteritems()
  for property_name, dir_name in got_revision_mapping.iteritems():
    # Make sure dir_name always ends with a single slash.
    dir_name = '%s/' % dir_name.rstrip('/')
    if dir_name not in solutions_output:
    solution_output = solutions_output[dir_name]
    if solution_output.get('scm') is None:
      # This is an ignored DEPS, so the output got_revision should be 'None'.
      revision = commit_position = None
      # Since we are using .DEPS.git, everything had better be git.
      assert solution_output.get('scm') == 'git'
      revision = git('rev-parse', 'HEAD', cwd=dir_name).strip()
      commit_position = get_commit_position(dir_name)

    properties[property_name] = revision
    if commit_position:
      properties['%s_cp' % property_name] = commit_position

  return properties 
Example 7
Project: jumpscale_core8   Author: Jumpscale   File:    Apache License 2.0 5 votes vote down vote up
def getBaseName(self, path):
        """Return the base name of pathname path."""
        self.logger.debug('Get basename for path: %s' % path)
        if path is None:
            raise TypeError('Path is not passed in system.fs.getDirName')
            return os.path.basename(path.rstrip(os.path.sep))
        except Exception as e:
            raise j.exceptions.RuntimeError(
                'Failed to get base name of the given path: %s, Error: %s' % (path, str(e)))