Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
|
cd40e283ac | ||
|
8f3ba1e55d | ||
|
960b18a461 | ||
|
db7565dcd0 | ||
|
1fe4f2df10 | ||
|
f361b9fd50 | ||
|
423897a9a3 | ||
|
c230c64680 | ||
|
92e9e9d4bb | ||
|
bc4c514cbb |
|
@ -1,10 +1,16 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "brewserverblocklist"
|
name = "brewserverblocklist"
|
||||||
version = "1.1.3"
|
version = "1.1.7"
|
||||||
description = "A python script to collect the server-wide blocklists from Friendica nodes to build a collection from trusted admin choice"
|
description = "A python script to collect the server-wide blocklists from Friendica nodes to build a collection from trusted admin choice"
|
||||||
authors = ["Tobias Diekershoff"]
|
authors = ["Tobias Diekershoff"]
|
||||||
license = "GNU General Public License v3.0"
|
license = "GNU General Public License v3.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
include = [
|
||||||
|
{ path = "src/brewserverblocklist" },
|
||||||
|
]
|
||||||
|
packages = [
|
||||||
|
{ include = "brewserverblocklist", from = "src"},
|
||||||
|
]
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
brewserverblocklist = "brewserverblocklist.brewserverblocklist:main"
|
brewserverblocklist = "brewserverblocklist.brewserverblocklist:main"
|
||||||
|
|
|
@ -14,6 +14,21 @@ import sys
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
class BParser(argparse.ArgumentParser):
|
||||||
|
"""
|
||||||
|
This expansion of the ArgParser class will display the --help results by
|
||||||
|
default if an error occurs (e.g. no arguments are passed to the script).
|
||||||
|
|
||||||
|
It is based on an StackOverflow answer from 2010 by unutbu who refered to
|
||||||
|
a reply from Steven Bethard as source of the code.
|
||||||
|
|
||||||
|
https://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argu/4042861#4042861
|
||||||
|
"""
|
||||||
|
def error(self, message):
|
||||||
|
sys.stderr.write('error: %s\n' % message)
|
||||||
|
self.print_help()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
class BrewBlocklist():
|
class BrewBlocklist():
|
||||||
"""
|
"""
|
||||||
This is the cauldron that is used to
|
This is the cauldron that is used to
|
||||||
|
@ -36,7 +51,6 @@ class BrewBlocklist():
|
||||||
config = configparser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.read(configfile)
|
config.read(configfile)
|
||||||
for section in config.sections():
|
for section in config.sections():
|
||||||
print(section)
|
|
||||||
section_values = dict(config.items(section))
|
section_values = dict(config.items(section))
|
||||||
if (section.find('http://') > -1) or (section.find('https://') > -1):
|
if (section.find('http://') > -1) or (section.find('https://') > -1):
|
||||||
print('The section name in the config file must not contain the protocol ({})'.format(section))
|
print('The section name in the config file must not contain the protocol ({})'.format(section))
|
||||||
|
@ -139,6 +153,12 @@ class BrewBlocklist():
|
||||||
orig_stdout = sys.stdout
|
orig_stdout = sys.stdout
|
||||||
sys.stdout = out_file
|
sys.stdout = out_file
|
||||||
for key, value in self.blocklist.items():
|
for key, value in self.blocklist.items():
|
||||||
|
try:
|
||||||
|
if ("," in self.reasons[key] or " " in self.reasons[key]) and not self.reasons[key].startswith('"'):
|
||||||
|
self.reasons[key] = '"{}"'.format(self.reasons[key])
|
||||||
|
except TypeError:
|
||||||
|
self.reasons[key] = '"no reason given"'
|
||||||
|
self.error.append("for {} no blocking reason was provided".format(key))
|
||||||
print('{}, {}, {}'.format(key, self.reasons[key], value))
|
print('{}, {}, {}'.format(key, self.reasons[key], value))
|
||||||
if self.outputfile:
|
if self.outputfile:
|
||||||
sys.stdout = orig_stdout
|
sys.stdout = orig_stdout
|
||||||
|
@ -157,7 +177,7 @@ def main():
|
||||||
* collect the ingredient
|
* collect the ingredient
|
||||||
* serve the result
|
* serve the result
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser()
|
parser = BParser()
|
||||||
parser.add_argument('-c', '--config',
|
parser.add_argument('-c', '--config',
|
||||||
dest='configfile',
|
dest='configfile',
|
||||||
required=True,
|
required=True,
|
||||||
|
|
Loading…
Reference in a new issue