From b28ef80161dd9e17ad9c83b6fdd9cc1aef041e91 Mon Sep 17 00:00:00 2001 From: sunny Date: Fri, 6 Sep 2013 00:57:39 +0530 Subject: [PATCH] Removing build --- build/lib.linux-i686-2.7/clsearch/__init__.py | 0 build/lib.linux-i686-2.7/clsearch/base.py | 133 ---------- build/lib.linux-i686-2.7/clsearch/index.py | 248 ------------------ build/lib.linux-i686-2.7/clsearch/search.py | 145 ---------- .../clsearch/test/test_base.py | 57 ---- .../clsearch/test/test_index.py | 92 ------- .../clsearch/test/test_search.py | 37 --- build/scripts-2.7/clsearch | 74 ------ 8 files changed, 786 deletions(-) delete mode 100644 build/lib.linux-i686-2.7/clsearch/__init__.py delete mode 100644 build/lib.linux-i686-2.7/clsearch/base.py delete mode 100644 build/lib.linux-i686-2.7/clsearch/index.py delete mode 100644 build/lib.linux-i686-2.7/clsearch/search.py delete mode 100644 build/lib.linux-i686-2.7/clsearch/test/test_base.py delete mode 100644 build/lib.linux-i686-2.7/clsearch/test/test_index.py delete mode 100644 build/lib.linux-i686-2.7/clsearch/test/test_search.py delete mode 100755 build/scripts-2.7/clsearch diff --git a/build/lib.linux-i686-2.7/clsearch/__init__.py b/build/lib.linux-i686-2.7/clsearch/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/build/lib.linux-i686-2.7/clsearch/base.py b/build/lib.linux-i686-2.7/clsearch/base.py deleted file mode 100644 index 62957b7..0000000 --- a/build/lib.linux-i686-2.7/clsearch/base.py +++ /dev/null @@ -1,133 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import division -import os -import sqlite3 -import re -import sys - -class Base(object): - """ - Provides helper functions to both Index and Search - """ - def __init__(self, dbPrefix = None, fout = sys.stdout): - """ - Creates the sqlite database if not already present. - Input: - dbPrefix: The directory where the database will be created. - Defaults to ~/.clsearch. - fout: Write all output to this stream. Defaults to stdout - - *Schema: - -Media: - +path: the absolute path to the file - +format: extensions. Makes for faster search by type. - - -Words: - +word: unicode string - +df: document frequency. Incremented for each occurence - of the word. Used as IDF in TF-IDF - - -Tags: - +tag: tag name. Either id3 or xmp. - - -Frequency: - +wordid: Foreign key to the Words table - +mediaid: Foreign key to the Media table - +tagid: Foreign key to the Tags table - +frequency: term frequency(TF). normalized frequency of word - in the string being indexed. Calculated as: - number of occurences of word in string / - length of string - - Note: - String can be file name or tag values - tagid is 0 for words appearing in file name. - """ - if dbPrefix: - dbPrefix = os.path.abspath(dbPrefix) - else: - dbPrefix = os.path.expanduser("~") - - dbPrefix = os.path.join(dbPrefix, '.clsearch') - - db = os.path.join(dbPrefix, 'clsdb.sqlite') - isFirst = False - if not os.path.exists(db): - if not os.path.exists(dbPrefix): - os.mkdir(dbPrefix) - isFirst = True - - self.fout = fout - - self.conn = sqlite3.connect(db) - self.cur = self.conn.cursor() - - if isFirst: - self.__create_db() - - def __del__(self): - if hasattr(self, "conn"): - self.conn.commit() - self.conn.close() - - def __create_db(self): - self.cur.execute("create table Media (path string, format string)") - self.cur.execute("create table Words (word string,\ - df int default 1 not null)") - self.cur.execute("create table Tags (tag string)") - self.cur.execute("create table Frequency (wordid int,\ - mediaid int, tagid int, frequency float)") - self.conn.commit() - - def get_split_string(self): - """ - Splitting on [\W_]+ causes loss of characters because re - in 2.x considers combining forms in unicode to be non-alphanumeric - - Eg: 1. In [34]: re.split(ur"[\W_]+", 'Sigur Rós') - Out[34]: ['Sigur', 'R', 's'] - - 2. In [42]: split_string = i.get_split_string() - - In [43]: re.split(split_string, 'Sigur Rós') - Out[43]: ['Sigur', 'R\xc3\xb3s'] - - Although this solution is crude, it should work in most of the - cases. - - Builds and returns a string consisting of all non-alphanumeric - characters from ASCII 0 to 126 - """ - split_string = ur'' - for i in range(0, 48): - split_string += chr(i) - for i in range(58, 65): - split_string += chr(i) - for i in range(91, 97): - split_string += chr(i) - for i in range(123, 127): - split_string += chr(i) - - split_string = re.escape(split_string) - return "[" + split_string + "]+" - - def to_unicode(self, str_): - """ - The standard unicode function was not - sufficient because of the odd file encoded in - latin-1 - - Takes a and returns a - by trying to decode it using utf-8 or latin-1 - """ - try: - str_ = str_.decode("utf-8") - except UnicodeDecodeError: - try: - str_ = str_.decode("latin-1") - except UnicodeDecodeError: - str_ = str_.decode("utf-8", errors = "ignore") - except UnicodeEncodeError: - str_ = str_.decode("utf-8", errors = "replace") - return str_ - diff --git a/build/lib.linux-i686-2.7/clsearch/index.py b/build/lib.linux-i686-2.7/clsearch/index.py deleted file mode 100644 index 0c917d2..0000000 --- a/build/lib.linux-i686-2.7/clsearch/index.py +++ /dev/null @@ -1,248 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import division -import os -import sys -import re -import time -from clsearch.base import Base - -class Index(Base): - """ - - Inherits and extends Base - - Walks through specified directory. ~ by default - - Populates database - - Extracts metadata tags - """ - def __init__(self, quiet = False, fileTypes = [], dbPrefix = None, fout = sys.stdout): - """ - - Checks if xmp libraries are present - - Calls Base parent class constructor with - dbPrefix and fout input options - - Input: - quiet: Don't display blow-by-blow details of indexing. - False by default. - fileTypes: Additional types to be searched and indexing - along with mp3, aac, ogg, avi, mkv and mp4 - dbPrefix: Argument to parent constructor. Specificies the - directory where the sqlite database will be created. - ~ by default. - fout: Argument to parent constructor. Specified stream to which - all output will be written to. - """ - - try: - import libxmp as lx - self.xmp_file_to_dict = lx.utils.file_to_dict - self.isXMP = True - except Exception, e: - fout.write("XMP error: %s, xmp tags will not be indexed.\n"%e) - self.isXMP = False - self.quiet = quiet - self.fileTypes = ["mp3", "aac", "ogg", "avi", "mkv", "mp4"] + fileTypes - self.counter = 0 - def index(self, dirName = None): - """ - - The function called by the script to index files. - - Uses os.path.walk to recurse through the directory structure. - - If a file has any of the given filetypes at the end, - call add_to_index() with that filename. - - Measure time taken for the walk function to return, - including time to index files. - - Print summary of indexing: - number of files read from the counter class attribute. - - Reset index counter to 0. - - Input: - dirName: The directory given as input to - os.path.walk. ~ by default. - """ - - if dirName: - dirName = os.path.abspath(dirName) - dirName = 1 and dirName or os.path.expanduser("~") - - def crawl(args, dName, fNames): - if not self.quiet: - self.fout.write("Searching %s\n"%dName) - for fName in fNames: - if os.path.splitext(fName)[1][1:].strip().lower() in self.fileTypes: - self.add_to_index(os.path.join(dName, fName)) - - if self.quiet: - self.fout.write("Indexing...\n") - start_time = time.time() - os.path.walk(dirName, crawl, None) - self.conn.commit() - end_time = time.time() - self.__printSummary(end_time - start_time) - self.counter = 0 - - - def add_to_index(self, path): - """ - - Add a given file to the database. - - Convert filename to unicode string. - - If file is already in database, return False. - - If not, add filename to Media table. - - Add words in filename to Words table. - - Get id3 and xmp tags. - - Add tag keys to Tags table. - - Add words in tag values to Words table. - - Input: - path: file to be added - """ - path = self.to_unicode(path) - #FIXME: This splitting is being done twice because of the unicode dilemma - name, format_ = os.path.splitext(os.path.split(path)[1]) - - media_id, created = self.__get_or_create("Media", path = path, format = format_.strip().lower()) - if not created: - return False - else: - self.counter += 1 - if not self.quiet: - self.fout.write("Indexing %s\n"%path) - self.__add_string(name, media_id, 0) - tags = {} - if self.isXMP: - tags.update(self.get_xmp_tags(path)) - tags.update(self.get_id3_tags(path)) - for tag, value in tags.items(): - tag_id, created = self.__get_or_create("Tags", tag = tag) - self.__add_string(value, media_id, tag_id) - return True - - def __add_string(self, string, media_id, tag_id): - """ - - Called by add_to_index - - Adds to Words and Frequency tables - - Uses get_split_string to split into words - - Updates document frequency(DF) of word - """ - words = filter(lambda x: x.strip(),\ - map(lambda x: x.lower(),\ - #FIXME: re.UNICODE causes weird problems with the new split string - re.split(self.get_split_string(), string))) - wRows = [self.__get_or_create("Words", word = word) for word in words] - for i, w in enumerate(wRows): - if not w[1]: - self.cur.execute("update Words set df = df + 1 where word = ?",[words[i]]) - self.cur.execute("insert into Frequency values (?, ?, ?, ?)",\ - [w[0], media_id, tag_id, words.count(words[i]) / len(words)]) - #FIXME: The loop is not entered if wRows is empty..so no worry about zero division? - - - def __get_or_create(self, tableName, **colVals): - """ - A limited imitation of django's similar ORM function - """ - if not colVals: - raise Exception("No column values specified") - - query = "select rowid from %s where "%tableName - query += " and ".join(["%s='%s'"%(k,v.replace("'", "''")) for k, v in colVals.items()]) - self.cur.execute(query) - row = self.cur.fetchone() - if row: - return (row[0], False) - - query = "insert into %s values (%s"%(tableName,\ - ",".join(["'%s'"%col.replace("'", "''") for col in colVals.values()])) - #FIXME: Hack - query += tableName == "Words" and ",1)" or ")" - self.cur.execute(query) - return (self.cur.lastrowid, True) - - def __printSummary(self, numSeconds): - """ - - Print number of indexed files in number of seconds - - Called even in quiet mode - """ - self.fout.write("-" * 42 + "\n") - if self.counter == 0: - self.fout.write("\nNo new media files\n\n") - else: - self.fout.write("\nIndexed %d new files in %d seconds\n\n"%(self.counter, numSeconds)) - self.fout.write("-" * 42) - - def get_id3_tags(self, fileName): - """ - Code taken from 'Dive Into Python' and genre list lookup has been added - - Input: - fileName: get tags for this file - """ - def stripnulls(data): - return self.to_unicode(data.replace("\00", "").strip().lower()) - - tags = {} - tagDataMap = { "title": ( 3, 33, stripnulls), - "artist" : ( 33, 63, stripnulls), - "album": ( 63, 93, stripnulls), - "year": ( 93, 97, stripnulls), - "comment" : ( 97, 126, stripnulls), - "genre": (127, 128, lambda x: self.to_unicode(genre_list[ord(x) % 149])) - } - - genre_list = ['blues', 'classic rock', 'country', 'dance', 'disco', 'funk', - 'grunge', 'hip-hop', 'jazz', 'metal', 'new age', 'oldies', 'other', 'pop', - 'r&b', 'rap', 'reggae', 'rock', 'techno', 'industrial', 'alternative', - 'ska', 'death metal', 'pranks', 'soundtrack', 'euro-techno', 'ambient', - 'trip-hop', 'vocal', 'jazz+funk', 'fusion', 'trance', 'classical', - 'instrumental', 'acid', 'house', 'game', 'sound clip', 'gospel', - 'noise', 'alternrock', 'bass', 'soul', 'punk', 'space', 'meditative', - 'instrumental pop', 'instrumental rock', 'ethnic', 'gothic', 'darkwave', - 'techno-industrial', 'electronic', 'pop-folk', 'eurodance', 'dream', - 'southern rock', 'comedy', 'cult', 'gangsta rap', 'top 40', 'christian rap', - 'pop / funk', 'jungle', 'native american', 'cabaret', 'new wave', - 'psychedelic', 'rave', 'showtunes', 'trailer', 'lo-fi', 'tribal', 'acid punk', - 'acid jazz', 'polka', 'retro', 'musical', 'rock & roll', 'hard rock', 'folk', - 'folk-rock', 'national folk', 'swing', 'fast fusion', 'bebob', 'latin', - 'revival', 'celtic', 'bluegrass', 'avantgarde', 'gothic rock', - 'progressive rock', 'psychedelic rock', 'symphonic rock', 'slow rock', - 'big band', 'chorus', 'easy listening', 'acoustic', 'humour', 'speech', - 'chanson', 'opera', 'chamber music', 'sonata', 'symphony', 'booty bass', - 'primus', 'porn groove', 'satire', 'slow jam', 'club', 'tango', 'samba', - 'folklore', 'ballad', 'power ballad', 'rhythmic soul', 'freestyle', - 'duet', 'punk rock', 'drum solo', 'a cappella', 'euro-house', 'dance hall', - 'goa', 'drum & bass', 'club-house', 'hardcore', 'terror', 'indie', 'britpop', - 'negerpunk', 'polsk punk', 'beat', 'christian gangsta rap', 'heavy metal', - 'black metal', 'crossover', 'contemporary christian', 'christian rock', - 'merengue', 'salsa', 'thrash metal', 'anime', 'jpop', 'synthpop', 'rock/pop'] - - try: - if not os.path.isfile(os.path.abspath(fileName)): - fileName = fileName.encode('latin-1') - with open(fileName, 'rb') as f: - f.seek(-128, 2) - tagData = f.read(128) - if tagData[:3] == "TAG": - for tag, (start, end, parseMethod) in tagDataMap.items(): - tags[tag] = parseMethod(tagData[start : end]) - - except Exception, e: - if not self.quiet: - self.fout.write("Skipping %s because of error: %s\n"%(fileName, e)) - return tags - - def get_xmp_tags(self, fileName): - """ - Input: - fileName: get tags for this file - """ - tags = {} - try: - #FIXME: Hack for a failing part of the code in utls.py of libxml - if not os.path.isfile(os.path.abspath(fileName)): - fileName = fileName.encode('latin-1') - nSpaces = self.xmp_file_to_dict(file_path = fileName) - for ns in nSpaces.values(): - for prop in ns: - tags[prop[0].split(":")[1].lower().strip()] = prop[1].lower().strip() - - except Exception, e: - if not self.quiet: - self.fout.write("Skipping %s because of error: %s\n"%(fileName, e)) - return tags diff --git a/build/lib.linux-i686-2.7/clsearch/search.py b/build/lib.linux-i686-2.7/clsearch/search.py deleted file mode 100644 index 525ba4f..0000000 --- a/build/lib.linux-i686-2.7/clsearch/search.py +++ /dev/null @@ -1,145 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import division -import re -import sys -from clsearch.base import Base - -class Search(Base): - """ - - Inherits and extends Base - - Search a given query, first by type - and then in name and tags - - Print output under different sections - """ - def __init__(self, dbPrefix = None, fout = sys.stdout): - """ - - Calls Base parent class constructor with - dbPrefix and fout input options - - Input: - dbPrefix: Argument to parent constructor. Specificies the - directory where the sqlite database will be created. - ~ by default. - fout: Argument to parent constructor. Specified stream to which - all output will be written to. - """ - super(Search, self).__init__(dbPrefix, fout) - - def search(self, query): - """ - - First performs search by format - - If any word begins with a ".", it is considered - and extension type and searched. - - normalize_query is then called to get individual - terms - - A dictionary is built with hit paths as keys - - For each path, TF-IDF score is calculated as the sum - of the TF and 1/DF of each term of the query - which is a part of the path, either in name or tag. - - tagSet is a set of all tagids for each path - - __print_results function looks up tagids and substitues - appropriate tag names - - If 0 is part of tagSet, it is a direct hit - - Input: - query who terms should be searched - """ - results = {} - noFormatResults = True - for word in query.split(): - word = word.strip().lower() - if word[0] == ".": - if self.search_by_format(word): - noFormatResults = False - - for word in self.normalize_query(query): - word = self.to_unicode(word) - self.cur.execute("select m.path, f.frequency, w.df, f.tagid from\ - Media m, Frequency F, Words W where\ - m.rowid = f.mediaid and f.wordid = w.rowid and word = ?", [word]) - - for row in self.cur.fetchall(): - path, idf, tag_id = row[0], row[1] * (1 / row[2]), row[3] - cur, tagSet = results.get(path, [0, set()]) - tagSet.add(tag_id) - results[path] = [cur + idf, tagSet] - - self.__print_results(results, noFormatResults) - - def __print_results(self, results, noFormatResults): - """ - Split results into two lists based on - 0 being present in tagSet. - - 0 was used to indicate words appearing in - the name of a file - """ - if not results: - if noFormatResults: - self.fout.write("0 results found. Make sure you have indexed the files.\n") - return - - self.cur.execute("select tag from Tags") - tagNames = self.cur.fetchall() - - dResults = [] - tResults = [] - - for result in sorted([(k, v) for k, v in results.items()], - key = lambda x: x[1][0], reverse = True): - tagSet = result[1][1] - if 0 in tagSet: - tagSet.remove(0) - dResults.append(result) - else: - tResults.append(result) - - self.fout.write("\nDirect Results(in name):\n\n") - - for result in dResults: - self.fout.write(result[0]) - self.fout.write("\n") - if result[1][1]: - self.fout.write("Also in tags: %s"\ - % (",".join([tagNames[tag - 1][0] for tag in result[1][1]]))) - - print "\nTag Results:\n" - - for result in tResults: - self.fout.write(result[0]) - self.fout.write("\n") - self.fout.write("In tags: %s"\ - % ",".join([tagNames[tag - 1][0] for tag in result[1][1]])) - - - def normalize_query(self, query): - """ - - Returns list of individual terms in query - - Uses the same split string as the index function. - - Input: - query - """ - return [word.strip().lower() for word in\ - re.split(self.get_split_string(), query) if word] - - def search_by_format(self, format_): - """ - Search and print immediately by looking-up - format column in Words - - Returns True if there was atleast one hit, used to - account in the final hit score. - - Input: - format - """ - self.cur.execute("select path from Media where format = ?", [format_]) - results = [file_[0] for file_ in self.cur.fetchall() if file_] - if results: - self.fout.write("\nFiletype Results:\n\n") - for file_ in results: - self.fout.write(file_) - self.fout.write("\n") - return True - return False diff --git a/build/lib.linux-i686-2.7/clsearch/test/test_base.py b/build/lib.linux-i686-2.7/clsearch/test/test_base.py deleted file mode 100644 index 6a30ebc..0000000 --- a/build/lib.linux-i686-2.7/clsearch/test/test_base.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -import unittest -import sys -import os -import re -sys.path.insert(0, os.path.abspath("../..")) -from clsearch.base import Base - -class BaseTests(unittest.TestCase): - def setUp(self): - self.b = Base() - self.dbPath = ".clsearch/clsdb.sqlite" - - def test_db_creation(self): - self.assertRaises(OSError, Base, "/usr") - Base(".") - self.assertTrue(os.path.exists(self.dbPath)) - - def test_db_deletion(self): - os.remove(self.dbPath) - self.assertFalse(os.path.exists(self.dbPath)) - - Base(".") - self.assertTrue(os.path.exists(self.dbPath)) - - os.remove(self.dbPath) - os.rmdir(".clsearch") - self.assertFalse(os.path.exists(self.dbPath)) - - Base(".") - self.assertTrue(os.path.exists(self.dbPath)) - - os.remove(self.dbPath) - os.rmdir(".clsearch") - self.assertFalse(os.path.exists(self.dbPath)) - - def test_to_unicode(self): - testStrings = ["", "hello!~", "\x01\x92"] - for str_ in testStrings: - str_ = self.b.to_unicode(str_) - self.assertEqual(type(str_), unicode) - - self.assertRaises(AttributeError, self.b.to_unicode, 123.123) - - def test_get_split_string(self): - testStrings = { - u'uni\u0C80code ,,,, string': [u'uni\u0C80code', u'string'], - 'Sigur! Rós': ['Sigur', 'Rós'], - 'Sigur Rós!': ['Sigur', 'Rós', ''], - } - - for k, v in testStrings.items(): - self.assertEqual(re.split(self.b.get_split_string(), k), v) - - -if __name__ == "__main__": - unittest.main() diff --git a/build/lib.linux-i686-2.7/clsearch/test/test_index.py b/build/lib.linux-i686-2.7/clsearch/test/test_index.py deleted file mode 100644 index e52f0b7..0000000 --- a/build/lib.linux-i686-2.7/clsearch/test/test_index.py +++ /dev/null @@ -1,92 +0,0 @@ -# -*- coding: utf-8 -*- -import unittest -import sys -import os -import re -sys.path.insert(0, os.path.abspath("../..")) -from test_base import BaseTests -from clsearch.index import Index -import cStringIO - -class IndexTests(BaseTests): - def setUp(self): - BaseTests.setUp(self) - self.out = cStringIO.StringIO() - self.i = Index(quiet = True, dbPrefix = ".", fileTypes = ['jpg'], fout = self.out) - - def test_db_exists(self): - self.assertTrue(os.path.exists(self.dbPath)) - - def test_file_types(self): - self.assertTrue("jpg" in self.i.fileTypes) - - def test_add_to_index_quiet(self): - files = os.listdir("data/") - self.i.index(".") - output = self.out.getvalue() - - self.assertTrue("Indexing..." in output) - - for file_ in files: - self.assertFalse(file_ in output) - - self.assertTrue("Indexed %d new files"%len(files) in output) - - def test_add_to_index(self): - self.i = Index(dbPrefix = ".", fileTypes = ['jpg'], fout = self.out) - files = os.listdir("data/") - self.i.index(".") - output = self.out.getvalue() - - self.assertFalse("Indexing..." in output) - - for file_ in files: - self.assertTrue(file_ in output) - - self.assertTrue("Indexed %d new files"%len(files) in output) - - def test_db_entries(self): - self.test_add_to_index_quiet() - files = map(lambda x: os.path.join(os.path.abspath('data'), x), os.listdir("data/")) - self.i.cur.execute("select * from Media") - vals = self.i.cur.fetchall() - self.assertTrue(vals) - - self.assertEqual(len(vals), len(files)) - - for val in vals: - self.assertTrue(val[0] in files) - - def test_get_id3_tags(self): - test_dict = {'album': u'duet', - 'comment': u'', - 'title': u'how insensitive', - 'artist': u'chick corea & hiromi', - 'year': u'2008', 'genre': u'other'} - - self.assertEqual(self.i.get_id3_tags("data/02 How Insensitive.mp3"), test_dict) - - - def test_get_xmp_tags(self): - if self.i.isXMP: - test_dict = {u'album': u'duet', - u'artist': u'chick corea & hiromi', - u'createdate': u'2008', - u'title[1]': u'how insensitive', - u'tracknumber': u'2', - u'genre': u'jazz', - u'title': u'', - u'discnumber': u'1', - u'title[1]/?xml': u'x-default'} - self.assertEqual(self.i.get_xmp_tags("data/02 How Insensitive.mp3"), test_dict) - else: - pass - - def tearDown(self): - if os.path.exists(self.dbPath): - os.remove(self.dbPath) - os.rmdir(".clsearch") - self.out.close() - -if __name__ == "__main__": - unittest.main() diff --git a/build/lib.linux-i686-2.7/clsearch/test/test_search.py b/build/lib.linux-i686-2.7/clsearch/test/test_search.py deleted file mode 100644 index c84a9a0..0000000 --- a/build/lib.linux-i686-2.7/clsearch/test/test_search.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -import unittest -import sys -import os -import re -sys.path.insert(0, os.path.abspath("../..")) -from test_base import BaseTests -from test_index import IndexTests -from clsearch.search import Search -import cStringIO - -class SearchTests(IndexTests): - def setUp(self): - IndexTests.setUp(self) - self.s = Search(dbPrefix = ".", fout = self.out) - - def test_search_by_type(self): - files = map(lambda x: os.path.join(os.path.abspath('data'), x), os.listdir("data/")) - jpgfiles = [] - for file_ in files: - if re.search("jpg$", file_): - jpgfiles.append(file_) - self.test_add_to_index_quiet() - self.s.search(".jpg") - output = self.out.getvalue() - output = output[output.find("Filetype Results:"):] - for file_ in jpgfiles: - self.assertTrue(file_ in output) - - def test_search_no_results(self): - self.test_add_to_index() - self.s.search("should~not!##be__there") - output = self.out.getvalue() - self.assertTrue("0 results" in output) - -if __name__ == "__main__": - unittest.main() diff --git a/build/scripts-2.7/clsearch b/build/scripts-2.7/clsearch deleted file mode 100755 index 714e998..0000000 --- a/build/scripts-2.7/clsearch +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/python2.7 - -#FIXME: Even though deprecated, use this to work with <2.7 -from optparse import OptionParser -usage = """ - %prog -i|--index [-d|--dir ] [-t|--types ] [-q|--quiet] - %prog -s|--search - %prog -h|--help - - Examples: - %prog -i - %prog -i -d /home/example/Music/Awesome/ - %prog -i -t flv,txt - %prog -i -t "flv txt jpg" - - %prog -s lazarus - %prog -s "rock and roll" - - Note: - 1. For xmp tags to be indexed, python-xmp-toolkit and it's dependency Exempy 2.1.1 have to be installed. 2. The indexing operation can be performed any number of times. Only new files are indexed each time. -""" -parser = OptionParser(usage = usage, version = "%prog 0.1") - -parser.add_option("-i", "--index", - dest="index", - action = "store_true", - help="Index filename and id3 and xmp tags if present. Searches for new files and indexes them.") - -parser.add_option("-d", "--dir", - dest="directory", - help="The directory to be searched for files. Defaults to '~' if not specified.") - -parser.add_option("-t", "--types", - dest="types", - help="Additional file types to index. By default mp3,aac,ogg,avi,mkv,mp4 files are indexed.") - -parser.add_option("-s", "--search", dest="query", - help="Search and return file paths ranked by TF-IDF.") - -parser.add_option("-q", "--quiet", - dest="quiet", - default=False, - action = "store_true", - help="Don't print indexed files to stdout.") - -(options, args) = parser.parse_args() - -try: - if not options.index and not options.query: - parser.print_help() - - if options.index and options.query: - parser.error("Index and search cannot be done together") - - if not options.index and (options.types or options.directory): - parser.error("-i not specified") - - if options.index: - import re - if options.types: - types = filter(lambda x: x, 1 and re.split(ur"[, ]+", options.types)) - else: - types = [] - from clsearch.index import Index - i = Index(options.quiet, types) - i.index(options.directory) - - elif options.query: - from clsearch.search import Search - s = Search() - s.search(options.query) - -except Exception, e: - print e