text
stringlengths
1
93.6k
epoch_time = stats.st_mtime.__trunc__()
except:
print('Can\'t access: ' + str(path))
epoch_time = 0
dir_list.append(('1', utf_path, '', epoch_time))
for fname in files:
path = os.path.join(root, fname)
utf_path = path.decode(encoding='utf-8', errors='ignore')
try:
stats = os.lstat(path)
size = stats.st_size
epoch_time = stats.st_mtime.__trunc__()
except:
print('Can\'t access: ' + str(path))
size = 0
epoch_time = 0
file_list.append(('0', utf_path, size, epoch_time))
table = dir_list + file_list
new_database(table)
def crawling_drives_lite():
def error(err):
print(err)
root_dir = b'/'
table = []
dir_list = []
file_list = []
if SCANDIR_AVAILABLE:
ror = scandir
else:
ror = os
for root, dirs, files in ror.walk(root_dir, onerror=error):
dirs.sort()
files.sort()
if root == b'/' and b'proc' in dirs:
dirs.remove(b'proc')
dirs[:] = remove_excluded_dirs(dirs, root, PREP_EXCLUDED)
for dname in dirs:
dir_list.append(('1', os.path.join(root, dname).decode(
encoding='UTF-8', errors='ignore')))
for fname in files:
file_list.append(('0', os.path.join(root, fname).decode(
encoding='UTF-8', errors='ignore')))
table = dir_list + file_list
new_database_lite(table)
def remove_excluded_dirs(dirs, root, to_ignore):
after_exclusion = []
for x in dirs:
for z in to_ignore:
if x == z['ign']:
if z['case'] == 1:
if root == z['up']:
break
elif z['case'] == 2:
break
elif z['case'] == 3:
y = [k for k in root.split(b'/') if k]
if y[-1] == z['up']:
break
else:
after_exclusion.append(x)
return after_exclusion
def new_database(table):
temp_db_path = TEMP_PATH + '/angry_database.db'
if os.path.exists(temp_db_path):
os.remove(temp_db_path)
con = sqlite3.connect(temp_db_path, check_same_thread=False)
cur = con.cursor()
if fts5_pragma_check():
cur.execute('''CREATE VIRTUAL TABLE angry_table
USING fts5(directory, path, size, date)''')
cur.execute('''PRAGMA user_version = 4;''')
else:
cur.execute('''CREATE VIRTUAL TABLE angry_table
USING fts4(directory, path, size, date)''')
cur.execute('''PRAGMA user_version = 3;''')
cur.executemany('''INSERT INTO angry_table VALUES (?, ?, ?, ?)''', table)
con.commit()
replace_old_db_with_new()
def new_database_lite(table):