mirror of
https://github.com/venthur/blag.git
synced 2025-11-26 13:13:06 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
595356e915 | ||
|
|
6005369108 | ||
|
|
db4e03afde | ||
|
|
877c47c391 | ||
|
|
3bd7125873 | ||
|
|
35f6ef05b6 | ||
|
|
7e8f2a5b9a | ||
|
|
d942bf150c | ||
|
|
48cfb49acb | ||
|
|
c3edbeb511 | ||
|
|
a60887e0d6 |
4
.github/workflows/python-package.yaml
vendored
4
.github/workflows/python-package.yaml
vendored
@@ -17,8 +17,8 @@ jobs:
|
|||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
python-version:
|
python-version:
|
||||||
- 3.8
|
- "3.8"
|
||||||
- 3.9
|
- "3.9"
|
||||||
- "3.10"
|
- "3.10"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,6 +5,9 @@ build/
|
|||||||
dist/
|
dist/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
|
|
||||||
|
docs/_build/
|
||||||
|
docs/api/
|
||||||
|
|
||||||
htmlcov/
|
htmlcov/
|
||||||
.coverage
|
.coverage
|
||||||
|
|
||||||
|
|||||||
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,5 +1,18 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.3.2] - 2022-06-29
|
||||||
|
|
||||||
|
* Added --version option
|
||||||
|
* Improved quickstart:
|
||||||
|
* respective default answers will be written to config if user provided no
|
||||||
|
answer
|
||||||
|
* added tests for quickstart
|
||||||
|
* Added some test cases for the MarkdownLinktreeProcessor
|
||||||
|
|
||||||
|
## [1.3.1] - 2022-06-10
|
||||||
|
|
||||||
|
* fixed man page
|
||||||
|
|
||||||
## [1.3.0] - 2022-06-09
|
## [1.3.0] - 2022-06-09
|
||||||
|
|
||||||
* debianized package
|
* debianized package
|
||||||
|
|||||||
1
Makefile
1
Makefile
@@ -46,6 +46,7 @@ clean:
|
|||||||
rm -rf build dist *.egg-info
|
rm -rf build dist *.egg-info
|
||||||
rm -rf $(VENV)
|
rm -rf $(VENV)
|
||||||
rm -rf $(DOCS_OUT)
|
rm -rf $(DOCS_OUT)
|
||||||
|
rm -rf $(DOCS_SRC)/api
|
||||||
find . -type f -name *.pyc -delete
|
find . -type f -name *.pyc -delete
|
||||||
find . -type d -name __pycache__ -delete
|
find . -type d -name __pycache__ -delete
|
||||||
# coverage
|
# coverage
|
||||||
|
|||||||
35
blag/blag.py
35
blag/blag.py
@@ -16,6 +16,8 @@ import feedgenerator
|
|||||||
|
|
||||||
from blag.markdown import markdown_factory, convert_markdown
|
from blag.markdown import markdown_factory, convert_markdown
|
||||||
from blag.devserver import serve
|
from blag.devserver import serve
|
||||||
|
from blag.version import __VERSION__
|
||||||
|
from blag.quickstart import quickstart
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@@ -54,6 +56,11 @@ def parse_args(args=None):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
'--version',
|
||||||
|
action='version',
|
||||||
|
version='%(prog)s '+__VERSION__,
|
||||||
|
)
|
||||||
|
|
||||||
commands = parser.add_subparsers(dest='command')
|
commands = parser.add_subparsers(dest='command')
|
||||||
commands.required = True
|
commands.required = True
|
||||||
@@ -419,33 +426,5 @@ def generate_tags(articles, tags_template, tag_template, output_dir):
|
|||||||
fh.write(result)
|
fh.write(result)
|
||||||
|
|
||||||
|
|
||||||
def quickstart(args):
|
|
||||||
"""Quickstart.
|
|
||||||
|
|
||||||
This method asks the user some questions and generates a
|
|
||||||
configuration file that is needed in order to run blag.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
args : argparse.Namespace
|
|
||||||
|
|
||||||
"""
|
|
||||||
base_url = input("Hostname (and path) to the root? "
|
|
||||||
"[https://example.com/]: ")
|
|
||||||
title = input("Title of your website? ")
|
|
||||||
description = input("Description of your website [John Doe's Blog]? ")
|
|
||||||
author = input("Author of your website [John Doe]? ")
|
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config['main'] = {
|
|
||||||
'base_url': base_url,
|
|
||||||
'title': title,
|
|
||||||
'description': description,
|
|
||||||
'author': author,
|
|
||||||
}
|
|
||||||
with open('config.ini', 'w') as fh:
|
|
||||||
config.write(fh)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
68
blag/quickstart.py
Normal file
68
blag/quickstart.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
"""Helper methods for blag's quickstart command.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
|
def get_input(question, default):
|
||||||
|
"""Prompt for user input.
|
||||||
|
|
||||||
|
This is a wrapper around the input-builtin. It will show the default answer
|
||||||
|
in the prompt and -- if no answer was given -- use the default.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
question : str
|
||||||
|
the question the user is presented
|
||||||
|
default : str
|
||||||
|
the default value that will be used if no answer was given
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
str
|
||||||
|
|
||||||
|
"""
|
||||||
|
reply = input(f"{question} [{default}]: ")
|
||||||
|
if not reply:
|
||||||
|
reply = default
|
||||||
|
return reply
|
||||||
|
|
||||||
|
|
||||||
|
def quickstart(args):
|
||||||
|
"""Quickstart.
|
||||||
|
|
||||||
|
This method asks the user some questions and generates a
|
||||||
|
configuration file that is needed in order to run blag.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
args : argparse.Namespace
|
||||||
|
|
||||||
|
"""
|
||||||
|
base_url = get_input(
|
||||||
|
"Hostname (and path) to the root?",
|
||||||
|
"https://example.com/",
|
||||||
|
)
|
||||||
|
title = get_input(
|
||||||
|
"Title of your website?",
|
||||||
|
"My little blog",
|
||||||
|
)
|
||||||
|
description = get_input(
|
||||||
|
"Description of your website?",
|
||||||
|
"John Doe's Blog",
|
||||||
|
)
|
||||||
|
author = get_input(
|
||||||
|
"Author of your website",
|
||||||
|
"John Doe",
|
||||||
|
)
|
||||||
|
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config['main'] = {
|
||||||
|
'base_url': base_url,
|
||||||
|
'title': title,
|
||||||
|
'description': description,
|
||||||
|
'author': author,
|
||||||
|
}
|
||||||
|
with open('config.ini', 'w') as fh:
|
||||||
|
config.write(fh)
|
||||||
@@ -1 +1 @@
|
|||||||
__VERSION__ = '1.3.0'
|
__VERSION__ = '1.3.2'
|
||||||
|
|||||||
6
debian/README.Debian
vendored
6
debian/README.Debian
vendored
@@ -1,6 +0,0 @@
|
|||||||
blag for Debian
|
|
||||||
--------------
|
|
||||||
|
|
||||||
<Possible notes regarding this package - if none, delete this file.>
|
|
||||||
|
|
||||||
-- Bastian Venthur <venthur@debian.org> Sun, 05 Jun 2022 15:20:48 +0200
|
|
||||||
1
debian/blag.install
vendored
Normal file
1
debian/blag.install
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
build/man/blag.1 /usr/share/man/man1
|
||||||
17
debian/changelog
vendored
17
debian/changelog
vendored
@@ -1,3 +1,20 @@
|
|||||||
|
blag (1.3.2) unstable; urgency=medium
|
||||||
|
|
||||||
|
* Added --version option
|
||||||
|
* Improved quickstart:
|
||||||
|
* respective default answers will be written to config if user provided no
|
||||||
|
answer
|
||||||
|
* added tests for quickstart
|
||||||
|
* Added some test cases for the MarkdownLinktreeProcessor
|
||||||
|
|
||||||
|
-- Bastian Venthur <venthur@debian.org> Wed, 29 Jun 2022 21:27:15 +0200
|
||||||
|
|
||||||
|
blag (1.3.1) unstable; urgency=medium
|
||||||
|
|
||||||
|
* re-upload with man pages
|
||||||
|
|
||||||
|
-- Bastian Venthur <venthur@debian.org> Fri, 10 Jun 2022 07:26:19 +0200
|
||||||
|
|
||||||
blag (1.3.0) unstable; urgency=medium
|
blag (1.3.0) unstable; urgency=medium
|
||||||
|
|
||||||
* Initial release. Closes: #1012584
|
* Initial release. Closes: #1012584
|
||||||
|
|||||||
56
debian/manpage.1.ex
vendored
56
debian/manpage.1.ex
vendored
@@ -1,56 +0,0 @@
|
|||||||
.\" Hey, EMACS: -*- nroff -*-
|
|
||||||
.\" (C) Copyright 2022 Bastian Venthur <venthur@debian.org>,
|
|
||||||
.\"
|
|
||||||
.\" First parameter, NAME, should be all caps
|
|
||||||
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
|
|
||||||
.\" other parameters are allowed: see man(7), man(1)
|
|
||||||
.TH Blag SECTION "June 5 2022"
|
|
||||||
.\" Please adjust this date whenever revising the manpage.
|
|
||||||
.\"
|
|
||||||
.\" Some roff macros, for reference:
|
|
||||||
.\" .nh disable hyphenation
|
|
||||||
.\" .hy enable hyphenation
|
|
||||||
.\" .ad l left justify
|
|
||||||
.\" .ad b justify to both left and right margins
|
|
||||||
.\" .nf disable filling
|
|
||||||
.\" .fi enable filling
|
|
||||||
.\" .br insert line break
|
|
||||||
.\" .sp <n> insert n+1 empty lines
|
|
||||||
.\" for manpage-specific macros, see man(7)
|
|
||||||
.SH NAME
|
|
||||||
blag \- program to do something
|
|
||||||
.SH SYNOPSIS
|
|
||||||
.B blag
|
|
||||||
.RI [ options ] " files" ...
|
|
||||||
.br
|
|
||||||
.B bar
|
|
||||||
.RI [ options ] " files" ...
|
|
||||||
.SH DESCRIPTION
|
|
||||||
This manual page documents briefly the
|
|
||||||
.B blag
|
|
||||||
and
|
|
||||||
.B bar
|
|
||||||
commands.
|
|
||||||
.PP
|
|
||||||
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
|
|
||||||
.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
|
|
||||||
.\" respectively.
|
|
||||||
\fBblag\fP is a program that...
|
|
||||||
.SH OPTIONS
|
|
||||||
These programs follow the usual GNU command line syntax, with long
|
|
||||||
options starting with two dashes ('-').
|
|
||||||
A summary of options is included below.
|
|
||||||
For a complete description, see the Info files.
|
|
||||||
.TP
|
|
||||||
.B \-h, \-\-help
|
|
||||||
Show summary of options.
|
|
||||||
.TP
|
|
||||||
.B \-v, \-\-version
|
|
||||||
Show version of program.
|
|
||||||
.SH SEE ALSO
|
|
||||||
.BR bar (1),
|
|
||||||
.BR baz (1).
|
|
||||||
.br
|
|
||||||
The programs are documented fully by
|
|
||||||
.IR "The Rise and Fall of a Fooish Bar" ,
|
|
||||||
available via the Info system.
|
|
||||||
126
debian/manpage.md.ex
vendored
126
debian/manpage.md.ex
vendored
@@ -1,126 +0,0 @@
|
|||||||
% blag(SECTION) | User Commands
|
|
||||||
%
|
|
||||||
% "June 5 2022"
|
|
||||||
|
|
||||||
[comment]: # The lines above form a Pandoc metadata block. They must be
|
|
||||||
[comment]: # the first ones in the file.
|
|
||||||
[comment]: # See https://pandoc.org/MANUAL.html#metadata-blocks for details.
|
|
||||||
|
|
||||||
[comment]: # pandoc -s -f markdown -t man package.md -o package.1
|
|
||||||
[comment]: #
|
|
||||||
[comment]: # A manual page package.1 will be generated. You may view the
|
|
||||||
[comment]: # manual page with: nroff -man package.1 | less. A typical entry
|
|
||||||
[comment]: # in a Makefile or Makefile.am is:
|
|
||||||
[comment]: #
|
|
||||||
[comment]: # package.1: package.md
|
|
||||||
[comment]: # pandoc --standalone --from=markdown --to=man $< --output=$@
|
|
||||||
[comment]: #
|
|
||||||
[comment]: # The pandoc binary is found in the pandoc package. Please remember
|
|
||||||
[comment]: # that if you create the nroff version in one of the debian/rules
|
|
||||||
[comment]: # file targets, such as build, you will need to include pandoc in
|
|
||||||
[comment]: # your Build-Depends control field.
|
|
||||||
|
|
||||||
[comment]: # Remove the lines starting with '[comment]:' in this file in order
|
|
||||||
[comment]: # to avoid warning messages from pandoc.
|
|
||||||
|
|
||||||
# NAME
|
|
||||||
|
|
||||||
blag - program to do something
|
|
||||||
|
|
||||||
# SYNOPSIS
|
|
||||||
|
|
||||||
**blag** **-e** _this_ [**\-\-example=that**] [{**-e** | **\-\-example**} _this_]
|
|
||||||
[{**-e** | **\-\-example**} {_this_ | _that_}]
|
|
||||||
|
|
||||||
**blag** [{**-h** | *\-\-help**} | {**-v** | **\-\-version**}]
|
|
||||||
|
|
||||||
# DESCRIPTION
|
|
||||||
|
|
||||||
This manual page documents briefly the **blag** and **bar** commands.
|
|
||||||
|
|
||||||
This manual page was written for the Debian distribution because the
|
|
||||||
original program does not have a manual page. Instead, it has documentation
|
|
||||||
in the GNU info(1) format; see below.
|
|
||||||
|
|
||||||
**blag** is a program that...
|
|
||||||
|
|
||||||
# OPTIONS
|
|
||||||
|
|
||||||
The program follows the usual GNU command line syntax, with long options
|
|
||||||
starting with two dashes ('-'). A summary of options is included below. For
|
|
||||||
a complete description, see the **info**(1) files.
|
|
||||||
|
|
||||||
**-e** _this_, **\-\-example=**_that_
|
|
||||||
: Does this and that.
|
|
||||||
|
|
||||||
**-h**, **\-\-help**
|
|
||||||
: Show summary of options.
|
|
||||||
|
|
||||||
**-v**, **\-\-version**
|
|
||||||
: Show version of program.
|
|
||||||
|
|
||||||
# FILES
|
|
||||||
|
|
||||||
/etc/foo.conf
|
|
||||||
: The system-wide configuration file to control the behaviour of
|
|
||||||
blag. See **foo.conf**(5) for further details.
|
|
||||||
|
|
||||||
${HOME}/.foo.conf
|
|
||||||
: The per-user configuration file to control the behaviour of
|
|
||||||
blag. See **foo.conf**(5) for further details.
|
|
||||||
|
|
||||||
# ENVIRONMENT
|
|
||||||
|
|
||||||
**FOO_CONF**
|
|
||||||
: If used, the defined file is used as configuration file (see also
|
|
||||||
the section called “FILES”).
|
|
||||||
|
|
||||||
# DIAGNOSTICS
|
|
||||||
|
|
||||||
The following diagnostics may be issued on stderr:
|
|
||||||
|
|
||||||
Bad configuration file. Exiting.
|
|
||||||
: The configuration file seems to contain a broken configuration
|
|
||||||
line. Use the **\-\-verbose** option, to get more info.
|
|
||||||
|
|
||||||
**blag** provides some return codes, that can be used in scripts:
|
|
||||||
|
|
||||||
Code Diagnostic
|
|
||||||
0 Program exited successfully.
|
|
||||||
1 The configuration file seems to be broken.
|
|
||||||
|
|
||||||
# BUGS
|
|
||||||
|
|
||||||
The program is currently limited to only work with the foobar library.
|
|
||||||
|
|
||||||
The upstream BTS can be found at http://bugzilla.foo.tld.
|
|
||||||
|
|
||||||
# SEE ALSO
|
|
||||||
|
|
||||||
**bar**(1), **baz**(1), **foo.conf**(5)
|
|
||||||
|
|
||||||
The programs are documented fully by The Rise and Fall of a Fooish Bar
|
|
||||||
available via the **info**(1) system.
|
|
||||||
|
|
||||||
# AUTHOR
|
|
||||||
|
|
||||||
Bastian Venthur <venthur@debian.org>
|
|
||||||
: Wrote this manpage for the Debian system.
|
|
||||||
|
|
||||||
# COPYRIGHT
|
|
||||||
|
|
||||||
Copyright © 2007 Bastian Venthur
|
|
||||||
|
|
||||||
This manual page was written for the Debian system (and may be used by
|
|
||||||
others).
|
|
||||||
|
|
||||||
Permission is granted to copy, distribute and/or modify this document under
|
|
||||||
the terms of the GNU General Public License, Version 2 or (at your option)
|
|
||||||
any later version published by the Free Software Foundation.
|
|
||||||
|
|
||||||
On Debian systems, the complete text of the GNU General Public License
|
|
||||||
can be found in /usr/share/common-licenses/GPL.
|
|
||||||
|
|
||||||
[comment]: # Local Variables:
|
|
||||||
[comment]: # mode: markdown
|
|
||||||
[comment]: # End:
|
|
||||||
4
debian/rules
vendored
4
debian/rules
vendored
@@ -21,5 +21,5 @@ execute_after_dh_auto_build-indep: export https_proxy=127.0.0.1:9
|
|||||||
execute_after_dh_auto_build-indep:
|
execute_after_dh_auto_build-indep:
|
||||||
PYTHONPATH=. python3 -m sphinx -N -bhtml \
|
PYTHONPATH=. python3 -m sphinx -N -bhtml \
|
||||||
docs/ build/html # HTML generator
|
docs/ build/html # HTML generator
|
||||||
# PYTHONPATH=. python3 -m sphinx -N -bman \
|
PYTHONPATH=. python3 -m sphinx -N -bman \
|
||||||
# docs/ build/man # Manpage generator
|
docs/ build/man # Manpage generator
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ API
|
|||||||
blag.blag
|
blag.blag
|
||||||
blag.markdown
|
blag.markdown
|
||||||
blag.devserver
|
blag.devserver
|
||||||
|
blag.quickstart
|
||||||
|
|||||||
@@ -277,3 +277,13 @@ foo bar
|
|||||||
|
|
||||||
def test_main(cleandir):
|
def test_main(cleandir):
|
||||||
blag.main(['build'])
|
blag.main(['build'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_version(capsys):
|
||||||
|
with pytest.raises(SystemExit) as ex:
|
||||||
|
blag.main(['--version'])
|
||||||
|
# normal system exit
|
||||||
|
assert ex.value.code == 0
|
||||||
|
# proper version reported
|
||||||
|
out, _ = capsys.readouterr()
|
||||||
|
assert blag.__VERSION__ in out
|
||||||
|
|||||||
@@ -32,6 +32,20 @@ def test_convert_markdown_links(input_, expected):
|
|||||||
assert expected in html
|
assert expected in html
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("input_, expected", [
|
||||||
|
# scheme
|
||||||
|
('[test](https://)', 'https://'),
|
||||||
|
# netloc
|
||||||
|
('[test](//test.md)', '//test.md'),
|
||||||
|
# no path
|
||||||
|
('[test]()', ''),
|
||||||
|
])
|
||||||
|
def test_dont_convert_normal_links(input_, expected):
|
||||||
|
md = markdown_factory()
|
||||||
|
html, _ = convert_markdown(md, input_)
|
||||||
|
assert expected in html
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("input_, expected", [
|
@pytest.mark.parametrize("input_, expected", [
|
||||||
('foo: bar', {'foo': 'bar'}),
|
('foo: bar', {'foo': 'bar'}),
|
||||||
('foo: those are several words', {'foo': 'those are several words'}),
|
('foo: those are several words', {'foo': 'those are several words'}),
|
||||||
|
|||||||
24
tests/test_quickstart.py
Normal file
24
tests/test_quickstart.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from blag.quickstart import get_input, quickstart
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_input_default_answer(monkeypatch):
|
||||||
|
monkeypatch.setattr('builtins.input', lambda x: '')
|
||||||
|
answer = get_input("foo", "bar")
|
||||||
|
assert answer == 'bar'
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_input(monkeypatch):
|
||||||
|
monkeypatch.setattr('builtins.input', lambda x: 'baz')
|
||||||
|
answer = get_input("foo", "bar")
|
||||||
|
assert answer == 'baz'
|
||||||
|
|
||||||
|
|
||||||
|
def test_quickstart(cleandir, monkeypatch):
|
||||||
|
monkeypatch.setattr('builtins.input', lambda x: 'foo')
|
||||||
|
quickstart(None)
|
||||||
|
with open('config.ini', 'r') as fh:
|
||||||
|
data = fh.read()
|
||||||
|
assert 'base_url = foo' in data
|
||||||
|
assert 'title = foo' in data
|
||||||
|
assert 'description = foo' in data
|
||||||
|
assert 'author = foo' in data
|
||||||
Reference in New Issue
Block a user