- 论坛徽章:
- 0
|
搜索程序是我自己寫的
我不知道是我的程序問題或系統問題
在Ubuntu中安裝Wine後搜索文件時發現卡死就是永遠回圈
件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/Program Files (x86)/iTunes/iTunes.Resources/pt_PT.lproj/DevicePrefsMovies.nib/objects.xib
/home/jack/.wine/drive_c/users/jack/我的文件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/Program Files (x86)/iTunes/iTunes.Resources/pt_PT.lproj/DevicePrefsMovies.nib
/home/jack/.wine/drive_c/users/jack/我的文件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/users/jack/我的文件/.wine/drive_c/Program Files (x86)/iTunes/iTunes.Resources/pt_PT.lproj/Localizable.strings
我也發現由根目錄開始搜索也有這個問題
/home/jack/python2/Backup.py
/home/jack/Backup.py
/proc/self/task/4994/root/home/jack/python2/Backup.py
/proc/self/task/4994/root/home/jack/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/home/jack/python2/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/home/jack/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/home/jack/python2/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/home/jack/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/home/jack/python2/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/home/jack/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/home/jack/python2/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/home/jack/Backup.py
/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/proc/self/task/4994/root/home/jack- #!/usr/bin/python3.2
- import os
- import sys
- import fnmatch
- import time
- import math
- fcount = dcount = 0
- maxdepth = 0
- result = [ ]
- class Search(object):
- def __init__(self, path, names, args=[]):
- # Check if defalut arg not in args will extend in args
-
- self.path = path
- self.names = names
- self.args = args
-
- def _match_return(self, patterns):
- def __match_return(path, files):
- result = [ ]
- for pattern in patterns:
- result.extend(fnmatch.filter(files, pattern))
- return result
- return __match_return
-
- def search(self):
- global fcount, dcount, search_result
- find_d = find_f = ignore = False
- files = os.listdir(self.path)
- file_list = files
- if 'i' in self.args or '--ignore' in self.args:
- ignore = True
- self.names = [n.upper( ) for n in self.names]
- files = [f.upper( ) for f in files]
- searchname = self._match_return(self.names)
- filenames = searchname(self.path, files)
-
- for file in file_list:
- srcname = os.path.join(self.path, file)
-
- if 'c' in self.args or '--count' in self.args:
- if os.path.isdir(srcname):
- dcount += 1
- else:
- fcount +=1
- tcount = time.clock( )
-
- # Dicition whether subdir if True into subdir
- if os.path.isdir(srcname):
- Search(srcname, self.names, self.args).search( )
- if ignore:
- file = file.upper( )
-
- if 'v' in self.args or '--verbose' in self.args:
- self._tryprint(srcname)
- if 'd' in self.args or '--dir' in self.args:
- find_d = True
- if file in filenames and os.path.isdir(srcname):
- result.append(srcname)
-
- if 'f' in self.args or '--file' in self.args:
- find_f = True
- if file in filenames and os.path.isfile(srcname):
- result.append(srcname)
- '''
- if 'm' in self.args or '--maxdepth' in self.args:
- depth = args.index()
- '''
- if file in filenames and find_f is not True and find_d is not True:
- result.append(srcname)
- print(srcname)
- def _tryprint(self, arg):
- try:
- print(arg)
- except UnicodeEncodeError:
- print(arg.encode('utf-16'))
-
- def _size(self, bytes):
- lst = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB']
- if bytes == 0:
- return ('0.00' + ' ' + lst[0])
- i = int(math.log(bytes, 1024))
- return ('%.2f' + ' ' + lst[i]) % (bytes / 1024 ** i)
-
- if __name__ == '__main__':
- #start = time.clock( )
- #s = Search('/home', ['PYTHON', 'Backup.py', 'GUI.py', 'BIND.py', 'dir.py'], ['--ignore'])
- s = Search('/', ['Backup.py'])
- s.search( )
- #print('Finish at: %s' % str(time.clock( ) - start))
- print('-'*25, 'Result', '-'*25)
- for r in result:
- print(r)
- #Search(path='/home/jack', names='python', args='s')
复制代码 |
|