Browse Source

removed definition of osex.update_locate_database and osex.locate

Fabian Peter Hammerle 8 years ago
parent
commit
0a65cf704c
3 changed files with 12 additions and 48 deletions
  1. 0 36
      osex/__init__.py
  2. 3 3
      setup.py
  3. 9 9
      tests/test_locate.py

+ 0 - 36
osex/__init__.py

@@ -40,39 +40,3 @@ def symlink(source, link_name, relative = False, override = False, backup = True
             os.symlink(source, link_name)
         else:
             raise OSError("link's path '%s' already exists." % link_name)
-
-def update_locate_database(root_path = None, database_path = None, require_visibility = None):
-    import subprocess
-    cmd = ['updatedb']
-    if root_path:
-        cmd.append('--database-root')
-        cmd.append(root_path)
-    if database_path:
-        cmd.append('--output')
-        cmd.append(database_path)
-    if require_visibility is not None:
-        cmd.append('--require-visibility')
-        cmd.append('yes' if require_visibility else 'no')
-    subprocess.check_call(cmd)
-
-def locate(patterns, match_all = False, ignore_case = False, database_path = None):
-    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")
-    if database_path:
-        options.append('--database')
-        options.append(database_path)
-    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.decode(sys.getfilesystemencoding()).strip().split('\n')

+ 3 - 3
setup.py

@@ -5,15 +5,15 @@ import glob
 setup(
     name = 'osex',
     packages = ['osex'],
-    version = '0.3.1',
+    version = '0.3.2',
     description = 'extension for python\'s build-in operating system interface',
     author = 'Fabian Peter Hammerle',
     author_email = 'fabian.hammerle@gmail.com',
     url = 'https://github.com/fphammerle/osex',
-    download_url = 'https://github.com/fphammerle/osex/tarball/0.3.1',
+    download_url = 'https://github.com/fphammerle/osex/tarball/0.3.2',
     keywords = [],
     classifiers = [],
     scripts = glob.glob('scripts/*'),
-    install_requires = ['ioex>0.2.1'],
+    install_requires = ['ioex>=0.3'],
     tests_require = ['pytest']
     )

+ 9 - 9
tests/test_locate.py

@@ -2,7 +2,7 @@
 
 import pytest
 
-import osex
+import osex.locate
 
 import os
 
@@ -16,9 +16,9 @@ def test_local_db_files(tmpdir):
     os.makedirs(os.path.join('dir', 'subdir2'))
     # update db
     database_path = os.path.join(test_dir_path, 'db')
-    osex.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
+    osex.locate.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
     # locate
-    results = osex.locate(
+    results = osex.locate.locate(
         [test_dir_path + '*file*'],
         database_path = database_path
         )
@@ -36,9 +36,9 @@ def test_local_db_files_unicode(tmpdir):
     open(u'file-ß', 'w').close()
     # update db
     database_path = os.path.join(test_dir_path, 'db')
-    osex.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
+    osex.locate.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
     # locate
-    results = osex.locate(
+    results = osex.locate.locate(
         [test_dir_path + '*file*'],
         database_path = database_path
         )
@@ -59,9 +59,9 @@ def test_local_db_dirs(tmpdir):
     os.makedirs(os.path.join('dir', 'subdir2'))
     # update db
     database_path = os.path.join(test_dir_path, 'db')
-    osex.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
+    osex.locate.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
     # locate
-    results = osex.locate(
+    results = osex.locate.locate(
         [test_dir_path + '*dir*'],
         database_path = database_path
         )
@@ -81,13 +81,13 @@ def test_local_db_subtree(tmpdir):
     os.makedirs(os.path.join('dir2', 'subdir4'))
     # update db
     database_path = os.path.join(test_dir_path, 'db')
-    osex.update_locate_database(
+    osex.locate.update_locate_database(
             database_path = database_path,
             root_path = os.path.join(test_dir_path, 'dir2'),
             require_visibility = False
             )
     # locate
-    results = osex.locate(
+    results = osex.locate.locate(
         [test_dir_path + '*subdir*'],
         database_path = database_path
         )