forked from github.com/blag
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
595356e915 | ||
|
|
6005369108 | ||
|
|
db4e03afde | ||
|
|
877c47c391 | ||
|
|
3bd7125873 | ||
|
|
35f6ef05b6 |
@@ -1,5 +1,14 @@
|
||||
# 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
|
||||
|
||||
35
blag/blag.py
35
blag/blag.py
@@ -16,6 +16,8 @@ import feedgenerator
|
||||
|
||||
from blag.markdown import markdown_factory, convert_markdown
|
||||
from blag.devserver import serve
|
||||
from blag.version import __VERSION__
|
||||
from blag.quickstart import quickstart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(
|
||||
@@ -54,6 +56,11 @@ def parse_args(args=None):
|
||||
|
||||
"""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--version',
|
||||
action='version',
|
||||
version='%(prog)s '+__VERSION__,
|
||||
)
|
||||
|
||||
commands = parser.add_subparsers(dest='command')
|
||||
commands.required = True
|
||||
@@ -419,33 +426,5 @@ def generate_tags(articles, tags_template, tag_template, output_dir):
|
||||
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__':
|
||||
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.1'
|
||||
__VERSION__ = '1.3.2'
|
||||
|
||||
11
debian/changelog
vendored
11
debian/changelog
vendored
@@ -1,3 +1,14 @@
|
||||
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
|
||||
|
||||
@@ -9,3 +9,4 @@ API
|
||||
blag.blag
|
||||
blag.markdown
|
||||
blag.devserver
|
||||
blag.quickstart
|
||||
|
||||
@@ -277,3 +277,13 @@ foo bar
|
||||
|
||||
def test_main(cleandir):
|
||||
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
|
||||
|
||||
|
||||
@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", [
|
||||
('foo: bar', {'foo': 'bar'}),
|
||||
('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