Пример #1
0
def build_gallery_dl_conf_5(path=None):

    TEMPLATE = r"""
.TH "GALLERY-DL.CONF" "5" "%(date)s" "%(version)s" "gallery-dl Manual"
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l

.SH NAME
gallery-dl.conf \- gallery-dl configuration file

.SH DESCRIPTION
gallery-dl will search for configuration files in the following places
every time it is started, unless
.B --ignore-config
is specified:
.PP
.RS 4
.nf
.I /etc/gallery-dl.conf
.I $HOME/.config/gallery-dl/config.json
.I $HOME/.gallery-dl.conf
.fi
.RE
.PP
It is also possible to specify additional configuration files with the
.B -c/--config
command-line option or to add further option values with
.B -o/--option
as <key>=<value> pairs,

Configuration files are JSON-based and therefore don't allow any ordinary
comments, but, since unused keys are simply ignored, it is possible to utilize
those as makeshift comments by settings their values to arbitrary strings.

.SH EXAMPLE
{
.RS 4
"base-directory": "/tmp/",
.br
"extractor": {
.RS 4
"pixiv": {
.RS 4
"directory": ["Pixiv", "Works", "{user[id]}"],
.br
"filename": "{id}{num}.{extension}",
.br
"username": "******",
.br
"password": "******"
.RE
},
.br
"flickr": {
.RS 4
"_comment": "OAuth keys for account 'foobar'",
.br
"access-token": "0123456789-0123456789abcdef",
.br
"access-token-secret": "fedcba9876543210"
.RE
}
.RE
},
.br
"downloader": {
.RS 4
"retries": 3,
.br
"timeout": 2.5
.RE
}
.RE
}

%(options)s

.SH BUGS
https://github.com/mikf/gallery-dl/issues

.SH AUTHORS
Mike Fährmann <*****@*****.**>
.br
and https://github.com/mikf/gallery-dl/graphs/contributors

.SH "SEE ALSO"
.BR gallery-dl (1)
"""

    sections = parse_docs_configuration()
    content = []

    for sec_name, section in sections.items():
        content.append(".SH " + sec_name.upper())

        for opt_name, option in section.items():
            content.append(".SS " + opt_name)

            for field, text in option.items():
                if field in ("Type", "Default"):
                    content.append('.IP "{}:" {}'.format(
                        field,
                        len(field) + 2))
                    content.append(strip_rst(text))
                else:
                    content.append('.IP "{}:" 4'.format(field))
                    content.append(strip_rst(text, field != "Example"))

    if not path:
        path = util.path("data/man/gallery-dl.conf.5")
    with open(path, "w", encoding="utf-8") as file:
        file.write(
            TEMPLATE.lstrip() % {
                "options": "\n".join(content),
                "version": gallery_dl.version.__version__,
                "date": datetime.datetime.now().strftime("%Y-%m-%d"),
            })
Пример #2
0
def build_gallery_dl_conf_5(path=None):

    TEMPLATE = r"""
.TH "GALLERY-DL.CONF" "5" "%(date)s" "%(version)s" "gallery-dl Manual"
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l

.SH NAME
gallery-dl.conf \- gallery-dl configuration file

.SH DESCRIPTION
gallery-dl will search for configuration files in the following places
every time it is started, unless
.B --ignore-config
is specified:
.PP
.RS 4
.nf
.I /etc/gallery-dl.conf
.I $HOME/.config/gallery-dl/config.json
.I $HOME/.gallery-dl.conf
.fi
.RE
.PP
It is also possible to specify additional configuration files with the
.B -c/--config
command-line option or to add further option values with
.B -o/--option
as <key>=<value> pairs,

Configuration files are JSON-based and therefore don't allow any ordinary
comments, but, since unused keys are simply ignored, it is possible to utilize
those as makeshift comments by settings their values to arbitrary strings.

.SH EXAMPLE
{
.RS 4
"base-directory": "/tmp/",
.br
"extractor": {
.RS 4
"pixiv": {
.RS 4
"directory": ["Pixiv", "Works", "{user[id]}"],
.br
"filename": "{id}{num}.{extension}",
.br
"username": "******",
.br
"password": "******"
.RE
},
.br
"flickr": {
.RS 4
"_comment": "OAuth keys for account 'foobar'",
.br
"access-token": "0123456789-0123456789abcdef",
.br
"access-token-secret": "fedcba9876543210"
.RE
}
.RE
},
.br
"downloader": {
.RS 4
"retries": 3,
.br
"timeout": 2.5
.RE
}
.RE
}

%(options)s

.SH BUGS
https://github.com/mikf/gallery-dl/issues

.SH AUTHORS
Mike Fährmann <*****@*****.**>
.br
and https://github.com/mikf/gallery-dl/graphs/contributors

.SH "SEE ALSO"
.BR gallery-dl (1)
"""

    sections = parse_docs_configuration()
    content = []

    for sec_name, section in sections.items():
        content.append(".SH " + sec_name.upper())

        for opt_name, option in section.items():
            content.append(".SS " + opt_name)

            for field, text in option.items():
                if field in ("Type", "Default"):
                    content.append('.IP "{}:" {}'.format(field, len(field)+2))
                    content.append(strip_rst(text))
                else:
                    content.append('.IP "{}:" 4'.format(field))
                    content.append(strip_rst(text, field != "Example"))

    if not path:
        path = util.path("gallery-dl.conf.5")
    with open(path, "w", encoding="utf-8") as file:
        file.write(TEMPLATE.lstrip() % {
            "options": "\n".join(content),
            "version": gallery_dl.version.__version__,
            "date"   : datetime.datetime.now().strftime("%Y-%m-%d"),
        })