Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter notebook list #64

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions magpie/handler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def _notebooks_list(self, hide_notebooks=False):
return []

return sorted([self.decode_name(nb) for nb in \
listdir(self.settings.repo) if nb != ''])
listdir(self.settings.repo) \
if (nb != '' and path.isdir(path.join(self.settings.repo, nb)) ) ])

def _notes_list(self, notebook_name):
notes_path = path.join(self.settings.repo,
Expand All @@ -47,9 +48,9 @@ def _notes_list(self, notebook_name):
return sorted(starred) + sorted(unstarred)

def highlight(self, text, highlight):
return text.replace(highlight.encode('utf8'),
"<font style=background-color:yellow>%s</font>" % \
highlight.encode('utf8'))
return re.sub( highlight.encode('utf8'),
lambda m: "<font style=background-color:yellow>" + m.group() \
+ "</font>", text, flags=re.IGNORECASE)

def get_current_user(self):
if self.settings.username is None and self.settings.pwdhash is None \
Expand Down
26 changes: 15 additions & 11 deletions magpie/handler/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,35 @@ def get(self):
if query == '':
self.redirect('/')
try:
results = str(grep('-R', '--exclude-dir', '.git', query,
results = str(grep('-Rli', '--exclude-dir', '.git', query,
self.settings.repo))
except ErrorReturnCode_1 as e:
results = ''

try:
results += str(find(self.settings.repo, '-type', 'f', '-name',
results += str(find(self.settings.repo, '-type', 'f', '-iname',
'*' + query + '*', '-not', '(', '-path',
'%s/%s/*' % (self.settings.repo, '.git') ))
'%s/%s/*' % (self.settings.repo, '.git'), ')'))
except ErrorReturnCode_1 as e:
pass

results = results.replace(self.settings.repo, '').split('\n')[:-1]
formatted_results = []
for result in results:
if 'Binary file' in result or result == '':
for filename in results:
if 'Binary file' in filename or filename == '':
continue

# TODO this doesn't play well with colons in filenames
stuff = result.split(':')
filename = stuff[0]
if path.basename(filename).startswith('.'):
filename = path.join(path.dirname(filename),
path.basename(filename)[1:])
string = ''.join(stuff[1:])
string = self.highlight(string, query)
formatted_results.append({'filename': filename, 'string': string})

resultpath = path.join(self.settings.repo, filename[1:])
if path.exists(resultpath):
try:
string = str(grep('-i', query, resultpath ))
except ErrorReturnCode_1 as e:
string = ''

string = self.highlight(string, query)
formatted_results.append({'filename': filename, 'string': string})
self.render('search.html', query=query, results=formatted_results)
4 changes: 0 additions & 4 deletions todo.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
## To Do
### ``magpie/handler/search.py``
(line 35) this doesn't play well with colons in filenames


### ``utils/email_notes.py``
(line 43) there seems to be a bug where other notes in other notebooks can be deleted

Expand Down