Python os.path.rfind() Examples

The following are code examples for showing how to use os.path.rfind(). 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: fiasko_bro   Author: devmanorg   File: url_helpers.py    MIT License 5 votes vote down vote up
def get_filename_from_path(path):
    return path[path.rfind(os.path.sep) + 1:] 
Example 2
Project: arch-setup-i3wm   Author: i-PUSH   File: commands_full.py    GNU General Public License v3.0 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: symstore   Author: elmirjagudin   File: util.py    MIT License 5 votes vote down vote up
def _file_part(path):
    sep_pos = path.rfind("/")
    if sep_pos == -1:
        sep_pos = path.rfind("\\")

    if sep_pos == -1:
        return path

    return path[sep_pos+1:] 
Example 4
Project: itdepends   Author: zebmason   File: dependencies.py    GNU Lesser General Public License v2.1 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 5
Project: topical_word_embeddings   Author: thunlp   File: sources.py    MIT License 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: topical_word_embeddings   Author: thunlp   File: sources.py    MIT License 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: topical_word_embeddings   Author: thunlp   File: sources.py    MIT License 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 8
Project: topical_word_embeddings   Author: thunlp   File: sources.py    MIT License 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    MIT License 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: dmind   Author: siouka   File: CFileLoader.py    GNU General Public License v2.0 4 votes vote down vote up
def loadFTP(self,URL,localfile='',timeout=0,proxy="CACHING",content_type= '',retries=0):
        self.state=0 #success      
        
        #Parse URL according RFC 1738: ftp://user:[email protected]:port/path 
        #There is no standard Python funcion to split these URL's.
        username=''
        password=''        
        port=21
        
        #check for username, password
        index=URL.find('@')
        if index != -1:
            index2=URL.find(':',6,index)
            if index2 != -1:
                username=URL[6:index2]
                print 'user: '+username
                password=URL[index2+1:index]
                print 'password: '+password            
            URL=URL[index+1:]
        else:
            URL=URL[6:]
        
        #check for host
        index=URL.find('/')
        if index != -1:
            host=URL[:index]
            path=URL[index:]
        else:
            host=URL
            path=''
        
        #retrieve the port
        index=host.find(':')
        if index != -1:
            port=int(host[index+1:])
            host=host[:index]
            
        print 'host: '+host    
        print 'port: '+str(port)
        
        #split path and file
        index=path.rfind('/')
        if index != -1:
            file=path[index+1:]
            path=path[:index]
        else:
            file=''        
        
        print 'path: '+path
        print 'file: '+file
        
        try:
            self.f=ftplib.FTP()
            self.f.connect(host,port)
        except (socket.error, socket.gaierror),e:
            print 'ERROR: cannot reach "%s"'%host
            self.state= -1 #failed to download the file
            return