示例#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 _handle_row(self, row):
        """
        handle a single row
        """

        try:
            # assume unix timestamp
            if not self._args.timestamp_format:
                timestamp = datetime.datetime.fromtimestamp(
                    int(row[self._args.timestamp_field]))
            else:
                timestamp = time.strptime(row[self._args.timestamp_field],
                                          self._args.timestamp_format)

            # show time with the timestamp format, but only
            # if it contains at least hours and minutes
            if not self._args.timestamp_format or \
             any(x in self._args.timestamp_format for x in ['%H', '%M']):
                timestamp = OrgFormat.datetime(timestamp)
            else:
                timestamp = OrgFormat.date(timestamp)

        except ValueError, e:
            logging.error("timestamp-format does not match: %s", e)
            sys.exit(1)
示例#4
0
文件: ical.py 项目: M1lan/Memacs
    def __get_datetime(self, mydate):
        """
        @return string: Datetime - in Org Format
        """
        mydate_tupel = OrgFormat.datetupelutctimestamp(mydate)

        return OrgFormat.date(mydate_tupel)
示例#5
0
    def __handle_file(self, file, rootdir):
        """
        handles a file
        """
        # don't handle emacs tmp files (file~)
        if file[-1:] == '~':
            return

        link = os.path.join(rootdir, file)
        logging.debug(link)

        if self._args.force_filedate_extraction:
            file_datetime = time.localtime(os.path.getmtime(link))

            if self._args.skip_filetime_extraction:
                orgdate = OrgFormat.date(file_datetime)
            else:
                orgdate = OrgFormat.datetime(file_datetime)

            self.__write_file(file, link, orgdate)

        elif DATESTAMP_REGEX.match(file):
            try:
                # we put this in a try block because:
                # if a timestamp is false i.e. 2011-14-19 or false time
                # we can handle those not easy with REGEX, therefore we have
                # an Exception TimestampParseException, which is thrown,
                # wen strptime (parse from string to time tupel) fails
                self.__parse_file(file, link)
            except TimestampParseException, e:
                logging.warning("False date(time) in file: %s", link)
示例#6
0
文件: ical.py 项目: serycjon/Memacs
    def __get_datetime(self, mydate):
        """
        @return string: Datetime - in Org Format
        """
        mydate_tupel = OrgFormat.datetupelutctimestamp(mydate)

        return OrgFormat.date(mydate_tupel)
示例#7
0
    def __getTimestamp(self, time, onlyDate=False):
        """
        converts xml timestamp into org readable timestamp
        Do  6 Nov 21:22:17 2014
        """
        time = time.strip().encode('utf-8')

        mail_date = datetime.strptime(time,"%c")
        if onlyDate is False:
            return OrgFormat.datetime(mail_date)
        return OrgFormat.date(mail_date)
示例#8
0
文件: mu.py 项目: njagadeesh/Memacs
    def __getTimestamp(self, time, onlyDate=False):
        """
        converts xml timestamp into org readable timestamp
        Do  6 Nov 21:22:17 2014
        """
        time = time.strip().encode('utf-8')

        mail_date = datetime.strptime(time,"%a %d %b %H:%M:%S %Y")
        if onlyDate is False:
            return OrgFormat.datetime(mail_date)
        return OrgFormat.date(mail_date)
示例#9
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)