示例#1
0
文件: Journal.py 项目: SawnaMC/jrnl
 def write(self):
     """Writes only the entries that have been modified into plist files."""
     for entry in self.entries:
         if entry.modified:
             if not hasattr(entry, "uuid"):
                 entry.uuid = uuid.uuid1().hex
             utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
             filename = os.path.join(self.config['journal'], "entries", entry.uuid+".doentry")
             entry_plist = {
                 'Creation Date': utc_time,
                 'Starred': entry.starred if hasattr(entry, 'starred') else False,
                 'Entry Text': entry.title+"\n"+entry.body,
                 'Time Zone': util.get_local_timezone(),
                 'UUID': entry.uuid,
                 'Tags': [tag.strip(self.config['tagsymbols']) for tag in entry.tags]
             }
             plistlib.writePlist(entry_plist, filename)
     for entry in self._deleted_entries:
         filename = os.path.join(self.config['journal'], "entries", entry.uuid+".doentry")
         os.remove(filename)
示例#2
0
文件: Journal.py 项目: SawnaMC/jrnl
 def open(self):
     filenames = [os.path.join(self.config['journal'], "entries", f) for f in os.listdir(os.path.join(self.config['journal'], "entries"))]
     self.entries = []
     for filename in filenames:
         with open(filename, 'rb') as plist_entry:
             dict_entry = plistlib.readPlist(plist_entry)
             try:
                 timezone = pytz.timezone(dict_entry['Time Zone'])
             except (KeyError, pytz.exceptions.UnknownTimeZoneError):
                 timezone = pytz.timezone(util.get_local_timezone())
             date = dict_entry['Creation Date']
             date = date + timezone.utcoffset(date)
             raw = dict_entry['Entry Text']
             sep = re.search("[\n!?.]+", raw)
             title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "")
             entry = Entry.Entry(self, date, title, body, starred=dict_entry["Starred"])
             entry.uuid = dict_entry["UUID"]
             entry.tags = dict_entry.get("Tags", [])
             self.entries.append(entry)
     self.sort()
示例#3
0
    def write(self):
        """Writes only the entries that have been modified into plist files."""
        for entry in self.entries:
            # Assumption: since jrnl can not manipulate existing entries, all entries
            # that have a uuid will be old ones, and only the one that doesn't will
            # have a new one!
            if not hasattr(entry, "uuid"):
                utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
                new_uuid = uuid.uuid1().hex
                filename = os.path.join(self.config['journal'], "entries", new_uuid+".doentry")
                entry_plist = {
                    'Creation Date': utc_time,
                    'Starred': entry.starred if hasattr(entry, 'starred') else False,
                    'Entry Text': entry.title+"\n"+entry.body,
                    'Time Zone': util.get_local_timezone(),
                    'UUID': new_uuid,
                    'Tags': [tag.strip(self.config['tagsymbols']) for tag in entry.tags]
                }
                # print entry_plist

                plistlib.writePlist(entry_plist, filename)
示例#4
0
 def parse(self, filenames):
     """Instead of parsing a string into an entry, this method will take a list
     of filenames, interpret each as a plist file and create a new entry from that."""
     self.entries = []
     for filename in filenames:
         with open(filename, 'rb') as plist_entry:
             dict_entry = plistlib.readPlist(plist_entry)
             try:
                 timezone = pytz.timezone(dict_entry['Time Zone'])
             except (KeyError, pytz.exceptions.UnknownTimeZoneError):
                 timezone = pytz.timezone(util.get_local_timezone())
             date = dict_entry['Creation Date']
             date = date + timezone.utcoffset(date)
             entry = self.new_entry(raw=dict_entry['Entry Text'], date=date, sort=False)
             entry.starred = dict_entry["Starred"]
             entry.uuid = dict_entry["UUID"]
             entry.tags = dict_entry.get("Tags", [])
     # We're using new_entry to create the Entry object, which adds the entry
     # to self.entries already. However, in the original Journal.__init__, this
     # method is expected to return a list of newly created entries, which is why
     # we're returning the obvious.
     return self.entries