示例#1
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)
示例#2
0
 def on_save_button(self):
     if len(self.ids.name_input.text) == 0:
         status.message('Name must not be empty', weak=True)
         return
     if not self.has_changed():
         status.message('No changes to write', weak=True)
         return
     name = self.ids.name_input.text
     kwargs = {'icon': self.ids.image_widget.icon,
               'linktypeconfig': self.linktypeconfig}
     if self.entry is None:
         status.message('Saving new entry {}'.format(name), weak=True)
         try:
             self.entry = Entry(name=name,**kwargs)
             status.message('Saved new entry {}'.format(name), weak=True)
         except (EntryException, LinktypeException) as e:
             status.error(e)
     elif self.entry.name != name:
         status.message('Saving entry {}'.format(name), weak=True)
         try:
             new_entry = Entry(name=name,**kwargs)
             if new_entry is not None:
                 self.entry.delete()
                 self.entry = new_entry
             status.message('Saved entry {}'.format(name), weak=True)
         except (EntryException, LinktypeException) as e:
             status.error(e)
     else:
         status.message('Saving entry {}'.format(name), weak=True)
         try:
             self.entry.save(**kwargs)
             status.message('Saved entry {}'.format(name), weak=True)
         except (EntryException, LinktypeException) as e:
             status.error(e)
示例#3
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()
示例#4
0
class PylesEdit(BoxLayout):

    def __init__(self, entry = None, **kwargs):
        super(PylesEdit, self).__init__(**kwargs)
        self.app = App.get_running_app()
        self.linktypeconfig = None
        self.entry = entry
        if self.entry is None:
            self.on_linktypename(self.ids.linktype_selection.text)
        else:
            self.ids.linktype_selection.text = self.entry.linktype.name
            self.ids.name_input.text = self.entry.name
            self.ids.image_widget.load_entry(self.entry)
            self.linktypeconfig = self.entry.linktypeconfig
            self.build_settings()
    
    def has_changed(self):
        # Not editing an entry
        if self.entry is None:
            # Name is mandatory
            if len(self.ids.name_input.text) > 0:
                return True
        else:
            # Name has changed
            if self.ids.name_input.text != self.entry.name:
                return True
            # LinkType has changed
            if self.linktypeconfig != self.entry.linktypeconfig:
                return True
            # Setting has changed
            for key, setting in self.linktypeconfig['settings'].items():
                if setting.has_changed():
                    return True
            # Icon has changed
            if self.ids.image_widget.icon != self.entry.icon:
                return True
        return False

    def on_back_button(self):
        self.app.set_widget('list')
        
    def on_save_button(self):
        if len(self.ids.name_input.text) == 0:
            status.message('Name must not be empty', weak=True)
            return
        if not self.has_changed():
            status.message('No changes to write', weak=True)
            return
        name = self.ids.name_input.text
        kwargs = {'icon': self.ids.image_widget.icon,
                  'linktypeconfig': self.linktypeconfig}
        if self.entry is None:
            status.message('Saving new entry {}'.format(name), weak=True)
            try:
                self.entry = Entry(name=name,**kwargs)
                status.message('Saved new entry {}'.format(name), weak=True)
            except (EntryException, LinktypeException) as e:
                status.error(e)
        elif self.entry.name != name:
            status.message('Saving entry {}'.format(name), weak=True)
            try:
                new_entry = Entry(name=name,**kwargs)
                if new_entry is not None:
                    self.entry.delete()
                    self.entry = new_entry
                status.message('Saved entry {}'.format(name), weak=True)
            except (EntryException, LinktypeException) as e:
                status.error(e)
        else:
            status.message('Saving entry {}'.format(name), weak=True)
            try:
                self.entry.save(**kwargs)
                status.message('Saved entry {}'.format(name), weak=True)
            except (EntryException, LinktypeException) as e:
                status.error(e)

    def on_linktypename(self, linktypename):
        self.linktypeconfig = manager.get_config(linktypename)
        self.build_settings()
        
    def build_settings(self):
        if self.linktypeconfig:
            self.ids.linktype_settings.clear_widgets()
            for key, setting in self.linktypeconfig['settings'].items():
                self.ids.linktype_settings.add_widget(
                    SingleLabel(text=setting.label))
                self.ids.linktype_settings.add_widget(
                    setting.get_widget())
示例#5
0
 def test_name_simple_filename(self):
     entry = Entry()
     entry.name = "myfile.ext"
     self.assertEqual(entry.name, "myfile.ext")
     self.assertEqual(entry.type, "ext")
示例#6
0
 def test_set_date(self):
     entry = Entry()
     entry.modified = 0
     self.assertEqual(entry.modified_str, "1970-01-01")
示例#7
0
 def test_set_full_path_relative(self):
     entry = Entry()
     entry.full_path = "../this/is/somepath/myname.ext"
     self.assertEqual(entry.name, "myname.ext")
     self.assertEqual(entry.path, "../this/is/somepath")
     self.assertEqual(entry.type, "ext")