Example #1
0
def minion_find(args):
    search_filter = args['<text>']
    find_any = False
    if args['find']:
        find_any = True
    match_files = brain.find_files(filter=search_filter, archives=args['--archives'],
                                   find_any=find_any)

    # Set archives if no finds...
    total = brain.get_total_file_count(args['--archives'])

    # Display results / total
    notes_home = brain.get_notes_home()
    match_template = "{matching} of {total} files match search " +\
        "'{search}' in directory {directory}"
    print(match_template.format(
        directory=notes_home,
        matching=len(match_files),
        search=','.join(search_filter),
        total=total))

    # Display results
    # print match_files
    brain.display_output(
        title=None,
        output=match_files,
        raw_files=args['--files'],
    )

    sys.exit(0)
Example #2
0
def minion_find(args):
    search_filter = args['<text>']
    find_any = False
    if args['find']:
        find_any = True
    match_files = brain.find_files(filter=search_filter,
                                   archives=args['--archives'],
                                   find_any=find_any)

    # Set archives if no finds...
    total = brain.get_total_file_count(args['--archives'])

    # Display results / total
    notes_home = brain.get_notes_home()
    match_template = "{matching} of {total} files match search " +\
        "'{search}' in directory {directory}"
    print match_template.format(directory=notes_home,
                                matching=len(match_files),
                                search=','.join(search_filter),
                                total=total)

    # Display results
    # print match_files
    brain.display_output(
        title=None,
        output=match_files,
        raw_files=args['--files'],
    )

    sys.exit(0)
Example #3
0
 def test_list_recent_with_recent_file(self):
     # Arrange
     TestFileStuff.clean_directory()
     recent_file_path, _ = brain.create_new_note(TEST_TOPIC, 'note')
     expected = dict()
     expected[datetime.today().date()] = [recent_file_path]
     # Act
     match_files = brain.find_files(filter=[], days=1)
     actual = brain.list_recent(match_files)
     # Assert
     self.assertEqual(expected, actual)
Example #4
0
 def test_list_recent_with_recent_file(self):
     # Arrange
     TestFileStuff.clean_directory()
     recent_file_path, _ = brain.create_new_note(TEST_TOPIC, 'note')
     expected = dict()
     expected[datetime.today().date()] = [recent_file_path]
     # Act
     match_files = brain.find_files(filter=[], days=1)
     actual = brain.list_recent(match_files)
     # Assert
     self.assertEqual(expected, actual)
Example #5
0
def minion_folders(args):
    updated_files = []
    # match_files = get_match_files(args)
    match_files = brain.find_files()
    # All poorly used folders
    too_few = 5
    notes_home = brain.get_notes_home()
    for folder in os.listdir(brain.get_notes_home()):
        folder = os.path.join(notes_home, folder)
        if os.path.isdir(folder):
            if len(os.listdir(folder)) < too_few:
                items = brain.find_files(filter=folder)
                for item in items:
                    updated_files.append(item)

    match_files = updated_files

    total = len(match_files)
    count = 0
    for item in match_files:
        count += 1
        print(brain.to_bar(count, total))
        _ = brain.doInboxInteractive(item)
Example #6
0
def minion_folders(args):
    updated_files = []
    # match_files = get_match_files(args)
    match_files = brain.find_files()
    # All poorly used folders
    too_few = 5
    notes_home = brain.get_notes_home()
    for folder in os.listdir(brain.get_notes_home()):
        folder = os.path.join(notes_home, folder)
        if os.path.isdir(folder):
            if len(os.listdir(folder)) < too_few:
                items = brain.find_files(filter=folder)
                for item in items:
                    updated_files.append(item)

    match_files = updated_files

    total = len(match_files)
    count = 0
    for item in match_files:
        count += 1
        print brain.to_bar(count, total)
        _ = brain.doInboxInteractive(item)
Example #7
0
    def test_list_recent_with_old_file(self):
        if not sys.platform == 'darwin':
            # Arrange
            TestFileStuff.clean_directory()
            recent_file_path, _ = brain.create_new_note(TEST_TOPIC, 'note')
            old_date = 2014-04-01
            os.utime(recent_file_path, (old_date, old_date))
            expected = dict()

            # Act
            match_files = brain.find_files(filter=[], days=1)
            actual = brain.list_recent(match_files)

            # Assert
            self.assertEqual(expected, actual)
Example #8
0
    def test_list_recent_with_old_file(self):
        if not sys.platform == 'darwin':
            # Arrange
            TestFileStuff.clean_directory()
            recent_file_path, _ = brain.create_new_note(TEST_TOPIC, 'note')
            old_date = 2014 - 04 - 01
            os.utime(recent_file_path, (old_date, old_date))
            expected = dict()

            # Act
            match_files = brain.find_files(filter=[], days=1)
            actual = brain.list_recent(match_files)

            # Assert
            self.assertEqual(expected, actual)
Example #9
0
def minion_tags(args):
    # Rid of this. Concept of 'tags' does not play well with the
    #       filesystem.
    # Switch to simply using any word as a 'tag'.
    # So what is 'poorly tagged'? Too short of a name? Too many common words?

    # A 'tag cloud' would be pretty awesome...
    notes_home = brain.get_notes_home()
    all_files = brain.find_files()
    word_count = dict()
    for filename in all_files:
        filename = filename.replace(notes_home, '')
        filename = filename.replace('/', '-').replace('.', '-')
        words = filename.split('-')
        print(words)
        for word in words:
            if word in word_count:
                word_count[word] += 1
            else:
                word_count[word] = 1
    # word_count.sort()
    print(word_count)
Example #10
0
def minion_tags(args):
    # Rid of this. Concept of 'tags' does not play well with the
    #       filesystem.
    # Switch to simply using any word as a 'tag'.
    # So what is 'poorly tagged'? Too short of a name? Too many common words?

    # A 'tag cloud' would be pretty awesome...
    notes_home = brain.get_notes_home()
    all_files = brain.find_files()
    word_count = dict()
    for filename in all_files:
        filename = filename.replace(notes_home, '')
        filename = filename.replace('/', '-').replace('.', '-')
        words = filename.split('-')
        print words
        for word in words:
            if word in word_count:
                word_count[word] += 1
            else:
                word_count[word] = 1
    # word_count.sort()
    print word_count
Example #11
0
    def test_template_duplicates(self):
        ''' Test that template does not recreate a file
        if a file with the same name alreadye exists. '''

        # Start clean
        TestFileStuff.clean_directory()

        # Create it elsewhere than the inbox.
        params = {
            'topic_fragments': ['testing', 'note', 'template'],
            'note_template': 'note',
            'notes_dir': TEST_DATA_NOT_INBOX,
            'quick': True
        }
        brain.new_note_interactive(**params)

        # Then create another copy, without specifying where.
        params = {
            'topic_fragments': ['testing', 'note', 'template'],
            'note_template': 'note',
            'quick': True
        }
        brain.new_note_interactive(**params)

        dir_contents = os.listdir(TEST_DATA_NOT_INBOX)
        # Inbox exists.
        self.assertEqual(len(dir_contents), 1, '1 in not_inbox')

        # See if we can find more than one.
        params = {
            'filter': ['testing', 'note', 'template'],
        }
        results = brain.find_files(**params)
        self.assertEqual(len(results), 1,
                         'note_template created ' + str(len(results)) +
                         ' files instead of exactly 1.')
Example #12
0
    def test_template_duplicates(self):
        ''' Test that template does not recreate a file
        if a file with the same name alreadye exists. '''

        # Start clean
        TestFileStuff.clean_directory()

        # Create it elsewhere than the inbox.
        params = {
            'topic_fragments': ['testing', 'note', 'template'],
            'note_template': 'note',
            'notes_dir': TEST_DATA_NOT_INBOX,
            'quick': True
        }
        brain.new_note_interactive(**params)

        # Then create another copy, without specifying where.
        params = {
            'topic_fragments': ['testing', 'note', 'template'],
            'note_template': 'note',
            'quick': True
        }
        brain.new_note_interactive(**params)

        dir_contents = os.listdir(TEST_DATA_NOT_INBOX)
        # Inbox exists.
        self.assertEqual(len(dir_contents), 1, '1 in not_inbox')

        # See if we can find more than one.
        params = {
            'filter': ['testing', 'note', 'template'],
        }
        results = brain.find_files(**params)
        self.assertEqual(
            len(results), 1, 'note_template created ' + str(len(results)) +
            ' files instead of exactly 1.')
Example #13
0
def get_match_files(args, days=None):
    matches = brain.find_files(
        filter=args['<text>'],
        archives=args['--archives'],
        days=days)
    return matches
Example #14
0
def get_match_files(args, days=None):
    matches = brain.find_files(filter=args['<text>'],
                               archives=args['--archives'],
                               days=days)
    return matches