def search(query): print '''I\'m a little confused. Please enter a choice 1 : Search for file by its name 2 : Search for files which contain a keyword ''' try: choice = int(raw_input('>> ')) if(choice == 1): filename = support.get_file_name(query) if(filename): os.system('locate -b \'\\'+filename+'\'') else: print 'not able to get the filename' elif(choice == 2): keyword = raw_input('Enter keyword : ') print '''By default I\'ll start searching from HOME directory.\ But this usually takes time. 1 : Search from HOME directory 2 : Search from current directory ''' location = int(raw_input('>> ')) if(location == 1): os.system('grep -i -n -r \''+keyword+'\' '+os.path.expanduser('~')) elif(location == 2): os.system('grep -i -n -r \''+keyword+'\' '+os.path.abspath(os.curdir)) else: print 'Invalid input' else: print 'Invalid input' return except: print 'Something went wrong. Most likely its an input error. Please try again'
def make_executable(query): """make_executable(query) -- give executable permissions to a given file """ filename = support.get_file_name(query) if(os.path.isfile(filename)): os.system('chmod +x '+filename) else: print 'file not found'
def lines(query): """lines(query) -- print the number of lines in a given file """ filename = support.get_file_name(query) if(os.path.isfile(filename)): with open(filename) as openfile: print len(openfile.readlines()) else: print 'File not found : ' + filename
def file_info(query): """file_info(query) -- print some human readable information of a given file """ filename = support.get_file_name(query) if(os.path.isfile(filename)): stat_info = os.stat(filename) owner_name = pwd.getpwuid(stat_info.st_uid).pw_name print 'owner : ' + owner_name file_size = support.get_readable_filesize(stat_info.st_size) print 'size : ' + file_size print 'created : ' + time.ctime(stat_info.st_ctime) print 'last modified : ' + time.ctime(stat_info.st_mtime) else: print 'file not found'
def search_new(query): print '''I\'m a little confused. Please enter a choice 1 : Search for file by its name 2 : Search for files which contain a keyword ''' try: choice = int(raw_input('>> ')) if(choice == 1): filename = support.get_file_name(query) if(filename): os.system('locate -b \'\\'+filename+'\'') else: print 'not able to get the filename' elif(choice == 2): keyword = raw_input('Enter keyword : ') if(len(keyword) > 0): os.system('grep -i -n -r \''+keyword+'\' '+os.path.abspath(os.curdir)) else: print 'Invalid input' else: print 'Invalid input' return except: print 'Something went wrong. Most likely its an input error. Please try again'