Reformatted code base using black.

This commit is contained in:
Goffi 2024-06-19 18:44:57 +02:00
commit 53fdaa9d09

View file

@ -87,16 +87,22 @@ class Get(base.CommandBase):
start, "medium", tz_info=date_utils.TZ_LOCAL
)
end = event["end"]
self.disp(A.color(
A.BOLD, start_human, A.RESET, " ",
f"({date_utils.delta2human(start, end)}) ",
C.A_HEADER, name
))
self.disp(
A.color(
A.BOLD,
start_human,
A.RESET,
" ",
f"({date_utils.delta2human(start, end)}) ",
C.A_HEADER,
name,
)
)
if self.verbosity > 0:
descriptions = event.get("descriptions", [])
if descriptions:
self.disp(descriptions[0]["description"])
if idx < (nb_events-1):
if idx < (nb_events - 1):
self.disp("")
@ -106,7 +112,7 @@ class CategoryAction(argparse.Action):
if nargs is not None or metavar is not None:
raise ValueError("nargs and metavar must not be used")
if metavar is not None:
metavar="TERM WIKIDATA_ID LANG"
metavar = "TERM WIKIDATA_ID LANG"
if "--help" in sys.argv:
# FIXME: dirty workaround to have correct --help message
# argparse doesn't normally allow variable number of arguments beside "+"
@ -128,9 +134,7 @@ class CategoryAction(argparse.Action):
if not values:
parser.error("category values must be set")
category = {
"term": values[0]
}
category = {"term": values[0]}
if len(values) == 1:
pass
@ -153,14 +157,21 @@ class CategoryAction(argparse.Action):
class EventBase:
def add_parser_options(self):
self.parser.add_argument(
"-S", "--start", type=base.date_decoder, metavar="TIME_PATTERN",
help=_("the start time of the event"))
"-S",
"--start",
type=base.date_decoder,
metavar="TIME_PATTERN",
help=_("the start time of the event"),
)
end_group = self.parser.add_mutually_exclusive_group()
end_group.add_argument(
"-E", "--end", type=base.date_decoder, metavar="TIME_PATTERN",
help=_("the time of the end of the event"))
end_group.add_argument(
"-D", "--duration", help=_("duration of the event"))
"-E",
"--end",
type=base.date_decoder,
metavar="TIME_PATTERN",
help=_("the time of the end of the event"),
)
end_group.add_argument("-D", "--duration", help=_("duration of the event"))
self.parser.add_argument(
"-H", "--head-picture", help="URL to a picture to use as head-picture"
)
@ -168,47 +179,65 @@ class EventBase:
"-d", "--description", help="plain text description the event"
)
self.parser.add_argument(
"-C", "--category", action=CategoryAction, dest="categories",
help="Category of the event"
"-C",
"--category",
action=CategoryAction,
dest="categories",
help="Category of the event",
)
self.parser.add_argument(
"-l", "--location", action="append", nargs="+", metavar="[KEY] VALUE",
help="Location metadata"
"-l",
"--location",
action="append",
nargs="+",
metavar="[KEY] VALUE",
help="Location metadata",
)
rsvp_group = self.parser.add_mutually_exclusive_group()
rsvp_group.add_argument(
"--rsvp", action="store_true", help=_("RSVP is requested"))
"--rsvp", action="store_true", help=_("RSVP is requested")
)
rsvp_group.add_argument(
"--rsvp_json", metavar="JSON", help=_("JSON description of RSVP form"))
"--rsvp_json", metavar="JSON", help=_("JSON description of RSVP form")
)
for node_type in ("invitees", "comments", "blog", "schedule"):
self.parser.add_argument(
f"--{node_type}",
nargs=2,
metavar=("JID", "NODE"),
help=_("link {node_type} pubsub node").format(node_type=node_type)
help=_("link {node_type} pubsub node").format(node_type=node_type),
)
self.parser.add_argument(
"-a", "--attachment", action="append", dest="attachments",
help=_("attach a file")
"-a",
"--attachment",
action="append",
dest="attachments",
help=_("attach a file"),
)
self.parser.add_argument("--website", help=_("website of the event"))
self.parser.add_argument(
"--status", choices=["confirmed", "tentative", "cancelled"],
help=_("status of the event")
"--status",
choices=["confirmed", "tentative", "cancelled"],
help=_("status of the event"),
)
self.parser.add_argument(
"-T", "--language", metavar="LANG", action="append", dest="languages",
help=_("main languages spoken at the event")
"-T",
"--language",
metavar="LANG",
action="append",
dest="languages",
help=_("main languages spoken at the event"),
)
self.parser.add_argument(
"--wheelchair", choices=["full", "partial", "no"],
help=_("is the location accessible by wheelchair")
"--wheelchair",
choices=["full", "partial", "no"],
help=_("is the location accessible by wheelchair"),
)
self.parser.add_argument(
"--external",
nargs=3,
metavar=("JID", "NODE", "ITEM"),
help=_("link to an external event")
help=_("link to an external event"),
)
def get_event_data(self):
@ -229,17 +258,10 @@ class EventBase:
event["end"] = self.args.end
if self.args.head_picture:
event["head-picture"] = {
"sources": [{
"url": self.args.head_picture
}]
}
event["head-picture"] = {"sources": [{"url": self.args.head_picture}]}
if self.args.description:
event["descriptions"] = [
{
"type": "text",
"description": self.args.description
}
{"type": "text", "description": self.args.description}
]
if self.args.categories:
event["categories"] = self.args.categories
@ -270,9 +292,7 @@ class EventBase:
if self.args.attachments:
attachments = event["attachments"] = []
for attachment in self.args.attachments:
attachments.append({
"sources": [{"url": attachment}]
})
attachments.append({"sources": [{"url": attachment}]})
extra = {}
@ -288,11 +308,7 @@ class EventBase:
if self.args.external:
ext_jid, ext_node, ext_item = self.args.external
event["external"] = {
"jid": ext_jid,
"node": ext_node,
"item": ext_item
}
event["external"] = {"jid": ext_jid, "node": ext_node, "item": ext_item}
return event
@ -388,8 +404,12 @@ class InviteeGet(base.CommandBase):
def add_parser_options(self):
self.parser.add_argument(
"-j", "--jid", action="append", dest="jids", default=[],
help=_("only retrieve RSVP from those JIDs")
"-j",
"--jid",
action="append",
dest="jids",
default=[],
help=_("only retrieve RSVP from those JIDs"),
)
async def start(self):