示例#1
0
    def __parse_and_write_file(self, file, link):
        """
        Parses the date+time and writes entry to outputfile

        @param file: filename
        @param link: path
        """
        if TIMESTAMP_REGEX.match(file):
            # if we found a timestamp too,take hours,min
            # and optionally seconds from this timestamp
            timestamp = TIMESTAMP_REGEX.match(file).group()
            orgdate = OrgFormat.strdatetimeiso8601(timestamp)
            logging.debug("found timestamp: " + orgdate)
        else:
            datestamp = DATESTAMP_REGEX.match(file).group()
            orgdate = OrgFormat.strdate(datestamp)
            orgdate_time_tupel = OrgFormat.datetupeliso8601(datestamp)
            file_datetime = time.localtime(os.path.getmtime(link))
            # check if the file - time information matches year,month,day,
            # then update time
            if file_datetime.tm_year == orgdate_time_tupel.tm_year and \
                    file_datetime.tm_mon == orgdate_time_tupel.tm_mon and \
                    file_datetime.tm_mday == orgdate_time_tupel.tm_mday:
                logging.debug("found a time in file.setting %s-->%s", orgdate,
                              OrgFormat.date(file_datetime, True))
                orgdate = OrgFormat.date(file_datetime, True)

        # write entry to org file
        output = OrgFormat.link(link=link, description=file)
        # we need optional data for hashing due it can be, that more
        # than one file have the same timestamp
        properties = OrgProperties(data_for_hashing=output)
        self._writer.write_org_subitem(timestamp=orgdate,
                                       output=output,
                                       properties=properties)
示例#2
0
    def __parse_and_write_file(self, file, link):
        """
        Parses the date+time and writes entry to outputfile

        @param file: filename
        @param link: path
        """
        if TIMESTAMP_REGEX.match(file):
            # if we found a timestamp too,take hours,min
            # and optionally seconds from this timestamp
            timestamp = TIMESTAMP_REGEX.match(file).group()
            orgdate = OrgFormat.strdatetimeiso8601(timestamp)
            logging.debug("found timestamp: " + orgdate)
        else:
            datestamp = DATESTAMP_REGEX.match(file).group()
            orgdate = OrgFormat.strdate(datestamp)
            orgdate_time_tupel = OrgFormat.datetupeliso8601(datestamp)
            file_datetime = time.localtime(os.path.getmtime(link))
            # check if the file - time information matches year,month,day,
            # then update time
            if file_datetime.tm_year == orgdate_time_tupel.tm_year and \
                    file_datetime.tm_mon == orgdate_time_tupel.tm_mon and \
                    file_datetime.tm_mday == orgdate_time_tupel.tm_mday:
                logging.debug("found a time in file.setting %s-->%s",
                              orgdate, OrgFormat.date(file_datetime, True))
                orgdate = OrgFormat.date(file_datetime, True)

        # write entry to org file
        output = OrgFormat.link(link=link, description=file)
        # we need optional data for hashing due it can be, that more
        # than one file have the same timestamp
        properties = OrgProperties(data_for_hashing=output)
        self._writer.write_org_subitem(timestamp=orgdate,
                                       output=output,
                                       properties=properties)
示例#3
0
    def __parse_file(self, file, link):
        """
        Parses the date+time and writes entry to outputfile

        @param file: filename
        @param link: path
        """
        if TIMESTAMP_REGEX.match(file):
            # if we found a timestamp too,take hours,min
            # and optionally seconds from this timestamp
            timestamp = TIMESTAMP_REGEX.match(file).group()
            orgdate = OrgFormat.strdatetimeiso8601(timestamp)
            logging.debug("found timestamp: " + orgdate)
        else:
            datestamp = DATESTAMP_REGEX.match(file).group()
            orgdate = OrgFormat.strdate(datestamp)
            orgdate_time_tupel = OrgFormat.datetupeliso8601(datestamp)

            if self._args.skip_filetime_extraction != True:

                if os.path.exists(link):
                    file_datetime = time.localtime(os.path.getmtime(link))
                    # check if the file - time information matches year,month,day,
                    # then update time
                    if file_datetime.tm_year == orgdate_time_tupel.tm_year and \
                        file_datetime.tm_mon == orgdate_time_tupel.tm_mon and \
                        file_datetime.tm_mday == orgdate_time_tupel.tm_mday:

                        logging.debug("found a time in file.setting %s-->%s",
                                      orgdate,
                                      OrgFormat.date(file_datetime, True))
                        orgdate = OrgFormat.date(file_datetime, True)
                else:
                    logging.debug(
                        "item [%s] not found and thus could not determine mtime"
                        % link)

        self.__write_file(file, link, orgdate)
示例#4
0
    def __write(self):
        """
        write attributes to writer (make an org_sub_item)
        """
        logging.debug("msg:%s", self.__msg)

        #getting tags
        if self.__attrtags:
            tags = self.__attrtags
            if self.__split:
                tags = tags.split(self.__split)
            else:
                tags = tags.split(' ')
            tags = tags[1:]
        elif self.__taging:
            tags = self.__taging
            if self.__split:
                tags = tags.split(self.__split)
            else:
                tags = tags.split(' ')
        else:
            tags = []
        for item in tags:
            if item == '':
                tags.remove(item)

        #getting output
        if not self.__attroutput:
            output = "%s: %s" % (self.__author, self.__msg)
        else:
            output = self.__attroutput

        part = output.split(" ")
        output = ""
        for item in part:
            if re.search("http[s]?://", item) != None:
                unformatted_link = item
                short_link = OrgFormat.link(unformatted_link, "link")
                output = output + " " + short_link + ": " + item
            else:
                output = output + " " + item
        output = output[1:]

        #getting properties
        if not self.__attrproperties:
            properties = OrgProperties(data_for_hashing=self.__author \
                                       + self.__msg + self.__date)
        else:
            properties = OrgProperties(data_for_hashing=self.__attrproperties)

        #getting notes
        if self.__attrnote:
            notes = self.__attrnote
        elif self.__notes:
            notes = self.__notes
        else:
            notes = ""

        if notes:
            parts = notes.split(" ")
            notes = ""
            for item in parts:
                if re.search("http[s]?://", item) != None:
                    unformatted_link = item
                    short_link = OrgFormat.link(unformatted_link,
                                                "link")
                    notes = notes + " " + short_link + ": " + item
                else:
                    notes = notes + " " + item
            notes = notes[1:]

        #prepare for most time formats + getting timestamp
        if self.__attrtime:
            self.__date = self.attrtime

        try:
            if (self.__time == 'YYYYMMDD' or self.__time == 'YYYY'
                or self.__time == 'YYYYMMDDTHHMMSSZ'
                or self.__time == 'YYYYMMDDTHHMMSST'):
                timestamp = OrgFormat.datetime(
                                      OrgFormat.datetupelutctimestamp(
                                      self.__date))
            elif (self.__time == ('YYYY-MM-DD')):
                timestamp = OrgFormat.datetime(
                                      OrgFormat.datetupeliso8601(
                                      self.__date))
            elif (self.__time == 'YYYY-MM-DDTHH.MM.SS' or
                  self.__time == 'YYYY-MM-DDTHH.MM'):
                timestamp = OrgFormat.datetime(
                                      OrgFormat.datetimetupeliso8601(
                                      self.__date))
            elif (self.__time == 'timetuple'):
                time_tupel = time.localtime(time.mktime(
                                            parsedate(self.__date)))
                timestamp = OrgFormat.datetime(time_tupel)

        except:
                logging.debug("Write functione @timestamp timestamp=%s",
                              self.__date)
                logging.error("A timestamp problem occured")
                sys.exit(2)
        self._writer.write_org_subitem(output=output,
                                       timestamp=timestamp,
                                       note=notes,
                                       tags=tags,
                                       properties=properties)