|
@@ -40,3 +40,28 @@ def symlink(source, link_name, relative = False, override = False, backup = True
|
|
os.symlink(source, link_name)
|
|
os.symlink(source, link_name)
|
|
else:
|
|
else:
|
|
raise OSError("link's path '%s' already exists." % link_name)
|
|
raise OSError("link's path '%s' already exists." % link_name)
|
|
|
|
+
|
|
|
|
+def update_locate_database():
|
|
|
|
+ import subprocess
|
|
|
|
+ subprocess.call(['sudo', 'updatedb'])
|
|
|
|
+
|
|
|
|
+def locate(patterns, match_all = False, ignore_case = False, update_database = False):
|
|
|
|
+ if update_database:
|
|
|
|
+ update_locate_database()
|
|
|
|
+ if type(patterns) is not list:
|
|
|
|
+ patterns = [str(patterns)]
|
|
|
|
+ patterns = [str(p) for p in patterns]
|
|
|
|
+ options = []
|
|
|
|
+ if match_all:
|
|
|
|
+ options.append("--all")
|
|
|
|
+ if ignore_case:
|
|
|
|
+ options.append("--ignore-case")
|
|
|
|
+ import subprocess
|
|
|
|
+ try:
|
|
|
|
+ output = subprocess.check_output(["locate"] + options + patterns)
|
|
|
|
+ except subprocess.CalledProcessError as e:
|
|
|
|
+ if e.returncode == 1:
|
|
|
|
+ return []
|
|
|
|
+ else:
|
|
|
|
+ raise e
|
|
|
|
+ return output.strip().split('\n')
|