Example #1
0
    def set_name(entry: Entry,
                 destination_folder: str = "",
                 nas: bool = False,
                 dropbox: bool = False,
                 name_from_modified_date: bool = False,
                 keep_manual_names: bool = False,
                 is_month: bool = False) -> None:
        """ Set the name and path for a file based on the following criteria:

        Path: if the destination_folder parameter is not empty, use that as the path. If it is empty, assemble the path
        from the captured date (YYYY/MM_MonthName) or if the captured date is not set, from the modified time date.
        Sometimes the filename itself contains a string YYYYMMDD somewhere in the middle (true for Whatsapp images),
        if that pattern is found, set the path accordingly. The name is kept as is.
        However, if the date does not come from the captured time, check that the file has not already been catalogued
        somewhere else and moved there manually. So if the catalog contains the same checksum already, the file is
        skipped.

        Name:
        If the name_from_captured_date is True, and the entry has the captured time, use that to set the file name.
        If the name_from_modified_date is True, and it does have the captured_date, then again the captured date is set.
        Otherwise the modified date is set, prepended to the previous name (with an @ in between).
        There is also a keep_manual_names flag, if set, we simply keep the name if it seems to be mostly characters,
        not digits, because that seems like a human set the name manually.
         """

        if nas:
            entry.nas = True
        if dropbox:
            entry.dropbox = True

        # set folder
        if destination_folder and not is_month:
            entry.path = destination_folder
        else:
            Folder.set_path_from_name(entry)

        # set name
        name, ext = os.path.splitext(entry.name)
        entry.name = name + ext.lower()
        if keep_manual_names and Folder.is_probably_text(name):
            # if there is significant text in the name already, keep that text, ignore numerals
            if hasattr(entry, "captured"):
                # but append the captured time to the text if there is one
                entry.name = name + ' ' + entry.captured_str + ext.lower()
            return
        if hasattr(entry, "captured"):
            # if there is a captured date/time, use that, always
            entry.name = entry.captured_str + ext.lower()
        elif name_from_modified_date:
            # Prepend the modification date if explicitly requested
            entry.name = entry.modified_time_str + ' @ ' + name + ext.lower()
Example #2
0
 def test_name_invalid_path(self):
     entry = Entry()
     try:
         entry.name = "somepath/myname.ext"
         self.fail("Should have raised exception")
     except EntryException as e:
         self.assertEqual(e.args[0].find("File name given must just"), 0)
Example #3
0
 def test_name_simple_filename(self):
     entry = Entry()
     entry.name = "myfile.ext"
     self.assertEqual(entry.name, "myfile.ext")
     self.assertEqual(entry.type, "ext")