Python os.path.rfind() Examples

The following are code examples for showing how to use os.path.rfind(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: jumpscale_portal   Author: jumpscale7   File: elFinder.py    (license) View Source Project 6 votes vote down vote up
def __mimetype(self, path):
		"""Detect mimetype of file"""
		mime = mimetypes.guess_type(path)[0] or 'unknown'
		ext = path[path.rfind('.') + 1:]

		if mime == 'unknown' and ('.' + ext) in mimetypes.types_map:
			mime = mimetypes.types_map['.' + ext]

		if mime == 'text/plain' and ext == 'pl':
			mime = self._mimeType[ext]

		if mime == 'application/vnd.ms-office' and ext == 'doc':
			mime = self._mimeType[ext]

		if mime == 'unknown':
			if os.path.basename(path) in ['README', 'ChangeLog']:
				mime = 'text/plain'
			else:
				if ext in self._mimeType:
					mime = self._mimeType[ext]

		# self.__debug('mime ' + os.path.basename(path), ext + ' ' + mime)
		return mime 
Example 2
Project: myDotFiles   Author: GuidoFe   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path) 
Example 3
Project: SegmentationService   Author: jingchaoluan   File: common.py    (license) View Source Project 5 votes vote down vote up
def pyconstruct(s):
    """Constructs a Python object from a constructor, an expression
    of the form x.y.z.name(args).  This ensures that x.y.z is imported.
    In the future, more forms of syntax may be accepted."""
    env = {}
    if "(" not in s:
        s += "()"
    path = s[:s.find("(")]
    if "." in path:
        module = path[:path.rfind(".")]
        print("import", module)
        exec "import "+module in env
    return eval(s,env) 
Example 4
Project: arch-setup-i3wm   Author: i-PUSH   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path) 
Example 5
Project: paragraph2vec   Author: thunlp   File: sources.py    (license) View Source Project 5 votes vote down vote up
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId) 
Example 6
Project: paragraph2vec   Author: thunlp   File: sources.py    (license) View Source Project 5 votes vote down vote up
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId) 
Example 7
Project: itdepends   Author: zebmason   File: dependencies.py    (license) View Source Project 5 votes vote down vote up
def GetPath(self, path):
		if path in self.tree:
			return self.tree[path]
		i = path.rfind('/')
		if i == -1:
			parent = self.tree['']
			branch = Branch(path, parent)
		else:
			parent = self.GetPath(path[:i])
			branch = Branch(path[i+1:], parent)
		parent.Add(branch)
		self.tree[path] = branch
		return branch 
Example 8
Project: topical_word_embeddings   Author: thunlp   File: sources.py    (license) View Source Project 5 votes vote down vote up
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId) 
Example 9
Project: topical_word_embeddings   Author: thunlp   File: sources.py    (license) View Source Project 5 votes vote down vote up
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId) 
Example 10
Project: topical_word_embeddings   Author: thunlp   File: sources.py    (license) View Source Project 5 votes vote down vote up
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId) 
Example 11
Project: topical_word_embeddings   Author: thunlp   File: sources.py    (license) View Source Project 5 votes vote down vote up
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId) 
Example 12
Project: topical_word_embeddings   Author: thunlp   File: sources.py    (license) View Source Project 5 votes vote down vote up
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId) 
Example 13
Project: dotfiles   Author: maotora   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path) 
Example 14
Project: my-dots   Author: maotora   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path) 
Example 15
Project: anchorhub   Author: samjabrahams   File: test_getanchorhubpath.py    (license) View Source Project 5 votes vote down vote up
def test_get_anchorhub_path_directory():
    """
    getanchorhubpath.py: Make sure directory given is named 'anchorhub'
    """
    path = get_anchorhub_path()
    dir = path[path.rfind(get_path_separator()) + 1:]
    assert dir == 'anchorhub' 
Example 16
Project: dotfiles   Author: leolanavo   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path) 
Example 17
Project: BinarizationService   Author: jingchaoluan   File: common.py    (license) View Source Project 5 votes vote down vote up
def pyconstruct(s):
    """Constructs a Python object from a constructor, an expression
    of the form x.y.z.name(args).  This ensures that x.y.z is imported.
    In the future, more forms of syntax may be accepted."""
    env = {}
    if "(" not in s:
        s += "()"
    path = s[:s.find("(")]
    if "." in path:
        module = path[:path.rfind(".")]
        print("import", module)
        exec "import "+module in env
    return eval(s,env) 
Example 18
Project: deep_ocr   Author: JinpengLI   File: common.py    (license) View Source Project 5 votes vote down vote up
def pyconstruct(s):
    """Constructs a Python object from a constructor, an expression
    of the form x.y.z.name(args).  This ensures that x.y.z is imported.
    In the future, more forms of syntax may be accepted."""
    env = {}
    if "(" not in s:
        s += "()"
    path = s[:s.find("(")]
    if "." in path:
        module = path[:path.rfind(".")]
        print("import", module)
        exec "import "+module in env
    return eval(s,env) 
Example 19
Project: plasma   Author: jnkh   File: data_processing.py    (license) View Source Project 5 votes vote down vote up
def clean_shot_list(self,path):
        data = loadtxt(path)
        ending_idx = path.rfind('.')
        new_path = append_to_filename(path,'_clear')
        if len(shape(data)) < 2:
            #nondisruptive
            nd_times = -1.0*ones_like(data)
            data_two_column = vstack((data,nd_times)).transpose()
            savetxt(new_path,data_two_column,fmt = '%d %f')
            print('created new file: {}'.format(new_path))
            print('deleting old file: {}'.format(path))
            os.remove(path) 
Example 20
Project: plasma   Author: jnkh   File: data_processing.py    (license) View Source Project 5 votes vote down vote up
def append_to_filename(path,to_append):
    ending_idx = path.rfind('.')
    new_path = path[:ending_idx] + to_append + path[ending_idx:]
    return new_path 
Example 21
Project: dotfiles   Author: ildyria   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path) 
Example 22
Project: jumpscale_portal   Author: jumpscale7   File: elFinder.py    (license) View Source Project 4 votes vote down vote up
def __uniqueName(self, path, copy = ' copy'):
		"""Generate unique name for file copied file"""
		curDir = os.path.dirname(path)
		curName = os.path.basename(path)
		lastDot = curName.rfind('.')
		ext = newName = ''

		if not os.path.isdir(path) and re.search(r'\..{3}\.(gz|bz|bz2)$', curName):
			pos = -7
			if curName[-1:] == '2':
				pos -= 1
			ext = curName[pos:]
			oldName = curName[0:pos]
			newName = oldName + copy
		elif os.path.isdir(path) or lastDot <= 0:
			oldName = curName
			newName = oldName + copy
			pass
		else:
			ext = curName[lastDot:]
			oldName = curName[0:lastDot]
			newName = oldName + copy

		pos = 0

		if oldName[-len(copy):] == copy:
			newName = oldName
		elif re.search(r'' + copy +'\s\d+$', oldName):
			pos = oldName.rfind(copy) + len(copy)
			newName = oldName[0:pos]
		else:
			newPath = os.path.join(curDir, newName + ext)
			if not os.path.exists(newPath):
				return newPath

		# if we are here then copy already exists or making copy of copy
		# we will make new indexed copy *black magic*
		idx = 1
		if pos > 0: idx = int(oldName[pos:])
		while True:
			idx += 1
			newNameExt = newName + ' ' + str(idx) + ext
			newPath = os.path.join(curDir, newNameExt)
			if not os.path.exists(newPath):
				return newPath
			# if idx >= 1000: break # possible loop

		return