How to use the javaproperties.writing.java_timestamp function in javaproperties

To help you get started, we’ve selected a few javaproperties examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jwodder / javaproperties / javaproperties / __main__.py View on Github external
def select(ctx, default_value, defaults, escaped, separator, file, key,
           encoding, outfile):
    """ Extract key-value pairs from a Java .properties file """
    ok = True
    with click.open_file(outfile, 'w', encoding=encoding) as fpout:
        print(to_comment(java_timestamp()), file=fpout)
        for k,v in getselect(file, key, defaults, default_value, encoding,
                             escaped):
            if v is None:
                click.echo(u'javaproperties: {0}: key not found'.format(k),
                           err=True)
                ok = False
            else:
                print(join_key_value(k, v, separator=separator), file=fpout)
    ctx.exit(0 if ok else 1)
github jwodder / javaproperties / javaproperties / __main__.py View on Github external
if in_header:
            if k is None:
                if prevsrc is not None:
                    print(prevsrc, end='', file=fpout)
                prevsrc = src
                continue
            else:
                if prevsrc is not None:
                    if preserve_timestamp:
                        print(prevsrc, end='', file=fpout)
                    else:
                        if not re.match(TIMESTAMP_RGX, prevsrc, flags=re.U):
                            print(prevsrc, end='', file=fpout)
                        print(to_comment(java_timestamp()), file=fpout)
                elif not preserve_timestamp:
                    print(to_comment(java_timestamp()), file=fpout)
                in_header = False
        if k in newprops:
            if newprops[k] is not None:
                print(join_key_value(k, newprops[k], separator=separator),
                      file=fpout)
                newprops[k] = None
        else:
            # In case the last line of the file ends with a trailing line
            # continuation:
            src = re.sub(r'(?
github jwodder / javaproperties / javaproperties / __main__.py View on Github external
prevsrc = None
    for k, _, src in parse(fpin):
        if in_header:
            if k is None:
                if prevsrc is not None:
                    print(prevsrc, end='', file=fpout)
                prevsrc = src
                continue
            else:
                if prevsrc is not None:
                    if preserve_timestamp:
                        print(prevsrc, end='', file=fpout)
                    else:
                        if not re.match(TIMESTAMP_RGX, prevsrc, flags=re.U):
                            print(prevsrc, end='', file=fpout)
                        print(to_comment(java_timestamp()), file=fpout)
                elif not preserve_timestamp:
                    print(to_comment(java_timestamp()), file=fpout)
                in_header = False
        if k in newprops:
            if newprops[k] is not None:
                print(join_key_value(k, newprops[k], separator=separator),
                      file=fpout)
                newprops[k] = None
        else:
            # In case the last line of the file ends with a trailing line
            # continuation:
            src = re.sub(r'(?
github jwodder / javaproperties / javaproperties / propfile.py View on Github external
def timestamp(self, value):
        if value is not None and value is not False:
            if not isinstance(value, six.string_types):
                value = java_timestamp(value)
            comments = [
                Comment(c) for c in ascii_splitlines(to_comment(value) + '\n')
            ]
        else:
            comments = []
        for n in self._lines.iternodes():
            if isinstance(n.value, Comment) and n.value.is_timestamp():
                if comments:
                    n.value = comments[0]
                    for c in comments[1:]:
                        n = n.insert_after(c)
                else:
                    n.unlink()
                return
            elif isinstance(n.value, KeyValue):
                for c in comments: