def test_gen_filelist(self, mock_environ, mock_path): with patch.dict(local.local_files, {"onefile": "onefile"}, clear=True): mock_path.mkdir_p.return_value = True mock_path.write_text.return_value = True mock_environ["HOME"].return_value = "guda" local.gen_filelist("testingxx") self.assertIn(call('testingxx'), mock_path.mock_calls) self.assertIn(call('guda'), mock_path.mock_calls)
def sync(self): self.local_files = local.gen_filelist(self.notedir) notebooks = self.getNotebooks() if not notebooks: return if not self.checkdir(): logger.error('notedir not exist and failed to mkdir') return self.chdir(config.linote_config.get('linote.notedir')) for notebook in notebooks: subdir = self.getNotebookDir(notebook) notes = self.getNotes(notebook) if not notes: return for note in notes: if self.need_to_sync(note): self.process(note, subdir)
def search_filename(self, keywords): keywords = keywords.strip().lower().split(' ') try: files = pickle.loads(open(self.cachefile).read()) except Exception: files = local.gen_filelist(self.notedir) related = [] for _id in files: fullname = files[_id]['file'] filename = path(fullname).basename().lower()[37:] for keyword in keywords: if keyword not in filename.lower(): is_related = False break if is_related: print _id, fullname related.append((_id, fullname)) return related
def search_filename(self, keywords): keywords = keywords.strip().lower().split(' ') try: files = pickle.loads( open(self.cachefile).read()) except Exception: files = local.gen_filelist(self.notedir) related = [] for _id in files: fullname = files[_id]['file'] filename = path(fullname).basename().lower()[37:] for keyword in keywords: if keyword not in filename.lower(): is_related = False break if is_related: print _id, fullname related.append((_id, fullname)) return related
def search_content(self, keywords): keywords = keywords.strip().lower().split(' ') try: files = pickle.loads(path(self.cachefile).open().read()) except Exception: files = local.gen_filelist() related = [] for _id in files: fullname = files[_id]['file'] try: content = path(fullname).open().read() except: continue is_related = True for keyword in keywords: if keyword not in content: is_related = False break if is_related: print _id, fullname related.append((_id, fullname)) return related
def search_content(self, keywords): keywords = keywords.strip().lower().split(' ') try: files = pickle.loads( path(self.cachefile).open().read()) except Exception: files = local.gen_filelist() related = [] for _id in files: fullname = files[_id]['file'] try: content = path(fullname).open().read() except: continue is_related = True for keyword in keywords: if keyword not in content: is_related = False break if is_related: print _id, fullname related.append((_id, fullname)) return related