Пример #1
0
    def format_file(self, filepath):
        # weird buggy errors with watchdog where event is triggered twice
        if filepath == self.last_formatted and time.time(
        ) - self.time_formatted <= 40:
            return

        try:
            file_contents = open(filepath, "r").read()
        except FileNotFoundError:
            return

        # extract name of file
        split_path = filepath.replace(self.data_dir, "").split(SEP)
        file_title = split_path[-1].split(".")[0]
        directory = "/".join(split_path[0:-1])
        note_dataobj = {
            "title": file_title,
            "content": file_contents,
            "type": "note",
            "path": directory
        }

        dataobj = models.DataObj(**note_dataobj)
        dataobj.insert()

        self.last_formatted = filepath
        self.time_formatted = time.time()
        try:
            os.remove(filepath)
        except FileNotFoundError:
            return
Пример #2
0
    def format_file(self, filepath):
        # weird buggy errors with watchdog
        try:
            file_contents = open(filepath, "r").read()
        except FileNotFoundError:
            return
        # extract name of file
        split_path = filepath.replace(self.data_dir, "").split("/")
        file_title = split_path[-1].split(".")[0]
        directory = "/".join(split_path[0:-1])
        note_dataobj = {
                "title": file_title,
                "content": file_contents,
                "type": "note",
                "path": directory
            }

        dataobj = models.DataObj(**note_dataobj)
        dataobj.insert()
        try:
            os.remove(filepath)
        except FileNotFoundError:
            return