當前位置: 首頁>>代碼示例>>Python>>正文


Python path.strip方法代碼示例

本文整理匯總了Python中os.path.strip方法的典型用法代碼示例。如果您正苦於以下問題:Python path.strip方法的具體用法?Python path.strip怎麽用?Python path.strip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os.path的用法示例。


在下文中一共展示了path.strip方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: action_upload

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def action_upload(self, courseid, taskid, path, fileobj):
        """ Upload a file """
        # the path is given by the user. Let's normalize it
        path = path.strip()
        if not path.startswith("/"):
            path = "/" + path
        wanted_path = self.verify_path(courseid, taskid, path, True)
        if wanted_path is None:
            return self.show_tab_file(courseid, taskid, _("Invalid new path"))

        task_fs = self.task_factory.get_task_fs(courseid, taskid)
        try:
            task_fs.put(wanted_path, fileobj.file.read())
        except:
            return self.show_tab_file(courseid, taskid, _("An error occurred while writing the file"))
        return self.show_tab_file(courseid, taskid) 
開發者ID:UCL-INGI,項目名稱:INGInious,代碼行數:18,代碼來源:task_edit_file.py

示例2: get_sources

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def get_sources(def_file):
    sources = []
    files = []
    visited = set()
    mxnet_path = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
    for line in open(def_file):
        files = files + line.strip().split(' ')

    for f in files:
        f = f.strip()
        if not f or f.endswith('.o:') or f == '\\': continue
        f = os.path.realpath(f)
        fn = os.path.relpath(f)
        if f.startswith(mxnet_path) and fn not in visited:
            sources.append(fn)
            visited.add(fn)
    return sources 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:19,代碼來源:amalgamation.py

示例3: get_problem_hashes

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def get_problem_hashes():
    """
    Function: get_problem_hashes
    Summary: Walking from each problem and return a tuple
            (problem_name, hash_content)
    Returns: list of tuples <problem_name: string, hash_content: string>
    """
    hash_pattern = re.compile("./Problem[0-9]{3}")
    hashes = {}
    for file_tuple in os.walk("."):
        if hash_pattern.match(file_tuple[0]) and ".hash" in file_tuple[-1]:
            problem = file_tuple[0]
            hash_path = path.join(problem, '.hash')
            hash_content = read_hashfile(hash_path)
            hashes[problem.strip('./')] = hash_content

    return hashes 
開發者ID:DestructHub,項目名稱:ProjectEuler,代碼行數:19,代碼來源:stats.py

示例4: which

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def which(program):
        def is_exe(fpath):
            return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

        fpath, fname = os.path.split(program)
        if fpath:
            if is_exe(program):
                return program
        else:
            for path in os.environ["PATH"].split(os.pathsep):
                path = path.strip('"')
                exe_file = os.path.join(path, program)
                if is_exe(exe_file):
                    return exe_file

        return None

    #---------------------------------------------------------------------- 
開發者ID:cytopia,項目名稱:crawlpy,代碼行數:20,代碼來源:crawlpy-login.py

示例5: action_create

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def action_create(self, courseid, taskid, path):
        """ Delete a file or a directory """
        # the path is given by the user. Let's normalize it
        path = path.strip()
        if not path.startswith("/"):
            path = "/" + path

        want_directory = path.endswith("/")

        wanted_path = self.verify_path(courseid, taskid, path, True)
        if wanted_path is None:
            return self.show_tab_file(courseid, taskid, _("Invalid new path"))

        task_fs = self.task_factory.get_task_fs(courseid, taskid)
        if want_directory:
            task_fs.from_subfolder(wanted_path).ensure_exists()
        else:
            task_fs.put(wanted_path, b"")
        return self.show_tab_file(courseid, taskid) 
開發者ID:UCL-INGI,項目名稱:INGInious,代碼行數:21,代碼來源:task_edit_file.py

示例6: action_rename

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def action_rename(self, courseid, taskid, path, new_path):
        """ Delete a file or a directory """
        # normalize
        path = path.strip()
        new_path = new_path.strip()
        if not path.startswith("/"):
            path = "/" + path
        if not new_path.startswith("/"):
            new_path = "/" + new_path

        old_path = self.verify_path(courseid, taskid, path)
        if old_path is None:
            return self.show_tab_file(courseid, taskid, _("Internal error"))

        wanted_path = self.verify_path(courseid, taskid, new_path, True)
        if wanted_path is None:
            return self.show_tab_file(courseid, taskid, _("Invalid new path"))

        try:
            self.task_factory.get_task_fs(courseid, taskid).move(old_path, wanted_path)
            return self.show_tab_file(courseid, taskid)
        except:
            return self.show_tab_file(courseid, taskid, _("An error occurred while moving the files")) 
開發者ID:UCL-INGI,項目名稱:INGInious,代碼行數:25,代碼來源:task_edit_file.py

示例7: action_delete

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def action_delete(self, courseid, taskid, path):
        """ Delete a file or a directory """
        # normalize
        path = path.strip()
        if not path.startswith("/"):
            path = "/" + path

        wanted_path = self.verify_path(courseid, taskid, path)
        if wanted_path is None:
            return self.show_tab_file(courseid, taskid, _("Internal error"))

        # special case: cannot delete current directory of the task
        if "/" == wanted_path:
            return self.show_tab_file(courseid, taskid, _("Internal error"))

        try:
            self.task_factory.get_task_fs(courseid, taskid).delete(wanted_path)
            return self.show_tab_file(courseid, taskid)
        except:
            return self.show_tab_file(courseid, taskid, _("An error occurred while deleting the files")) 
開發者ID:UCL-INGI,項目名稱:INGInious,代碼行數:22,代碼來源:task_edit_file.py

示例8: path_components

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def path_components(path, delimiter=PathDelimiter):
    # type: (str, str) -> collections.Iterable[str]
    p = path.strip()
    pos = 0
    while pos < len(p):
        idx = p.find(delimiter, pos)
        if idx >= 0:
            if idx+1 < len(p):
                if p[idx+1] == delimiter:
                    pos = idx + 2
                    continue
            comp = p[:idx].strip()
            p = p[idx+1:].strip()
            pos = 0
            if len(comp) > 0:
                yield comp.replace(2*delimiter, delimiter)
        else:
            p = strip_path_delimiter(p, delimiter=delimiter)
            if len(p) > 0:
                yield p.replace(2*delimiter, delimiter)
                p = '' 
開發者ID:Keeper-Security,項目名稱:Commander,代碼行數:23,代碼來源:importer.py

示例9: delete_file

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def delete_file(self, path):
        """Delete file at path."""
        path = path.strip('/')
        if not self._pyfilesystem_instance.exists(path):
            raise web.HTTPError(404, u'File or directory does not exist: %s' % path)

        def is_non_empty_dir(os_path):
            if self._pyfilesystem_instance.isdir(path):
                # A directory containing only leftover checkpoints is
                # considered empty.
                cp_dir = getattr(self.checkpoints, 'checkpoint_dir', None)
                if set(self._pyfilesystem_instance.listdir(path)) - {cp_dir}:
                    return True
            return False

        if self._pyfilesystem_instance.isdir(path):
            # Don't permanently delete non-empty directories.
            if is_non_empty_dir(path):
                raise web.HTTPError(400, u'Directory %s not empty' % path)
            self.log.debug("Removing directory %s", path)
            self._pyfilesystem_instance.removetree(path)
        else:
            self.log.debug("Unlinking file %s", path)
            self._pyfilesystem_instance.remove(path) 
開發者ID:jpmorganchase,項目名稱:jupyter-fs,代碼行數:26,代碼來源:fsmanager.py

示例10: rename_file

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def rename_file(self, old_path, new_path):
        """Rename a file."""
        old_path = old_path.strip('/')
        new_path = new_path.strip('/')
        if new_path == old_path:
            return

        # Should we proceed with the move?
        if self._pyfilesystem_instance.exists(new_path):  # TODO and not samefile(old_os_path, new_os_path):
            raise web.HTTPError(409, u'File already exists: %s' % new_path)

        # Move the file
        try:
            self._pyfilesystem_instance.move(old_path, new_path)
        except web.HTTPError:
            raise
        except Exception as e:
            raise web.HTTPError(500, u'Unknown error renaming file: %s %s' % (old_path, e)) 
開發者ID:jpmorganchase,項目名稱:jupyter-fs,代碼行數:20,代碼來源:fsmanager.py

示例11: which

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def which(program):

    """Test if program is pathed."""

    # stackoverflow.com/questions/377017/test-if-executable-exists-in-python

    fpath = os.path.split(program)[0]

    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None 
開發者ID:android-dtf,項目名稱:dtf,代碼行數:21,代碼來源:utils.py

示例12: exe_exist

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def exe_exist(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return True
    else:
        try_paths = []
        is_win = platform.system() == 'Windows'

        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            full_path = os.path.join(path, program)
            try_paths.append(full_path)
            if is_win:
                try_paths.append(full_path + '.exe')

        if any(map(is_exe, try_paths)):
            return True
    return False 
開發者ID:maralla,項目名稱:validator.vim,代碼行數:24,代碼來源:utils.py

示例13: which

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def which(program):
    import os
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return True
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return True

    return "Not found" 
開發者ID:B-UMMI,項目名稱:chewBBACA,代碼行數:19,代碼來源:CreateSchema.py

示例14: which

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def which(program):
    """Tests if the given executable is available in system PATH.

    args:
        program: string
            The executable name.
    """
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None


#=============================================================================== 
開發者ID:SINGROUP,項目名稱:pycp2k,代碼行數:27,代碼來源:setup_manual.py

示例15: which

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import strip [as 別名]
def which(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None 
開發者ID:mrworf,項目名稱:iceshelf,代碼行數:18,代碼來源:configuration.py


注:本文中的os.path.strip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。