Git Product home page Git Product logo

filetags's Introduction

filetags

bin/screencast.gif

… filetags example demonstrating: controlled vocabulary file ~/.filetags, tagging multiple files at once, removing tags by prepending a minus character, tagging using the proposed number shortcuts, tab completion of tags via Tab, and mutually exclusive tags (switching from draft to final without removing draft).

This Python script adds or removes tags to file names in the following form:

  • “file without time stamp in name -​- tag2.txt”
  • “file name with several tags -​- tag1 tag2.jpeg”
  • “another example file name with multiple example tags -​- fun videos kids.mpeg”
  • “2013-05-09 a file name with ISO date stamp in name -​- tag1.jpg”
  • “2013-05-09T16.17 file name with time stamp -​- tag3.csv”

The script accepts an arbitrary number of files (see your shell for possible length limitations).

https://imgs.xkcd.com/comics/trained_a_neural_net.png (Source: xkcd)

Why

Besides the fact that I am using ISO dates and times in file names (as shown in examples above), I am using tags with file names. To separate tags from the file name, I am using the separator “space dash dash space”.

For people familiar with Regular Expressions:

(<ISO date/time stamp>)?(?<descriptive file name>)?( -- <list of tags separated by spaces>)?.<file extension>

Tagging files this way requires a file renaming process. Adding (or removing) tag(s) to a set of file results in multiple renaming processes. Despite advanced renaming tools like vidir (from moreutils) it’s handy to have a tool that makes adding and removing tags as simple as possible.

You may like to add this tool to your image or file manager of choice. I added mine to geeqie which is my favorite image viewer on GNU/Linux.

Here is a 45 minute talk I gave at Linuxtage Graz 2018 presenting the idea of and workflows related to filetags and other handy tools for file management:

bin/2018-05-06 filetags demo slide for video preview with video button -- screenshots.png

Installation

This tool needs Python 3 to be installed.

You can install filetags either via pip which is the recommended way. Or you can install filetags using the source code, e.g., by cloning the GitHub repository of filetags.

Installation Via Pip

If you have installed Python 2 and Python 3 in parallel, make sure to use the correct pip version. You might need to use pip3 instead of pip. If you only have Python 3 installed, you don’t have to care ;-)

On Microsoft Windows (only), you are going to need pip install pypiwin32 as prerequisite. For easy Windows File Explorer integration, take a look at integratethis.

Now install filetags via pip: pip install filetags

You get updates by executing the very same pip command again.

Installation Via Source Code

If you use the GitHub sources (and not pip):

  • You need to install depending packages via: pip install -r requirements.txt
  • The executable is filetags/__init__.py. You might want to create a symbolic link named “filetags” to that file.

Usage

usage: ./filetags/__init__.py [-h] [-t "STRING WITH TAGS"] [--remove] [-i]
                              [-R] [-s] [--hardlinks] [-f]
                              [--filebrowser PATH_TO_FILEBROWSER] [--tagtrees]
                              [--tagtrees-handle-no-tag "treeroot" | "ignore" | "FOLDERNAME"]
                              [--tagtrees-link-missing-mutual-tagged-items]
                              [--tagtrees-dir <existing_directory>]
                              [--tagtrees-depth TAGTREES_DEPTH] [--ln] [--la]
                              [--lu] [--tag-gardening] [-v] [-q] [--version]
                              [FILE [FILE ...]]

This tool adds or removes simple tags to/from file names.

Tags within file names are placed between the actual file name and
the file extension, separated with " -- ". Multiple tags are
separated with " ":
  Update for the Boss -- projectA presentation.pptx
  2013-05-16T15.31.42 Error message -- screenshot projectB.png

This easy to use tag system has a drawback: for tagging a larger
set of files with the same tag, you have to rename each file
separately. With this tool, this only requires one step.

Example usages:
  filetags --tags="presentation projectA" *.pptx
      … adds the tags "presentation" and "projectA" to all PPTX-files
  filetags --tags="presentation -projectA" *.pptx
      … adds the tag "presentation" to and removes tag "projectA" from all PPTX-files
  filetags -i *
      … ask for tag(s) and add them to all files in current folder
  filetags -r draft *report*
      … removes the tag "draft" from all files containing the word "report"

This tools is looking for the optional first text file named ".filetags" in
current and parent directories. Each of its lines is interpreted as a tag
for tag completion. Multiple tags per line are considered mutual exclusive.

Verbose description: http://Karl-Voit.at/managing-digital-photographs/

positional arguments:
  FILE                  One or more files to tag

optional arguments:
  -h, --help            show this help message and exit
  -t "STRING WITH TAGS", --tags "STRING WITH TAGS"
                        One or more tags (in quotes, separated by spaces) to
                        add/remove
  --remove              Remove tags from (instead of adding to) file name(s)
  -i, --interactive     Interactive mode: ask for (a)dding or (r)emoving and
                        name of tag(s)
  -R, --recursive       Recursively go through the current directory and all
                        of its subdirectories. Implemented for --tag-gardening
                        and --tagtrees
  -s, --dryrun          Enable dryrun mode: just simulate what would happen,
                        do not modify files
  --hardlinks           Use hard links instead of symbolic links. This is
                        ignored on Windows systems. Note that renaming link
                        originals when tagging does not work with hardlinks.
  -f, --filter          Ask for list of tags and generate links in
                        "$HOME/.filetags_tagfilter" containing links to all
                        files with matching tags and start the filebrowser.
                        Target directory can be overridden by --tagtrees-dir.
  --filebrowser PATH_TO_FILEBROWSER
                        Use this option to override the tool to view/manage
                        files (for --filter; default: geeqie). Use "none" to
                        omit the default one.
  --tagtrees            This generates nested directories in
                        "$HOME/.filetags_tagfilter" for each combination of
                        tags up to a limit of 2. Target directory can be
                        overridden by --tagtrees-dir. Please note that this
                        may take long since it relates exponentially to the
                        number of tags involved. Can be combined with
                        --filter. See also http://Karl-Voit.at/tagstore/ and
                        http://Karl-Voit.at/tagstore/downloads/Voit2012b.pdf
  --tagtrees-handle-no-tag "treeroot" | "ignore" | "FOLDERNAME"
                        When tagtrees are created, this parameter defines how
                        to handle items that got no tag at all. The value
                        "treeroot" is the default behavior: items without a
                        tag are linked to the tagtrees root. The value
                        "ignore" will not link any non-tagged items at all.
                        Any other value is interpreted as a folder name within
                        the tagreees which is used to link all non-tagged
                        items to.
  --tagtrees-link-missing-mutual-tagged-items
                        When the controlled vocabulary holds mutual exclusive
                        tags (multiple tags in one line) this option generates
                        directories in the tagtrees root that hold links to
                        items that have no single tag from those mutual
                        exclusive sets. For example, when "draft final" is
                        defined in the vocabulary, all items without "draft"
                        and "final" are linked to the "no-draft-final"
                        directory.
  --tagtrees-dir <existing_directory>
                        When tagtrees are created, this parameter overrides
                        the default target directory
                        "$HOME/.filetags_tagfilter" with a user-defined
                        one. It has to be an empty directory or a non-existing
                        directory which will be created. This also overrides
                        the default directory for --filter.
  --tagtrees-depth TAGTREES_DEPTH
                        When tagtrees are created, this parameter defines the
                        level of depth of the tagtree hierarchy. The default
                        value is 2. Please note that increasing the depth
                        increases the number of links exponentially.
                        Especially when running Windows (using lnk-files
                        instead of symbolic links) the performance is really
                        slow. Choose wisely.
  --ln, --list-tags-by-number
                        List all file-tags sorted by their number of use
  --la, --list-tags-by-alphabet
                        List all file-tags sorted by their name
  --lu, --list-tags-unknown-to-vocabulary
                        List all file-tags which are found in file names but
                        are not part of .filetags
  --tag-gardening       This is for getting an overview on tags that might
                        require to be renamed (typos, singular/plural, ...).
                        See also http://www.webology.org/2008/v5n3/a58.html
  -v, --verbose         Enable verbose mode
  -q, --quiet           Enable quiet mode
  --version             Display version and exit

:copyright: (c) by Karl Voit <[email protected]>
:license: GPL v3 or any later version
:URL: https://github.com/novoid/filetags
:bugreports: via github or <[email protected]>
:version: 2018-08-02
·

Examples:

filetags --tags foo a_file_name.txt

… adds tag “foo” such that it results in a_file_name -- foo.txt

filetags -i *.jpeg

… interactive mode: asking for list of tags (for the JPEG files) from the user

filetags --tags "foo bar" "file name 1.jpg" "file name 2 -- foo.txt" "file name 3 -- bar.csv"

… adds tag “foo” such that it results in …

"file name 1 -- foo bar.jpg"
"file name 2 -- foo bar.txt"
"file name 3 -- bar foo.csv"
filetags --remove --tags foo "foo a_file_name -- foo.txt"

… removes tag “foo” such that it results in foo a_file_name.txt

filetags --tag-gardening

… prints out a summary of tags in current and sub-folders used and tags that are most likely typos or abandoned

For --filter and --tagtrees examples see sections below.

Independent to tags you might define on the fly, the optional file .filetags stores a controlled vocabulary of recurrent tags; adjust this content to your needs. In an interactive session, this set is available to tag any file in the folder .filetags resides (click tab key) and propagates into folders of lower hierachy.

Changelog

  • 2013-05-16: first version on GitHub
  • 2014-12-21: --list-tags-by-number, --list-tags-by-alphabet, and --tag-gardening
  • 2015-01-02: tab completion for interactive tag input
    • Example: entering myt + pressing TAB completes the entered string to mytag if mytag is found in the vocabulary or existing file tags
  • 2015-12-11: shortcut numbers for removing tags
  • 2016-01-08: shortcut numbers for top nine tags for adding tags
    • Example: when filetags shows you Top nine previously used tags in this directory: with mytag(1) anothertag(2) oncemore(3), you don’t have to type in the tag names but use the numbers instead. Combinations of numbers are fine as well.
  • 2016-08-21: mutually exclusive tags: see chapter below
  • 2016-08-23: installable via pip install filetags
  • 2016-08-26: --filter option requires all tags to be matching
  • 2016-10-15: added tag gardening: vocabulary tags not used + tags not in vocabulary
  • 2016-10-16: interactively adding tags: omit already assigned tags in shortcuts and vocabulary
  • 2016-11-27: added existing shared tags to visual tags
  • 2017-02-06: better help text for --filter option
  • 2017-02-25: shortcut tags can be mixed with non-shortcut tags
    • Example: mytag 49 anothertag does add tags mytag and anothertag and the shortcut tags 4 and 9
  • 2017-04-09:
    • interactively removing tags via -tagname:
      • Example: the tag input tagname -removeme adds the tag tagname and removes the tag removeme from the filename(s)
    • try to find alternative filename if file not found
      • Example: if you try to tag file My file name.pdf which is not found, filetags tries to look for a different (unique and existing) filename that shares the same start of the file name such as My file name -- mytag.pdf. Very handy!
      • This happens a lof when you are interactively adding multiple tags one by one by simply re-executing the previous command line: the file name changes in between because of the previous tag(s) being added.
  • 2017-08-27: when tagging symbolic links whose source file has a matching file name, the source file gets the same tags as the symbolic link of it
    • This is especially useful when using the --filter option
  • 2017-08-28:
    • moved from optparse to argparse
    • removed option --tag (in favor to --tags)
    • added option shortcut for recursive: -R
    • renamed option --imageviewer to --filebrowser and enabled its functionality
    • added new feature --tagtrees
  • 2017-08-31:
    • improved screen output when renaming files
  • 2017-09-03:
    • --recursive option now works for linking files to tagtrees as well
    • corresponding .filetags files get linked to the output of tagtrees as well
  • 2017-11-11:
    • removed command line options -r, -d, and --delete
      • keeping --remove as the only option for removing tags
      • removing tags was overrepresented in the command line options, blocking them to be used for other useful commands
    • added --tagtrees-handle-no-tag "treeroot" | "ignore" | "FOLDERNAME"
    • added --tagtrees-link-missing-mutual-tagged-items
  • 2017-12-30:
    • added --tagtrees-dir <existing_directory>
      • overriding the default target directory for the tagtrees result
    • added --tagtrees-depth TAGTREES_DEPTH
      • allowing to override the default depth of tagtrees
      • use with care: especially on Windows a larger depth than 2 takes very long
    • tagtrees now work with Windows using lnk files
      • in contrast to symbolic links, that have rather poor performance though: generation of tagtrees take way longer than on Linux or macOS
  • 2018-01-30:
    • fixed the pip3 package
  • 2018-03-18:
    • added more detailed statistics on usage of tag groups when doing tag gardening
    • added internal data structure cache_of_files_with_metadata
  • 2018-04-05:
    • --tagtrees-dir can now be used for --filter
    • much deeper support for Windows .lnk files:
      • tagging lnk files within tagtrees also tag their original files
      • .filetags files can now be .lnk files as well
      • the unit tests now work on Windows and test some Windows specialities
  • 2018-04-18:
    • comments in .filetags files that contain the controlled vocabulary
  • 2018-04-25:
  • 2018-07-23: --tagtrees= can now be filtered with --filter
  • 2018-08-02: added option --hardlinks as an alternative for non-Windows systems
  • 2019-12-22: added manual file globbing for Windows because of #25
  • 2021-04-03: added support for #donotsuggest lines within .filetags files to omit tags from being proposed

Get the most out of filetags: controlled vocabulary .filetags

This awesome tool is providing support for controlled vocabularies. When invoked for interactive tagging, it is looking for files named .filetags in the current working directory and its parent directories as well. The first file of this name found is read in. Each line represents one tag. Those tags are used for tag completion.

This is purely great: with tags within .filetags you don’t have to enter the tags entrirely: just type the first characters and press TAB (twice to show you all possibilities). You will be amazed how efficiently you are going to tag things! :-)

Of course, you can remove existing tags by prepending a - character to the tag: -tagname. This also works interactively using the tab completion feature.

You can use comments in .filetags files: everything after a # character is considered a comment. You can even add a comment after a tag like ”mytag # this is a test tag”.

If you do use tags you do not want to get proposed for tagging, you can write them in lines like the following ones to omit their proposal (case insensitive):

#donotsuggest omit-this-tag dontshow
#donotsuggest wontpropose

Mutually exclusive tags

If you enter multiple tags in the same line in .filetags, they are interpreted as mutually exclusive tags. For example, if your .filetags contains the line winter spring summer autumn, filetags replaces any season-tag with the new one. So if you tag the file …

example file -- summer anothertag.txt

… with the tag winter, it gets renamed to …

example file -- winter anothertag.txt

… without having to manually remove the tag summer.

Common mutually exclusive tags are draft final or confidential internal public.

Filter

Consider you have a directory that contains hundreds of files.

If you want to retrieve a file whose tags you know, you can skim through all the files. However, filetags offers you a more elegant possibility: you can filter the files according to one or more tags.

For example, we take a look at following situation:

$HOME/my party/
|_ 2018-06-25 Party invitation -- scan correspondence.pdf
|_ 2018-07-31 Guest list -- correspondence.txt
|_ 2018-08-01T11.51.44 Uncle Bob arrives.jpg
|_ 2018-08-01T12.31.42 Sheila with her new boyfriend -- friends.jpg
|_ 2018-08-01T14.12.23 Start of BBQ with the big steak.jpg
|_ ...
|_ 2018-08-01T23.53.19 Even uncle Bob desides to go home -- fun.jpg
|_ 2018-08-05 Lessons learned for planning a party -- scan.pdf
|_ 2018-08-06 Thank-you letter Bob -- scan.pdf
|_ Bills/
  |_ 2018-07-30 Beverages by FreshYouUp -- scan taxes.pdf
  |_ 2018-08-03 Bill of the butcher -- scan taxes.pdf

Following command and interaction would generate following temporal link structure:

filetags --filter

User gets asked to enter one or more tags and she enters “scan”. What now happens is that filetags creates a directory whose content consists of links to all matching files from your query. By default, the resulting directory is .filetags_tagfilter in your home directory. After invoking for our example, the content of this retrieval directory looks like that:

$HOME/.filetags_tagfilter/
|_ 2018-06-25 Party invitation -- scan correspondence.pdf
|_ 2018-08-05 Lessons learned for planning a party -- scan.pdf
|_ 2018-08-06 Thank-you letter Bob -- scan.pdf

This way, our user is quickly able to skim through all scanned documents to locate the one desired to retrieve.

To locate all matching files in all sub-directories as well, the user is able to add the parameter --recursive

filetags --filter --recursive

… and chooses to enter the tag “scan” which would generate following temporal link structure:

$HOME/.filetags_tagfilter/
|_ 2018-06-25 Party invitation -- scan correspondence.pdf
|_ 2018-08-05 Lessons learned for planning a party -- scan.pdf
|_ 2018-08-06 Thank-you letter Bob -- scan.pdf
|_ 2018-07-30 Beverages by FreshYouUp -- scan taxes.pdf
|_ 2018-08-03 Bill of the butcher -- scan taxes.pdf

TagTrees

This functions is somewhat sophisticated as it is not a very well-known thing to have. If you’re really interested in the whole story behind the visualization/navigation of tags using TagTrees, feel free to read my PhD thesis about it on the tagstore webpage. It is surely a piece of work I am proud of and the general chapters of it are written so that the average person is perfectly well able to follow.

In short: this function takes the files of the current directory and generates hierarchies up to level of $maxdepth (by default 2, can be overridden via --tagtrees-depth) of all combinations of tags, linking all files according to their tags.

Too complicated? Then let’s explain it with some examples.

Consider having a file like:

My new car -- car hardware expensive.jpg

Now you generate the TagTrees, you’ll find links to this file within sub-directories of ~/.filetags, the default target directory: car/ and hardware/ and expensive/ and car/hardware/ and car/expensive/ and hardware/car/ and so on. You get the idea.

The default target directory can be overridden via --tagtrees-dir.

Therefore, within the folder new/expensive/ you will find all files that have at least the tags “new” and “expensive” in any order. This is really cool to have.

Files of the current directory that don’t have any tag at all, are linked directly to ~/.filetags so that you can find and tag them easily.

I personally, do use this feature within my image viewer of choice (geeqie). I mapped it to Alt-T because Alt-t is occupied by filetags for tagging of course. So when I am within my image viewer and I press Alt-T, TagTrees of the currently shown images are created. Then an additional image viewer window opens up for me, showing the resulting TagTrees. This way, I can quickly navigate through the tag combinations to easily interactively filter according to tags.

Please note: when you are tagging linked files within the TagTrees with filetags, only the current link gets updated with the new name. All other links to this modified filename within the other directories of the TagTrees gets broken. You have to re-create the TagTrees to update all the links after tagging files.

The option --tagtrees-handle-no-tag controls how files with no tags should be handled. When set to treeroot, untagged files are linked in the TagTrees target directory directly. The option ignore does not link them at all. The option FOLDERNAME links them to a directory named accordingly to the value which is a sub-directory of the TagTrees target directory.

With the option --tagtrees-link-missing-mutual-tagged-items you can control, whether or not there will be an additional TagTrees folder that contains all files which lack one of the mutually exclusive tags. Using the example winter spring summer autumn from above, all files that got none of those four tags get linked to a TagTrees directory named “no_winter_spring_summer_autumn”. This way, you can easily find and tag files that don’t participate in this set of mutually exclusive tags.

Using the example files from above:

$HOME/my party/
|_ 2018-06-25 Party invitation -- scan correspondence.pdf
|_ 2018-07-31 Guest list -- correspondence.txt
|_ 2018-08-01T11.51.44 Uncle Bob arrives.jpg
|_ 2018-08-01T12.31.42 Sheila with her new boyfriend -- friends.jpg
|_ 2018-08-01T14.12.23 Start of BBQ with the big steak.jpg
|_ ...
|_ 2018-08-01T23.53.19 Even uncle Bob desides to go home -- fun.jpg
|_ 2018-08-05 Lessons learned for planning a party -- scan.pdf
|_ 2018-08-06 Thank-you letter Bob -- scan.pdf
|_ Bills/
  |_ 2018-07-30 Beverages by FreshYouUp -- scan taxes.pdf
  |_ 2018-08-03 Bill of the butcher -- scan taxes.pdf

… and the command line …

filetags --tagtrees --tagtrees-handle-no-tag "has_no_tag" --tagtrees-depth 2 --recursive

… filetags generates the temporal link structure:

$HOME/.filetags_tagfilter/
|_ scan/
  |_ 2018-06-25 Party invitation -- scan correspondence.pdf
  |_ 2018-08-05 Lessons learned for planning a party -- scan.pdf
  |_ 2018-08-06 Thank-you letter Bob -- scan.pdf
  |_ 2018-07-30 Beverages by FreshYouUp -- scan taxes.pdf
  |_ 2018-08-03 Bill of the butcher -- scan taxes.pdf
  |_ correspondence/
    |_ 2018-06-25 Party invitation -- scan correspondence.pdf
  |_ taxes/
    |_ 2018-07-30 Beverages by FreshYouUp -- scan taxes.pdf
    |_ 2018-08-03 Bill of the butcher -- scan taxes.pdf
|_ correspondence/
  |_ 2018-06-25 Party invitation -- scan correspondence.pdf
  |_ 2018-07-31 Guest list -- correspondence.txt
  |_ scan/
    |_ 2018-06-25 Party invitation -- scan correspondence.pdf
|_ friends/
  |_ 2018-08-01T12.31.42 Sheila with her new boyfriend -- friends.jpg
|_ fun/
  |_ 2018-08-01T23.53.19 Even uncle Bob desides to go home -- fun.jpg
|_ taxes/
  |_ 2018-07-30 Beverages by FreshYouUp -- scan taxes.pdf
  |_ 2018-08-03 Bill of the butcher -- scan taxes.pdf
  |_ scan/
    |_ 2018-07-30 Beverages by FreshYouUp -- scan taxes.pdf
    |_ 2018-08-03 Bill of the butcher -- scan taxes.pdf
|_ has_no_tag/
  |_ 2018-08-01T11.51.44 Uncle Bob arrives.jpg
  |_ 2018-08-01T14.12.23 Start of BBQ with the big steak.jpg
  |_ ...

This looks complicated because there are many links generated the user does not really need. The beauty of this solution is that the user is able to navigate to a file using a wide set of different paths (the TagTrees) and she is able to choose the one path that suits the current cognitive model.

For example, she might want to retrieve “the one document from the last party which she remembers of having scanned and which she used for the invitation correspondence”. With this mind-set, she most likely retrieves the document via $HOME/.filetags_tagfilter/scan/correspondence/ or $HOME/.filetags_tagfilter/correspondence/scan/ (does not matter which).

The large number of other TagTrees can be ignored for this retrieval task.

Another retrieval task example would be “all photos that do have no tag in order to continue tagging the photos”. In this example, the user visits $HOME/.filetags_tagfilter/has_no_tag/, fires her image viewer (which has filetags integrated already - see below) and continues with the tagging activity. Since filetags synchronizes the tags within TagTrees linked files and the original files, the original files get renamed accordingly.

Bonus: Using tags to specify a sub-set of photographs

You know the problem: got back from Paris and you can not show 937 image files to your friends. It’s just too much.

My solution: I tag to define selections. For example, I am using sel (“selection”) for the ultimate cool photographs using filetags, of course.

Within geeqie, which is my preferred image viewer, I redefined F to call filetags with its --filter parameter. Now I get asked to enter one or more tags to filter the current folder. For presenting only the files that were tagged with sel, I enter sel and confirm with Enter.

This creates a temporary folder with symbolic links to all photographs of the current folder that contain the tag sel and it starts a new (additional) instance of geeqie.

In short: after returning from a trip, I mark all “cool” photographs within geeqie, choose t and tag them with sel (described in previous section). For showing only sel images, I just press F, enter sel and instead of 937 photographs, my friends just have to watch the best 50 or so. :-)

Watch this 45 minute talk on how I am using this (and other) features.

Integration Into Common Tools

If your system has Python 3 installed, you can start using filetags right away in any command line environment.

However, users do want to integrate tools like filetags also in various GUI tools.

The Integration.org file explains integration in some tools that allow external commands being added:

  • geeqie, a GNU/Linux image viewer I am using
  • Thunar is a popular GNU/Linux file browser for the xfce environment
  • GNOME Nautilus file manager
  • Windows Explorer
  • FreeCommander, my recommendated alternative to Windows explorer
  • Dired, the GNU/Emacs file manager

If you have integrated filetags in additional commonly used tools, please send me a short how-to so that others are able to get the most out of filetags as well.

Related Tools and Workflows

This tool is part of a tool-set which I use to manage my digital files such as photographs. My work-flows are described in this blog posting you might like to read and in the video which is linked above.

In short:

For tagging, please refer to filetags and its documentation.

See date2name for easily adding ISO time-stamps or date-stamps to files.

For easily naming and tagging files within file browsers that allow integration of external tools, see appendfilename (once more) and filetags.

Moving to the archive folders is done using move2archive.

Having tagged photographs gives you many advantages. For example, I automatically choose my desktop background image according to the current season.

Files containing an ISO time/date-stamp gets indexed by the filename-module of Memacs.


How to Thank Me

I’m glad you like my tools. If you want to support me:

  • Send old-fashioned postcard per snailmail - I love personal feedback!
  • Send feature wishes or improvements as an issue on GitHub
  • Create issues on GitHub for bugs
  • Contribute merge requests for bug fixes
  • Check out my other cool projects on GitHub

Exhaustive List of All Features

This section is an exhaustive list of features of filetags. You might skip this when you’re a first-time user in order not to get irritated for simple use-cases only.

This section is particularily helpful for re-implementing filetags functionality and for power-users which are interested in the advanced functions provided by this tool.

General

BeforeWhenAfterNote
Some file name.jpegtagging with fooSome file name -- foo.jpegTag separator is added automatically
Some file nametagging with fooSome file name -- fooThere is no need for a file extension
Some file name -- foo.jpegtagging with barSome file name -- foo bar.jpegbar becomes last tag
Some file name.jpeg.lnktagging with barSome file name -- bar.jpeg.lnkThe .lnk extension is taken into account
Some file name -- bar.jpeguntagging barSome file name.jpegTag separator is removed
Some file name -- foo bar.jpeguntagging fooSome file name -- bar.jpegTag order stays same when removing
  • filetags may be used
    1. interactively (via --interactive or missing “action” command line parameters) from command line or
    2. in a script using command line parameters.
  • filetags offers a --dryrun option which does not modify any file or directory.
  • Added tag(s) get appended as last tag(s).
  • When removing tags, their relative order is preserved.
  • When modifying any file that is a symbolic link or a Windows .LNK file to a file that has the same basename (file name without path), the linked/original file gets modified as well.
    • This comes very handy when working within TagTrees (see below).
    • However, when modifying links which do not share the same base-name with its link source, the link might become a broken one (depending on the link technology used).
  • When un-tagging tags from files that do not have those tags, it is silently ignored.
  • [ ] FIXXME: describe find_unique_alternative_to_file(filename) and implications
  • FUTURE: support for tagging folders/directories · Issue #13 · novoid/filetags · GitHub
  • FUTURE: Files within tagged directories do inherit the tags for all relevant features · Issue #14 · novoid/f…
    • Inheritance applies to many features such as “don’t tag a file with a tag from any parent directory” and so forth.
    • Not that simple to decide each use-case. This is a hard nut to crack with many complex things to take care of.
  • FUTURE: CV: add CLI option that prevents users from using tags that are not part of the used .filetags file …
    • Enforcing CVs is a good practice IMHO.

Interactive Mode

  • Print used tags of selected file(s).
    • For multiple files, show only the tags that are used within all selected files.
  • filetags dialog shows up to nine topmost used tags (sorted by number of usage) used for files within the current directory.
    • E.g., draft(1) projectX(2) customer(3) bill(4)
    • You can use 0-9 as shortcuts to select those tags.
      • You can concatenate shortcut numbers without spaces in-between: 143 foo tags with the shortcuts number 1, 3 and 4 and adds new tag foo.
        • With the example above, it is equivalent to tagging with: draft bill customer foo or draft 4 3 foo.
  • You can un-tag tags that appear in file name using the minus prefix.
    • E.g., -foo un-tags the tag foo.
    • Auto-completion is provided to un-tag existing tags.
  • Tags from the CV (within .filetags files) and from tags used in the current directory can be auto-completed via TAB.
    • Already used tags are not available for completion.
  • Multiple Files
    • You can tag/un-tag multiple selected files at once.
      • Selected files containing the tag(s) to tag are not modified and no tags get duplicated.
      • Selected files not containing the tag(s) to un-tag are not modified.
    • Tag suggestions for un-tagging contain the common tags of selected files.
  • Tagging dialog can be aborted any time via Ctrl-c.

Controlled Vocabulary (CV)

Please read this first in order to understand CVs.

  • CV is read from .filetags files.
    • One tag per line: simple tag
    • Multiple tags per line, separated via spaces: a group of mutually exclusive tags
      • E.g., draft final approved
        • When tagging My report -- draft.txt with final, draft gets replaced by final without the user un-tagging it before.
        • filetags does not prevent user from manually tagging files with two or more mutually exclusive tags.
    • The order of priority to locate “matching” .filetags files is:
      1. Current directory of the first file to tag/un-tag.
      2. Any higher-level directory from the current directory of the first file to tag/un-tag.
      3. .filetags file from the HOME directory.
    • .filetags files may be links (hardlinks, symbolic links or even Windows .LNK files)
  • Comments within .filetags files begin with one or more # characters that may be prepended by one or more spaces.
  • You can omit (case insensitive) tags from being proposed (selectable via shortcuts 0-9) by adding special comment lines like:
    #donotsuggest omit-this-tag dontshow
    #donotsuggest wontpropose
        
  • PLANNED: .filetags files may include other .filetags files via #include <relative or absolute path to another file>
  • FUTURE: CV: .filetags may contain mandatory options · Issue #17 · novoid/filetags · GitHub
    • Probably a nice to have for different default-behavior in different sub-hierarchies of the file system.

Filter

This function is very handy for filtering groups of photographs within a large set of photographs as described here.

  • The user defines one or more tags whose files are linked to a target directory.
  • Any “matching” .filetags file is linked to the target directory.
  • A populated target directory is never overwritten.
  • The default target directory is .filetags_tagfilter and might be changed by --tagtrees-dir.
  • When started interactively, a file browser is opened showing the target directory.
    • The file browser tool might be overwritten with --filebrowser.
  • The --recursive option is taken into account accordingly.

Features Related to TagTrees

The TagTrees concept was developed by me during my PhD thesis (PDF) when developing with the tagstore research platform.

Please note that in future, all functions related to TagTrees will be moved into a separate tool named tagtrees.

Tag Gardening

Just invoke filetags --tag-gardening or filetags --recursive --tag-gardening and read its output to learn about helpful analysis results to curate your tags. My personal favorites are:

  • I am able to find typos in tags (tag count is low and similar tags are found).
  • I can determine tags I seldom use and therefore might be removed from CVs.
  • Statistics on tag usage like, e.g.:
    • Distribution of mutually exclusive tag options.
    • Fraction of files that are not tagged.
  • Tags I have used which are not in my CVs.
  • Unused tags.

This feature is really powerful when it comes to maintenance of your file tags or get some insight related to your tagging patterns.

Local Variables

filetags's People

Contributors

deutschegabanna avatar icychkn avatar jonasjberg avatar nbehrnd avatar novoid avatar tuxlifan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

filetags's Issues

Naming pattern

I am currently setting up filetags, but want a slightly different naming scheme for my files:

20211224-tag1-tag2--thesis-proposal.org.

  1. Filename length often comes at a premium so date is YYYYMMDD saving 2 chars.
  2. Tags are between date and filename so that they 1) align (since I don't use time) and 2) are immediately visible.
  3. Tags are separated from the filename by -- saving 2 more chars.
  4. I realize special characters are mostly a non-issue today, but I am kinda OCD about them so decided to stick to a-z, 0-9 and - (I've used _ instead of - in the past, but it was largely a failure because for whatever reason it's not considered a word separator on Windows) - this last one is obviously out of scope and is mostly there to add context to my reasoning.
    I have a separate script to take care of that which strips all special characters and transliterates where appropriate.

My question is, is this achievable through minimal variable modification, or would it require some major rewriting and logic changes?

Of course please feel free to tell me if any/all of my changes are bad and why.

tagtrees seems to require geeqie

Trying out filetags and tagtrees for this first time, I get this:

filetags --recursive --tagtrees
INFO Creating tagtrees and their links. It may take a while … (exponentially with respect to number of tags)
INFO Number of links created in "/home/gina/.filetags_tagfilter" for the 2554 files: 2574 (tagtrees depth is 2)
Traceback (most recent call last):
File "/home/gina/.local/bin/filetags", line 8, in
sys.exit(main())
File "/home/gina/.local/lib/python3.10/site-packages/filetags/init.py", line 2575, in main
handle_option_tagtrees()
File "/home/gina/.local/lib/python3.10/site-packages/filetags/init.py", line 2444, in handle_option_tagtrees
start_filebrowser(chosen_tagtrees_dir)
File "/home/gina/.local/lib/python3.10/site-packages/filetags/init.py", line 2330, in start_filebrowser
subprocess.call([chosen_filebrowser, directory])
File "/usr/lib/python3.10/subprocess.py", line 345, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.10/subprocess.py", line 966, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.10/subprocess.py", line 1842, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geeqie'

I installed geeqie and the error went away. It seems like I should be able to run tagtrees without geeqie though.

filetags command in CLI not found

On Ubuntu 18.04
Install via pip install:
pip install filetags
Collecting filetags
Collecting pyreadline (from filetags)
Collecting clint (from filetags)
Collecting colorama (from filetags)
Using cached https://files.pythonhosted.org/packages/4f/a6/728666f39bfff1719fc94c481890b2106837da9318031f71a8424b662e12/colorama-0.4.1-py2.py3-none-any.whl
Collecting args (from clint->filetags)
Installing collected packages: pyreadline, args, clint, colorama, filetags
Successfully installed args-0.1.0 clint-0.5.1 colorama-0.4.1 filetags-2018.1.29.3 pyreadline-2.1

At the command line:
$ filetags
filetags: command not found

Thank you in advance!

Write number of errors to stdout

Idea is taken from 90d758c which introduces a variable for counting error cases.

It ends with:

    if num_errors > 0:
        error_exit(20, str(num_errors) + ' error(s) occurred. Please check messages above.') 

Maybe this functionality can be added to filetags.

Windows Install issues

I wanted to try your wonderful tagging idea using your scripts but encounter the following issues:

  1. First I tried the "Ubuntu on Windows" environment which leads to this error:
    Collecting filetags
    Using cached filetags-2017.12.30.tar.gz
    Requirement already satisfied: colorama in /usr/local/lib/python2.7/dist-packages (from filetags)
    Collecting importlib (from filetags)
    Using cached importlib-1.0.4.zip
    Collecting logging (from filetags)
    Using cached logging-0.4.9.6.tar.gz
    Collecting operator (from filetags)
    Could not find a version that satisfies the requirement operator (from filetags) (from versions: )
    No matching distribution found for operator (from filetags)

It's pip 9.0.1 (python 2.7)

  1. I cloned the git repo. Calling filetags.py again from "Ubuntu on Windows" leads to
    Traceback (most recent call last):
    File "software/git-repos/filetags/filetags.py", line 129, in
    :version: " + PROG_VERSION_DATE + "\n·\n"
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1: ordinal not in range(128)
    which seems to indicate a Unicode issue.

  2. I installed python 3.6.4 for Windows and called filetags.py leading to
    Could not find Python module "readline".
    Please install it, e.g., with "sudo pip install readline".
    Doing this leads to
    Collecting readline
    Downloading readline-6.2.4.1.tar.gz (2.3MB)
    Complete output from command python setup.py egg_info:
    error: this module is not meant to work on Windows

  3. I tried another route using docker:
    I created a python 2.7 docker container which clones this repo and then runs filetags.py --help
    This leads to
    Traceback (most recent call last):
    File "filetags/filetags.py", line 129, in
    :version: " + PROG_VERSION_DATE + "\n·\n"
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1: ordinal not in range(128)
    which is the same error as in 2)

Any idea what to do?

CV: .filetags may contain mandatory options

Controlled vocabulary files may contain a list of command line options that are mandatory.

Example: #options --recursive --filebrowser thunar always uses functions recursive and opens results in thunar (instead of a different default browser).

FIXXME:

  • What about contradicting CLI options?
    • example 1: --filebrowser thunar in .filetags and --filebrowser geeqie in command line?
    • example 2: --tagtrees-depth 3 in .filetags and user just wants to tag a file (which does not allow/need tagtrees at all and results in an error)

Cannot reuse custom tagtrees directories

Default tagtrees directory

$ filetags --tagtrees
INFO     Creating tagtrees and their links. It may take a while …  (exponentially with respect to number of tags)
INFO     Number of links created in "/home/user/.filetags_tagfilter" for the 5 files: 5  (tagtrees depth is 2)
$ filetags --tagtrees
INFO     Creating tagtrees and their links. It may take a while …  (exponentially with respect to number of tags)
INFO     Number of links created in "/home/user/.filetags_tagfilter" for the 5 files: 5  (tagtrees depth is 2)

Custom tagtrees directory

$ filetags --tagtrees --tagtrees-dir custom
INFO     Creating tagtrees and their links. It may take a while …  (exponentially with respect to number of tags)
INFO     Number of links created in "custom" for the 5 files: 5  (tagtrees depth is 2)
$ filetags --tagtrees --tagtrees-dir custom
ERROR    The given tagtrees directory custom is not empty. Aborting here instead of removing its content without asking. Please free it up yourself and try again.

Expectation

$ filetags --tagtrees --tagtrees-dir custom
INFO     Creating tagtrees and their links. It may take a while …  (exponentially with respect to number of tags)
INFO     Number of links created in "custom" for the 5 files: 5  (tagtrees depth is 2)
$ filetags --tagtrees --tagtrees-dir custom
INFO     Creating tagtrees and their links. It may take a while …  (exponentially with respect to number of tags)
INFO     Number of links created in "custom" for the 5 files: 5  (tagtrees depth is 2)

File case modifications on Windows

This seems really similar to #28 but since they couldn't recreate the issue I figured I'd open a new issue for now.

I'm using a checkout of af93083 with some of the debugging logging enabled. This is on Windows 10 1909 with python 3.7.4

This line is causing files be converted to all lower case (for some invocations)

expandedfiles = pathlib.Path(path.root).glob(str(pathlib.Path("").joinpath(*parts)))

The issue seems to be with glob and NTFS. In my setup, filetags is run via a batch file. That batch file is:

python.exe "C:\Users\user\Documents\filetags\filetags\__init__.py" %*

I can reliably recreate the issue with the following:

PS C:\_\filetagTests> ls


    Directory: C:\_\filetagTests


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         6/9/2020   1:18 AM              0 aaTestFile1.txt
-a----         6/9/2020   1:18 AM              0 bbTestFile2.txt

Ironically, using a wildcard works correctly:

PS C:\_\filetagTests> filetags -v aa*

C:\_\filetagTests>python.exe "C:\Users\user\Documents\filetags\filetags\__init__.py" -v aa*
DEBUG    2020-06-09 01:23:40,081 extracting list of files ...
DEBUG    2020-06-09 01:23:40,081 len(options.files) [1]
DEBUG    2020-06-09 01:23:40,082 WINDOWS: files[0] RAW [aa*]
DEBUG    2020-06-09 01:23:40,082 WINDOWS: len(files) [1]
DEBUG    2020-06-09 01:23:40,082 WINDOWS: files CONVERTED [['aaTestFile1.txt']]

But using a filename without a wildcard results in loss of capitalization:

PS C:\_\filetagTests> filetags -v aaTestFile1.txt

C:\_\filetagTests>python.exe "C:\Users\user\Documents\filetags\filetags\__init__.py" -v aaTestFile1.txt
DEBUG    2020-06-09 01:24:46,782 extracting list of files ...
DEBUG    2020-06-09 01:24:46,782 len(options.files) [1]
DEBUG    2020-06-09 01:24:46,783 WINDOWS: files[0] RAW [aaTestFile1.txt]
DEBUG    2020-06-09 01:24:46,783 WINDOWS: len(files) [1]
DEBUG    2020-06-09 01:24:46,784 WINDOWS: files CONVERTED [['aatestfile1.txt']]

With the FreeCommander integration all selected files are passed as an argument on the commandline resulting in any file you tag being converted to all lowercase. The most annoying instance being that if you build a tag tree and try to tag files in it, the link filenames are converted to lower case which doesn't match the original and so the tags are not added to the original file only to the links.

I had no idea what a good way to fix this was but then I couldn't get to sleep and thought of this:

files.append(str(file))

Changing it to files.append(str(file.resolve())) fixed the issue for me.

Apologies for not just putting in a PR, but I'm short on time and didn't think of a solution until after I wrote all this up.

Introduce TAG_EXTENSION_SEPARATOR to support TagSpaces name scheme

Hi Karl,

You defined <filename><separation string><list of tags>.<extension>. Using the vars

FILENAME_TAG_SEPARATOR = ' -- '
BETWEEN_TAG_SEPARATOR = ' '

I'm already able to choose a differnt seperator like your " -- ". That's fine.

But my wife does work on GUI only, so she's more a user of https://www.tagspaces.org/.
They use the scheme <filename>[<list of tags>].<extension>
I tried to implement this into the source code and filetags did write the tags in that way, but I didn't get the

# file names containing tags matches following regular expression
FILE_WITH_TAGS_REGEX = re.compile("(.+?)" + FILENAME_TAG_SEPARATOR + "(.+?)(\.(\w+))??$")

recognize existing tags.

What do you think about this enhancement? You know your code: Is it easy to implement this feature stable? If yes, I'll try it again. In additon, a .filetags.cfg file holding the vars would be useful for that case.

Thanks for your work,

Ralf

Request: add a way to filter by tag before applying tag

After using this tool for a while, I used --tag-gardening and it helpfully gave me a list that mentioned a few typos and mistakes. However, I have no easy way of fixing those mistakes!

Specifically, in my use case, I have various files where the tag word is occasionally included in the file name itself. This means I can't use standard shell functions to filter only for files with the wrong tag in the name.

As an example, I have a directory with many files including the following files (ttrpg battlemaps):

  • Seashore.jpg
  • Pirate Cove Ground Level.png
  • City docks under siege.png
  • Airship Docks 4.jpg

I intended to tag all of them as dock, but since the process was gradual over a long time, I accidentally tagged one of them differently:

  • Seashore -- sea dock.jpg
  • Pirate Cove Ground Level -- camp sea dock lair.png
  • City docks under siege -- settlement.png
  • Airship Docks 4 -- sky docks.jpg

Now I want to basically rename the tag docks to dock. However, I have no good way of doing that based on file tags, because Filetags has no such filter option, and my shell commands for *docks* catch unintended files.

Currently my best solution is to rely on careful regex checks and manual work, whenever I try to fix such a mistake.

However, I think this should be an easy feature to add to this program. One way of doing it is by specifically adding a --rename flag; however, I would personally suggest making it more generic and making a --select flag, used like this for example:
filetags --select="docks". this would open the interactive tagger for all files with that specific tag. Alternatively, this could just return an array of all those files, so re-tagging them would work by piping this command to | filetags again.

File enumeration/wildcards not implemented? (Windows)

Since *.txt and such aren't resolved on windows (or at least in cmd.exe), filetags gets the wildcard string directly:

echo hello > test.txt

filetags -v --tags="hello" *.txt

DEBUG    2019-12-21 13:20:55,617 extracting list of files ...
DEBUG    2019-12-21 13:20:55,618 len(options.files) [1]
DEBUG    2019-12-21 13:20:55,618 1 filenames found: [*.txt]
DEBUG    2019-12-21 13:20:55,618 reported console width: 80 and height: 80   (80/80 is the fall-back)
DEBUG    2019-12-21 13:20:55,618 locate_and_parse_controlled_vocabulary: called with startfile: "*.txt"
DEBUG    2019-12-21 13:20:55,618 locate_and_parse_controlled_vocabulary: called in cwd: C:\temp
DEBUG    2019-12-21 13:20:55,618 locate_file_in_cwd_and_parent_directories: called with startfile "*.txt" and filename ".filetags" ..
DEBUG    2019-12-21 13:20:55,618 locate_file_in_cwd_and_parent_directories: no startfile found; using cwd as starting_dir [C:\temp] ......
DEBUG    2019-12-21 13:20:55,619 locate_file_in_cwd_and_parent_directories: looking for ".filetags" in directory "C:\" .......
DEBUG    2019-12-21 13:20:55,620 locate_file_in_cwd_and_parent_directories: did NOT find ".filetags" in current directory or any parent directory
DEBUG    2019-12-21 13:20:55,620 locate_and_parse_controlled_vocabulary: locate_file_in_cwd_and_parent_directories did NOT find any filename
DEBUG    2019-12-21 13:20:55,620 locate_and_parse_controlled_vocabulary: this is Windows: also look out for lnk-files that link to .filetags files ...
DEBUG    2019-12-21 13:20:55,620 locate_file_in_cwd_and_parent_directories: called with startfile "*.txt" and filename ".filetags.lnk" ..
DEBUG    2019-12-21 13:20:55,620 locate_file_in_cwd_and_parent_directories: no startfile found; using cwd as starting_dir [C:\temp] ......
DEBUG    2019-12-21 13:20:55,620 locate_file_in_cwd_and_parent_directories: looking for ".filetags.lnk" in directory "C:\" .......
DEBUG    2019-12-21 13:20:55,620 locate_file_in_cwd_and_parent_directories: did NOT find ".filetags.lnk" in current directory or any parent directory
DEBUG    2019-12-21 13:20:55,620 locate_and_parse_controlled_vocabulary: this is Windows: .filetags (non-lnk) was found
DEBUG    2019-12-21 13:20:55,620 locate_and_parse_controlled_vocabulary: could not derive filename for controlled vocabulary
DEBUG    2019-12-21 13:20:55,620 non-interactive mode: extracting tags from argument ...
DEBUG    2019-12-21 13:20:55,620 tags found: [hello]
DEBUG    2019-12-21 13:20:55,620 iterate over files ...
DEBUG    2019-12-21 13:20:55,620 determined maximum file name length with 5
ERROR    2019-12-21 13:20:55,620 File "*.txt" does not exist. Skipping this one …
DEBUG    2019-12-21 13:20:55,621 successfully finished.

print out new filename when used non-interactive

To use filetags.py in scripts (e. g. to file away a tagged file) filetags.py should print out the new filename when used non-interactive:

I changed from line 950:

    new=handle_file(filename, tags_from_userinput, options.remove, options.dryrun)
    if options.tags:
        print new

retrieve data "from the archive" generated by filetags

The current version's header reads like a retrieval of the original files (or copies of them) once was envisioned (--copy flag), but either was not yet implemented, or is a feature (sadly) retracted. However, it would be a feature very welcome to facilitate e.g., access and subsequent share copies of non-image data stored at different dates in the archive (by move2archive).

Ad hoc , I identified the following approach working well enough. Perhaps parts of it can be used for the suggested feature extension:

  • enter the archive, e.g. and generate as usual a directory of file links, e.g.,
~/archive$ filetags --recursive --filter
                 
Please enter tags, separated by " "; abort with Ctrl-C
                     
         .--------, 
        | o   ?   | 
         `--------' 
                     
Tags: dw

INFO     filtering items with tag(s) "dw" and linking to directory "/home/norwid/.filetags_tagfilter" ...
 linking  "2022-05-17_dw550x__new_sketcher_icons -- dw updater.zip"
             ⤷   ".filetags_tagfilter"
 linking  "2022-05-21_molecules -- dw linked.dwar"
             ⤷   ".filetags_tagfilter"
 linking  "2022-05-21_example_str_skelspheres -- dw linked.png"
             ⤷   ".filetags_tagfilter"
[...]
  • Loop over the links which Python (now) may recognize as such (stackoverflow) and use to fetch copies with os.readlink() eventually resolved as self-sufficient files one may forward and share again:
~/.filetags_tagfilter$ python3 ./script.py

where script.py basically is

#!/usr/bin/env python3

"""Convert filetags' links into real files"""

import os
import shutil


for element in os.listdir("."):
    if os.path.islink(element):
        # get an intermediate «full file»
        new_name = "".join([os.path.basename(element), "_b"])
        shutil.copy(os.readlink(element), new_name)

        # remove the links from the folder
        os.remove(element)

# establish the original names:
for element in os.listdir("."):
    if element.endswith("_b"):
        shutil.move(element, str(element)[:-2])

The observations refer to Linux Debian 12/bookworm with Python 3.10.7 and the filetags executable reporting 2022-01-24 as last time of modification.

Generate something like TagTrees but for ctime/mtime

Add a separate script (I plan to separate filetags from tagtrees anyway) for generating a directory-link structure that reflects the datestamp of file creation (ctime=default) or modification (mtime): datetrees --dest "~/chosen_link_dir" --level month --mtime

$chosen_link_dir/2018/2018-05/2018-05-01_an_example_file.txt
$chosen_link_dir/2017/2017-11/an_example_file_without_datestamp_at_all.txt
...
  • choose a name: datetrees (?)
  • default result directory should differ from default tagtrees folder of filetags
  • Optional: stop at year/month/day-level with most probably "month" as the default
  • separate script within filetags-repository OR create an independent repository
    • dependency to #11
  • implement it ;-)

Fix TypeError in handle_file_and_optional_link()

Error occurred when invoking on Windows 10 test file structure.

Maybe it is caused by a duplicate file (file -- foo bar.txt) in two different folders which should be caught and handled appropriately.

See verbose output for details:

DEBUG    2018-06-01 14:10:48,862 create_link(C:\Users\karl.voit\2del\bar -- cust-nam draft internaluse foo bar.txt, C:\Users\karl.voit\.filetags_tagfilter\bar -- cust-nam draft internaluse foo bar.txt) called
DEBUG    2018-06-01 14:10:48,870 handle_file_and_optional_link("C:\Users\karl.voit\2del\bar -- cust-nam draft internaluse foo bar.txt") FINISHED  ????????????????????
DEBUG    2018-06-01 14:10:48,870 list_of_link_directories: []
DEBUG    2018-06-01 14:10:48,871 is_broken_link(C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt)  is not a lnk file at all; thus: not a broken link
DEBUG    2018-06-01 14:10:48,871 handle_file_and_optional_link("C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt") �  ????????????????????
DEBUG    2018-06-01 14:10:48,872 handle_file_and_optional_link: changing to dir "C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files"
DEBUG    2018-06-01 14:10:48,872 handle_file_and_optional_link: file is not a non-broken link (False) or TAG_LINK_ORIGINALS_WHEN_TAGGING_LINKS is not set
DEBUG    2018-06-01 14:10:48,872 handle_file_and_optional_link: after handling potential link originals, I now handle the file we were talking about in the first place: C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt
DEBUG    2018-06-01 14:10:48,873 handle_file("C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt") ##########  � with working dir "C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files"
 linking  "file -- foo bar.txt"
             ?   ".filetags_tagfilter"
DEBUG    2018-06-01 14:10:48,874 create_link(C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt, C:\Users\karl.voit\.filetags_tagfilter\file -- foo bar.txt) called
DEBUG    2018-06-01 14:10:48,882 handle_file_and_optional_link("C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt") FINISHED  ????????????????????
DEBUG    2018-06-01 14:10:48,882 list_of_link_directories: []
DEBUG    2018-06-01 14:10:48,893 is_broken_link(C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt.lnk) == C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt  which does exist -> non-broken link
DEBUG    2018-06-01 14:10:48,894 handle_file_and_optional_link("C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt.lnk") �  ????????????????????
DEBUG    2018-06-01 14:10:48,901 handle_file_and_optional_link: file is a non-broken link (and TAG_LINK_ORIGINALS_WHEN_TAGGING_LINKS is set)
DEBUG    2018-06-01 14:10:48,907 get_link_source_file(C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt.lnk) == C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt  which does exist -> non-broken link
DEBUG    2018-06-01 14:10:48,908 handle_file_and_optional_link: link "C:\Users\karl.voit\2del\2018-05-11_backup-tmp\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt.lnk" has same basename as its source file "C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt"  vvvvvvvvvvvvvvvvvvvv
DEBUG    2018-06-01 14:10:48,908 handle_file_and_optional_link: invoking handle_file_and_optional_link("C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt")  vvvvvvvvvvvvvvvvvvvv
DEBUG    2018-06-01 14:10:48,908 handle_file_and_optional_link("C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt") �  ????????????????????
DEBUG    2018-06-01 14:10:48,909 handle_file_and_optional_link: changing to dir "C:\Users\karl.voit\src\filetags\manualtests\test lnk files"
DEBUG    2018-06-01 14:10:48,910 handle_file_and_optional_link: file is not a non-broken link (False) or TAG_LINK_ORIGINALS_WHEN_TAGGING_LINKS is not set
DEBUG    2018-06-01 14:10:48,910 handle_file_and_optional_link: after handling potential link originals, I now handle the file we were talking about in the first place: C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt
DEBUG    2018-06-01 14:10:48,910 handle_file("C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt") ##########  � with working dir "C:\Users\karl.voit\src\filetags\manualtests\test lnk files"
 linking  "file -- foo bar.txt"
             ?   ".filetags_tagfilter"
DEBUG    2018-06-01 14:10:48,911 create_link(C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt, C:\Users\karl.voit\.filetags_tagfilter\file -- foo bar.txt) called
DEBUG    2018-06-01 14:10:48,924 handle_file_and_optional_link("C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt") FINISHED  ????????????????????
DEBUG    2018-06-01 14:10:48,924 handle_file_and_optional_link: RETURNED handle_file_and_optional_link("C:\Users\karl.voit\src\filetags\manualtests\test lnk files\file -- foo bar.txt")  vvvvvvvvvvvvvvvvvvvv
Traceback (most recent call last):
  File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python36\Scripts\filetags.exe\__main__.py", line 9, in <module>
  File "c:\python36\lib\site-packages\filetags\__init__.py", line 2626, in main
    options.dryrun)
  File "c:\python36\lib\site-packages\filetags\__init__.py", line 910, in handle_file_and_optional_link
    new_source_filename = os.path.join(old_source_dirname, new_source_basename)
  File "c:\python36\lib\ntpath.py", line 114, in join
    genericpath._check_arg_types('join', path, *paths)
  File "c:\python36\lib\genericpath.py", line 149, in _check_arg_types
    (funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'NoneType'

.filetags Error on windows

I try to use the .filetags facility but get the following error:

Traceback (most recent call last):
  File "c:\users\<USER>\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\<USER>\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\<USER>\AppData\Local\Programs\Python\Python36\Scripts\filetags.exe\__main__.py", line 9, in <module>
  File "c:\users\<USER>\appdata\local\programs\python\python36\lib\site-packages\filetags\__init__.py", line 1819, in main
    vocabulary = sorted(locate_and_parse_controlled_vocabulary(False))
  File "c:\users\<USER>\appdata\local\programs\python\python36\lib\site-packages\filetags\__init__.py", line 1158, in locate_and_parse_controlled_vocabulary
    for rawline in filehandle:
  File "c:\users\<USER>\appdata\local\programs\python\python36\lib\codecs.py", line 713, in __next__
    return next(self.reader)
  File "c:\users\<USER>\appdata\local\programs\python\python36\lib\codecs.py", line 644, in __next__
    line = self.readline()
  File "c:\users\<USER>\appdata\local\programs\python\python36\lib\codecs.py", line 557, in readline
    data = self.read(readsize, firstline=True)
  File "c:\users\<USER>\appdata\local\programs\python\python36\lib\codecs.py", line 503, in read
    newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 0: invalid start byte

It's the same both if I choose Unicode and if I choose ANSI to save the file. Any idea what I'm doing wrong?

.filetags CV-file: include other files

I want to include other .filetags files within a .filetags file like:

firsttag
#include ../other/subdir/additional_filetags.txt
normaltag
anothertag

Including other files is done in lines that must start with #include followed by a relative or absolute link to a file or symbolic link or Windows shortcut file.

  • make sure that circular includes are detected somehow -> concept needed
    • example: foo/.filetags includes bar/.filetags which includes baz/.filetags which includes foo/.filetags again
    • promising approach: calculate md5sum of each CV file before loading, compare with all md5sums already loaded and stop when the md5sum is already in the list of known CV files.

Support custom tag indicators

Hi:

This seems like a very useful project. I certainly hope to fit it into my workflow. I was wondering if it would be possible to support custom tag formats/indicators. I've been borrowing the # to indicate tags and I've seen others use @. It would be great to be able to use this script in order to name a file like this:

filename #tag1 #tag2.txt

Above all, this visually distinguishes (for me anyway) tags from other parts of the filename. I would also make it possible to search specifically for tags, rather than just something with that word in its title, while not throwing out the simplicity of your system.

Anyhow, thanks!

tab completion doesn't work

i made a folder with some files and tested filetags.
now i removed that folder and start to tag files in a new folder but tab completion doesn't work.
is there a problem with .filetags? how can i access to it?
thanks

Trouble running on Windows pypiwin32 win32com.client

This should take care of all prereqs:

conda create -n tag -c anaconda -c conda-forge clint pyreadline colorama pip
conda activate tag
python -m pip install --upgrade pypiwin32

However, running the script (python .\__init__.py) throws the following error:

Could not find Python module "win32com.client".
Please install it, e.g., with "sudo pip install pypiwin32".

conda list prints the following:

args                      0.1.0           pyhd8ed1ab_1004    conda-forge
ca-certificates           2020.10.14                    0    anaconda
certifi                   2020.6.20                py38_0    anaconda
clint                     0.5.1                      py_1    conda-forge
colorama                  0.4.4                      py_0    anaconda
openssl                   1.1.1h               he774522_0    anaconda
pip                       20.2.4                   py38_0    anaconda
pypiwin32                 223                      pypi_0    pypi
pyreadline                2.1                      py38_1    anaconda
python                    3.8.5                h5fd99cc_1    anaconda
pywin32                   303                      pypi_0    pypi
setuptools                50.3.0           py38h9490d1a_1    anaconda
sqlite                    3.33.0               h2a8f88b_0    anaconda
vc                        14.1                 h0510ff6_4    anaconda
vs2015_runtime            14.16.27012          hf0eaf9b_3    anaconda
wheel                     0.35.1                     py_0    anaconda
wincertstore              0.2                      py38_0    anaconda
zlib                      1.2.11           vc14h1cdd9ab_1  [vc14]  anaconda

which I think has everything needed.
I notice it lists both pypiwin32 and pywin32.
Could that be the issue?
I definitely didn't install pywin32, I think pip did it on its own when I installed pypiwin32.

tagging in general

one question about tagging in general. You have thought so much about information management so that maybe you can tell quickly whether my idea is bad. I read a lot (and have learned a lot) on your webpage and in the articles you posted online but I think you haven't written about my idea. In your software you put the tags at the end of the file names. If I don't use your software it's quite complicated to search for tags because I must use a long regular expression. I'm not sure if this is future proof because even today I'm increasingly relying on my ipad and most mobile os apps offer only a simplified UI. On my main machine I still use many scripts etc. but I think many attractive new devices won't offer the user so much freedom and I think I'll be tempted to use such devices.
So my idea is to start all my tags will a pair of letters like qv (→ "myfilename qvtag1 qvtag2.org"). I chose a pair of letters that's very infrequent in my native language and English and tested it on my file names with find and my file contents with grep.
Even if I only have a basic search field now I can search for tags because all my tags would start with this unique letter combination.
Are there any drawbacks apart from the fact that it doesn't look very nice? If I wanted to use a controlled vocabulary I would have to adjust my helper script that adds or removes qv at the beginning so that I can manage my tags without seeing the prefix. But this shouldn't be too difficult.
Thanks for your time.

P.S. The way your readme.org is rendered here on github is misleading. You use a double dash to separate the tags whereas in the html version on github there is a long dash. Would it help to put == or ~~ around your dashes so that your line 11 looks like this: file without time stamp in name =--= *tag2*.txt"?

filetags on windows

I have been using filetags PROG_VERSION_NUMBER = u"0.3" PROG_VERSION_DATE = u"2015-01-02" successfully for some time now.

I am using Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32

Now I tried to ipgrade to filetags PROG_VERSION_NUMBER = u"0.6beta" PROG_VERSION_DATE = u"2016-01-08" but ran into an error.

Traceback (most recent call last):
  File "filetags.py", line 973, in <module>
    main()
  File "filetags.py", line 887, in main
    vocabulary = sorted(locate_and_parse_controlled_vocabulary(args[0]))
TypeError: 'bool' object is not iterable

Unfortunately I do not know Python at all to be able to tackle this issue.

Thanks for the great script.

Python 3.10+ callable change

Hi! Do your python scrips import a module called Callable? It has been moved since 3.10+ into abc.callable and so I'm getting errors like:
"AttributeError: module 'collections' has no attribute 'Callable'" occurs for multiple reasons:
when launching your scripts.

Difference with other search tools

I was thinking how the -tagtrees capability differs from other search tools. Because as I see it, what this does is search for words in the file names. Using for instance, in mac name:WORD in FINDER's search achieves the same purpose (?). It will retrieve a list of files containing that tag in their file names, by frecency. Please, let me know if I got it wrong. Thanks in advance!

A secondary default path for TagTrees to be used for generating TagTrees from within another TagTree

Note: this feature implementation requires #16 to be implemented before.

I want to be able to generate a secondary TagTree when I'm browsing a existing TagTree.

For example, when I've generated a TagTree for my photographs and I'm within the TagTree directory "cliparts/cars" I want to be able to generate yet another TagTree just for the current files in the "cliparts/cars" directory. This way, I can "filter/browse/navigate" all files that are tagged with "cliparts" and "cars" for all other tags including mutual exclusive tags whose no-tags-directories aren't provided in nested directories.

The new links need to link to the original files and not to the primary TagTree files.

When I do want to generate a TagTree from within the secondary TagTree, I might as well re-use the primary TagTree directory for the third TagTree (alternating use of TagTree directories).

Using that feature requires either a command line option for a different TagTree base directory or another TagTree base directory in the config file from #16.

couldn't find python module readline in ubuntu

installed filetags six months back. worked flawlessly. after recent update of python packages, filetags complaining error of " couldn't find python module readline" .

An image file is attached to show the error message.
I have even tried to install in virualenv with pyenv. complaining the same error.

20190403T1049-crop

--filter options also works when generating tagtrees

I want to be able to use --filter option so that I get asked what tags I want to have in a tagtrees structure.

When I choose "foo" and "bar", the generated tagtrees only contain files which were tagged with both tags (and optional other tags as well).

setup.py / filetags script

I'm trying to put together a setup.py to easily install filetags with/in Guix and hack on it in a controlled manner.
I seem to be unable to find how pip (with --user option) condensed the code in ~/.local/bin/filetags out of thin air... any pointers?

Here's what I've got so far for setup.py:

from setuptools import setup, find_packages

setup(
    name='filetags',
    version='2018.4.250',
    description='Management of simple tags within file names',
    url='https://github.com/novoid/filetags',
    test_suite="tests.unit_tests",
    packages=find_packages()
)

write .filetags-tagtree and .filetags-tagfilter file to their root directories

When filetags is generating TagTrees or tagfilter hierarchies, there should be .filetags-tagtree and .filetags-tagfilter files in their root directories so that users are able to locate them for purposes like, e.g., excluding from backup runs.

Those files should contain explanations on filetags, TagTrees/tagfilter so that people are able to learn about it.

I'm not able to run filetags on Virtual Centos Install

When attempting to run filetags I get the following:

$ filetags -v
Traceback (most recent call last):
  File "/home/alpsdev/.local/bin/filetags", line 5, in <module>
    from filetags import main
  File "/home/alpsdev/.local/lib/python3.9/site-packages/filetags/__init__.py", line 51, in <module>
    save_import('readline')   # for raw_input() reading from stdin
  File "/home/alpsdev/.local/lib/python3.9/site-packages/filetags/__init__.py", line 35, in save_import
    globals()[library] = import_module(library)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/alpsdev/.local/lib/python3.9/site-packages/readline.py", line 6, in <module>
    from pyreadline.rlmain import Readline
  File "/home/alpsdev/.local/lib/python3.9/site-packages/pyreadline/__init__.py", line 12, in <module>
    from . import logger, clipboard, lineeditor, modes, console
  File "/home/alpsdev/.local/lib/python3.9/site-packages/pyreadline/clipboard/__init__.py", line 13, in <module>
    from .win32_clipboard import GetClipboardText, SetClipboardText
  File "/home/alpsdev/.local/lib/python3.9/site-packages/pyreadline/clipboard/win32_clipboard.py", line 39, in <module>
    from pyreadline.keysyms.winconstants import CF_UNICODETEXT, GHND
  File "/home/alpsdev/.local/lib/python3.9/site-packages/pyreadline/keysyms/__init__.py", line 23, in <module>
    raise ImportError("Could not import keysym for local pythonversion", x)
NameError: name 'x' is not defined

I installed it via pip
Python is an altinstall of 3.9 since centos uses it's own version that is 2.x

$ pip3 install date2name appendfilename filetags integratethis
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: date2name in /home/***/.local/lib/python3.9/site-packages (2018.5.9.1)
Requirement already satisfied: appendfilename in /home/***/.local/lib/python3.9/site-packages (2020.6.7.1)
Requirement already satisfied: filetags in /home/***/.local/lib/python3.9/site-packages (2021.4.3.1)
Requirement already satisfied: integratethis in /home/***/.local/lib/python3.9/site-packages (2020.1.8.1)
Requirement already satisfied: pyreadline in /home/***/.local/lib/python3.9/site-packages (from appendfilename) (2.1)
Requirement already satisfied: colorama in /home/***/.local/lib/python3.9/site-packages (from filetags) (0.4.4)
Requirement already satisfied: clint in /home/***/.local/lib/python3.9/site-packages (from filetags) (0.5.1)
Requirement already satisfied: args in /home/***/.local/lib/python3.9/site-packages (from clint->filetags) (0.1.0)

I am using Gnome-Terminal WindowMaker not sure if that would cause an issue => Trying with xterm => Same Result
Trying in pure terminal => Same result

Let me know if you need anything else.

Thank you for such an awesome set of tools!!!

Write a dedicated manual file with a list of standard use-cases

The README.org did get long. Tool integration was separated in 2018-04. However, there should be a dedicated manual with a chapter that lists typical use-cases such as:

  • tag gardening scenarios
  • CV explained
  • "hidden" features explained (mutual exclusive tagging, tagging original files within links, ...)
  • generating tagtrees and re-tagging
    • "foo" -> "bar"
    • fix singular to plural
    • find typos in tags
  • and much more

RFE: Sync tags to extended attributes (Linux), filesystem tags (OSX) or ntfs attributes

Recently found your filetags tool and really like it. I am very fond of managing files with tags and automate by assigning tags.
I found syncing the tags to filesystem attributes very helpful.

Maybe this feature may also be a good addition to filetags? That way, the operating system can index the tags and search is more efficient.

A small python script I currently use for this is https://github.com/rrottmann/tag2xattr

As I also use TagSpaces, my tagging style expects "filename [tag1, tag2, tag3].ext", though.

Follow XDG Base Directory specification

I believe ${XDG_STATE_HOME}/filetags is a more preferable default directory for tagtrees compared to ~/.filetags_tagfilter for people who want to avoid dotfile clutter. Albeit debatable, one may also want to move ${HOME}/.filetags inside of an xdg base directory, which could be at the following path: ${XDG_CONFIG_HOME}/filetags/vocabulary. If we continue this example, #16 maps to ${XDG_CONFIG_HOME}/filetags/filetags.{toml,yaml,...}.

Tagging files outside of their directory fails

Steps to reproduce

$ mkdir example/
$ touch example/file.txt
$ filetags --verbose example/file.txt
DEBUG    2023-08-19 19:52:24,250 extracting list of files ...
DEBUG    2023-08-19 19:52:24,251 len(options.files) [1]
DEBUG    2023-08-19 19:52:24,251 1 filenames found: [example/file.txt]
DEBUG    2023-08-19 19:52:24,251 reported console width: 190 and height: 45   (80/80 is the fall-back)
DEBUG    2023-08-19 19:52:24,251 locate_and_parse_controlled_vocabulary: called with startfile: "example/file.txt"
DEBUG    2023-08-19 19:52:24,251 locate_and_parse_controlled_vocabulary: called in cwd: /home/user/Documents
DEBUG    2023-08-19 19:52:24,251 locate_file_in_cwd_and_parent_directories: called with startfile "example/file.txt" and filename ".filetags" ..
DEBUG    2023-08-19 19:52:24,251 locate_file_in_cwd_and_parent_directories: startfile [example/file.txt] found, using it as starting_dir [/home/user/Documents/example] ....
DEBUG    2023-08-19 19:52:24,251 locate_file_in_cwd_and_parent_directories: looking for ".filetags" in directory "/home/user/Documents" .......
DEBUG    2023-08-19 19:52:24,251 locate_file_in_cwd_and_parent_directories: did NOT find ".filetags" in current directory or any parent directory
DEBUG    2023-08-19 19:52:24,251 locate_and_parse_controlled_vocabulary: locate_file_in_cwd_and_parent_directories did NOT find any filename
DEBUG    2023-08-19 19:52:24,251 locate_and_parse_controlled_vocabulary: could not derive filename for controlled vocabulary
DEBUG    2023-08-19 19:52:24,251 split_up_filename(example/file.txt) does NOT exist. Playing along and returning non-existent filename parts.
DEBUG    2023-08-19 19:52:24,251 found common tags: tags_intersection_of_files[]
DEBUG    2023-08-19 19:52:24,251 split_up_filename(example/file.txt) does NOT exist. Playing along and returning non-existent filename parts.
DEBUG    2023-08-19 19:52:24,251 deriving upto9_tags_for_shortcuts ...
Traceback (most recent call last):
  File "/home/user/.local/bin/filetags", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/user/.local/pipx/venvs/filetags/lib/python3.11/site-packages/filetags/__init__.py", line 2664, in main
    get_tags_from_files_and_subfolders(
  File "/home/user/.local/pipx/venvs/filetags/lib/python3.11/site-packages/filetags/__init__.py", line 1241, in get_tags_from_files_and_subfolders
    assert(os.path.isdir(startdir))
AssertionError
$ cd example/
$ filetags --verbose file.txt
DEBUG    2023-08-19 19:59:24,103 extracting list of files ...
DEBUG    2023-08-19 19:59:24,103 len(options.files) [1]
DEBUG    2023-08-19 19:59:24,103 1 filenames found: [file.txt]
DEBUG    2023-08-19 19:59:24,103 reported console width: 190 and height: 45   (80/80 is the fall-back)
DEBUG    2023-08-19 19:59:24,103 locate_and_parse_controlled_vocabulary: called with startfile: "file.txt"
DEBUG    2023-08-19 19:59:24,104 locate_and_parse_controlled_vocabulary: called in cwd: /home/user/Documents/example
DEBUG    2023-08-19 19:59:24,104 locate_file_in_cwd_and_parent_directories: called with startfile "file.txt" and filename ".filetags" ..
DEBUG    2023-08-19 19:59:24,104 locate_file_in_cwd_and_parent_directories: startfile [file.txt] found, using it as starting_dir [/home/user/Documents/example] ....
DEBUG    2023-08-19 19:59:24,104 locate_file_in_cwd_and_parent_directories: looking for ".filetags" in directory "/home/user/Documents" .......
DEBUG    2023-08-19 19:59:24,104 locate_file_in_cwd_and_parent_directories: found ".filetags" in directory "/home/user" ........
DEBUG    2023-08-19 19:59:24,104 locate_and_parse_controlled_vocabulary: locate_file_in_cwd_and_parent_directories returned: /home/user/.filetags
DEBUG    2023-08-19 19:59:24,104 locate_and_parse_controlled_vocabulary: .filetags found: /home/user/.filetags
DEBUG    2023-08-19 19:59:24,104 locate_and_parse_controlled_vocabulary: found controlled vocabulary
DEBUG    2023-08-19 19:59:24,104 locate_and_parse_controlled_vocabulary: reading controlled vocabulary in [/home/user/.filetags]
DEBUG    2023-08-19 19:59:24,104 locate_and_parse_controlled_vocabulary: found unique tags: draft final
DEBUG    2023-08-19 19:59:24,104 locate_and_parse_controlled_vocabulary: controlled vocabulary has 17 tags
DEBUG    2023-08-19 19:59:24,104 locate_and_parse_controlled_vocabulary: controlled vocabulary has 1 groups of unique tags
DEBUG    2023-08-19 19:59:24,104 found common tags: tags_intersection_of_files[]
DEBUG    2023-08-19 19:59:24,104 deriving upto9_tags_for_shortcuts ...
DEBUG    2023-08-19 19:59:24,104 get_tags_from_files_and_subfolders called with startdir [/home/user/Documents/example], cached startdirs [0]
DEBUG    2023-08-19 19:59:24,104 get_tags_from_files_and_subfolders: Writing 0 tags in cache for directory: /home/user/Documents/example
DEBUG    2023-08-19 19:59:24,104 get_upto_nine_keys_of_dict_with_highest_value: complete_list: 
DEBUG    2023-08-19 19:59:24,105 derived upto9_tags_for_shortcuts
DEBUG    2023-08-19 19:59:24,105 derived vocabulary with 17 entries
DEBUG    2023-08-19 19:59:24,105 len(files) [1]
DEBUG    2023-08-19 19:59:24,105 files: ['file.txt']
                 
Please enter tags, separated by " "; abort with Ctrl-C; complete 17 tags with TAB
                     
         .--------, 
        | o   ?   | 
         `--------' 
                     
DEBUG    2023-08-19 19:59:24,105 interactive mode: asking for tags ...
Tags: 

Root cause

A bunch of functions call os.chdir while others assume that the working directory is the original working directory. We also assume that os.path.abs generates a valid absolute path, but os.path.abs relies on the working directory to generate an absolute path. If filetags switches to /path/to/tagtrees, but the file argument is tagtrees/file.txt, os.path.abs generates /path/to/tagtrees/tagtrees/file.txt, which is obviously not what we want.

How to add filetags to macOS Finder context menu

I'd like to know how filetags could be integrated into the context menu of the macOS Finder.

My notes so far:

  • Automator:
    • Service receives selected "files or folders" in "any application"
    • "Run Shell Script"
      • Shell: /bin/bash
      • Pass input: "as arguments" (not: "to stdin")
      • /Library/Frameworks/Python.framework/Versions/3.6/bin/filetags "$@"; read $foo
    • On invocation:
The action "Run Shell Script" encountered an error: "stty: stdin isn't a terminal
Traceback (most recent call last):
 File "/Library/Frameworks/Python.framework/Versions/3.6/bin/filetags", line 11, in <module>
   sys.exit(main())
 File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/filetags/__init__.py", line 2564, in main
   tags_from_userinput = ask_for_tags(vocabulary, upto9_tags_for_shortcuts, tags_for_visual)
 File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/filetags/__init__.py", line 1888, in ask_for_tags
   entered_tags = input(colorama.Style.DIM + 'Tags: ' + colorama.Style.RESET_ALL).strip()
EOFError: EOF when reading a line"

CLI parameter to switch between: use symlink, hardlink, or copy

Non-Windows systems do not only know lnk files but also symbolic links and hard links.

I'd like to be able to choose for tagtrees and filter functionality whether or not (1) lnk files or symlinks are being used (2) hard links are used or (3) file get copied instead.

tagging in --quiet mode isn't quite quiet

If filtetag's flag -q / --quiet was meant to provide a generation of tagtrees without opening Geeqie (or an other file browser), then this option seems to be defunct.

At about 42:11 mm:ss and later, the video about your presentation at GLT18 briefly shows the results of using tagtrees, especially appealing after running move2archive. The bottom of the file navigator seems to list a script to rebuild this collection of links when necessary. A valuable detail, so I wrote a bash script which is deposit into the move2archive's target folder:

#!/usr/bin/bash

filetags --tagtrees --recursive --tagtrees-depth 3 --quiet

echo "Folder /home/norwid/.filetags_tagfilter/ contains the tagstree."

However, despite the flag --quiet, Geeqie is started.

Running filetags --tagtrees --recursive --tagtrees-depth 3 --quiet directly in the CLI does yields the same observation. It looks like this has been around for quite some time because checking out an earlier version of filtetags (2017-09-30, an earlier version of filetags to work with Python3) shares this when using flag -q, too.

2022-01-23_filetags_observations.zip

Separate tagtrees functionality into a different Python script

Functionalities that deal with generation of tagtrees were added to "filetags". Related command line options got more and more.

Maybe it is time to separate the tagtrees functionality to a new Python script which is still part of the "filetags" repository and pip package.

Files within tagged directories do inherit the tags for all relevant features

A file like $HOME/subdir1 -- foo/subdir2/a file.txt does inherit the tag "foo" from its absolute path.

#13 has to be done beforehand.

FIXXME: think about all implications of this feature and how to handle it. E.g., there will be untagged files in tagtrees and you don't have a clue why this file is there and you can't remove its filetag.

Note 2019-09-21: The TreeTags concept might give some potential solutions for combined tags within directory names and file names.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.