Skip to content

Commit

Permalink
Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jspricke committed Dec 24, 2021
1 parent 201a311 commit 087d46b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 71 deletions.
2 changes: 0 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -617,5 +617,3 @@ reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

END OF TERMS AND CONDITIONS
14 changes: 9 additions & 5 deletions ics_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def compare(first_in: Component, second_in: Component, second_out: Component) ->

found = True
first_in.remove(first)
print("matching %d to %d" % (i, j))
print(f"matching {i} to {j}")
if not found:
second_out.add(second)

Expand All @@ -106,14 +106,18 @@ def main() -> None:
parser.add_argument("first_output", help="First iCalendar file output")
parser.add_argument("second_output", help="Second iCalendar file output")
args = parser.parse_args()
first_cal = next(readComponents(open(args.first_input)))
second_cal = next(readComponents(open(args.second_input)))
with open(args.first_input, encoding="utf-8") as infile:
first_cal = next(readComponents(infile))
with open(args.second_input, encoding="utf-8") as infile:
second_cal = next(readComponents(infile))
second_out = iCalendar()

compare(first_cal, second_cal, second_out)

open(args.first_output, "w").write(first_cal.serialize())
open(args.second_output, "w").write(second_out.serialize())
with open(args.first_output, "w", encoding="utf-8") as outfile:
outfile.write(first_cal.serialize())
with open(args.second_output, "w", encoding="utf-8") as outfile:
outfile.write(second_out.serialize())


if __name__ == "__main__":
Expand Down
79 changes: 45 additions & 34 deletions remind.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def _parse_remind(
]
try:
process = run(cmd, input=lines, capture_output=True, text=True)
except FileNotFoundError:
raise FileNotFoundError("remind command not found, please install it")
except FileNotFoundError as error:
raise FileNotFoundError(
"remind command not found, please install it"
) from error

if "Unknown option" in process.stderr:
raise OSError(f'Error running: {" ".join(cmd)}, maybe old remind version')
Expand Down Expand Up @@ -110,7 +112,7 @@ def _parse_remind(
if "passthru" in entry:
continue

entry["uid"] = "%s@%s" % (entry["tags"].split(",")[-1][7:], getfqdn())
entry["uid"] = f"{entry['tags'].split(',')[-1][7:]}@{getfqdn()}"

if "eventstart" in entry:
dtstart: Union[datetime, date] = datetime.strptime(
Expand Down Expand Up @@ -268,7 +270,7 @@ def get_filesnames(self) -> list[str]:
@staticmethod
def _get_uid(line: str) -> str:
"""UID of a remind line."""
return "%s@%s" % (md5(line.strip().encode("utf-8")).hexdigest(), getfqdn())
return f"{md5(line.strip().encode('utf-8')).hexdigest()}@{getfqdn()}"

def get_uids(self, filename: str = "") -> list[str]:
"""UIDs of all reminders in the file excluding included files.
Expand Down Expand Up @@ -306,7 +308,7 @@ def to_vobject_etag(self, filename: str, uid: str) -> tuple[Component, str]:
return self._vobject_etag(filename, uid)[1:3]

def to_vobjects(
self, filename: str, uids: Iterable[str] = []
self, filename: str, uids: Iterable[str] = None
) -> list[tuple[str, Component, str]]:
"""Return iCal objects and etags of all Remind entries in uids.
Expand Down Expand Up @@ -340,8 +342,8 @@ def to_vobject(self, filename: str = "", uid: str = "") -> Component:
for event in self._reminders[filename].values():
self._gen_vevent(event, cal.add("vevent"))
else:
for filename in self._reminders:
for event in self._reminders[filename].values():
for events in self._reminders.values():
for event in events.values():
self._gen_vevent(event, cal.add("vevent"))
return cal

Expand All @@ -360,7 +362,7 @@ def _parse_rdate(rdates: list[date], repeat: int = 1) -> str:
for rdate in rdates
for d in range(repeat)
]
return "SATISFY [%s]" % "||".join(trigdates)
return f"SATISFY [{'||'.join(trigdates)}]"

@staticmethod
def _parse_rruleset(rruleset: Any, duration: timedelta) -> Union[str, list[str]]:
Expand All @@ -378,26 +380,26 @@ def _parse_rruleset(rruleset: Any, duration: timedelta) -> Union[str, list[str]]
if rruleset._rrule[0]._byweekday and len(rruleset._rrule[0]._byweekday) > 1:
rep.append("*1")
elif rruleset._rrule[0]._freq == rrule.DAILY:
rep.append("*%d" % rruleset._rrule[0]._interval)
rep.append(f"*{rruleset._rrule[0]._interval}")
elif rruleset._rrule[0]._freq == rrule.WEEKLY:
rep.append("*%d" % (7 * rruleset._rrule[0]._interval))
rep.append(f"*{(7 * rruleset._rrule[0]._interval)}")
elif (
rruleset._rrule[0]._freq == rrule.MONTHLY and rruleset._rrule[0]._bymonthday
):
rep.append("%d" % rruleset._rrule[0]._bymonthday[0])
rep.append(str(rruleset._rrule[0]._bymonthday[0]))
elif (
rruleset._rrule[0]._freq == rrule.MONTHLY and rruleset._rrule[0]._bynweekday
):
daynum, week = rruleset._rrule[0]._bynweekday[0]
weekday = weekdays[daynum]
rep.append("%s %d" % (weekday, week * 7 - 6))
rep.append(f"{weekday} {week * 7 - 6}")
else:
return Remind._parse_rdate(rruleset._rrule[0])

if rruleset._rrule[0]._byweekday and len(rruleset._rrule[0]._byweekday) > 1:
daynums = set(range(7)) - set(rruleset._rrule[0]._byweekday)
days = [weekdays[day] for day in daynums]
rep.append("SKIP OMIT %s" % " ".join(days))
rep.append(f"SKIP OMIT {' '.join(days)}")

if rruleset._rrule[0]._until:
rep.append(
Expand All @@ -413,7 +415,7 @@ def _event_duration(vevent: Component) -> timedelta:
"""Unify dtend and duration to the duration of the given vevent."""
if hasattr(vevent, "dtend"):
return vevent.dtend.value - vevent.dtstart.value
elif hasattr(vevent, "duration") and vevent.duration.value:
if hasattr(vevent, "duration") and vevent.duration.value:
return vevent.duration.value
return timedelta(0)

Expand All @@ -431,12 +433,12 @@ def _gen_msg(vevent: Component, label: str, tail: str, sep: str) -> str:
msg.append("empty reminder")

if hasattr(vevent, "location") and vevent.location.value:
msg.append("at %s" % Remind._rem_clean(vevent.location.value))
msg.append(f"at {Remind._rem_clean(vevent.location.value)}")

has_desc = hasattr(vevent, "description") and vevent.description.value.strip()

if tail or has_desc:
rem.append('%%"%s%%"' % " ".join(msg))
rem.append(f'%"{" ".join(msg)}%"')
else:
rem.append(" ".join(msg))

Expand Down Expand Up @@ -512,7 +514,7 @@ def to_remind(
remind.append(postdate)

if priority:
remind.append("PRIORITY %s" % priority)
remind.append(f"PRIORITY {priority}")

if isinstance(trigdates, list):
remind.extend(trigdates)
Expand All @@ -530,26 +532,25 @@ def to_remind(
remind.append(posttime)

if duration.total_seconds() > 0:
remind.append(
"DURATION %d:%02d" % divmod(duration.total_seconds() / 60, 60)
)
hours, minutes = divmod(duration.total_seconds() / 60, 60)
remind.append(f"DURATION {hours:.0f}:{minutes:02.0f}")

if hasattr(vevent, "rdate"):
remind.append(Remind._parse_rdate(vevent.rdate.value))

if hasattr(vevent, "class"):
remind.append("TAG %s" % Remind._abbr_tag(vevent.getChildValue("class")))
remind.append(f"TAG {Remind._abbr_tag(vevent.getChildValue('class'))}")

if isinstance(trigdates, str):
remind.append(trigdates)

if tags:
remind.extend(["TAG %s" % Remind._abbr_tag(tag) for tag in tags])
remind.extend([f"TAG {Remind._abbr_tag(tag) for tag in tags}"])

if hasattr(vevent, "categories_list"):
for categories in vevent.categories_list:
for category in categories.value:
remind.append("TAG %s" % Remind._abbr_tag(category))
remind.append(f"TAG {Remind._abbr_tag(category)}")

remind.append(Remind._gen_msg(vevent, label, tail, sep))

Expand Down Expand Up @@ -583,7 +584,8 @@ def append_vobject(self, ical: Component, filename: str = "") -> str:

with self._lock:
outdat = self.to_reminders(ical)
open(filename, "a").write(outdat)
with open(filename, "a", encoding="utf-8") as outfile:
outfile.write(outdat)

return Remind._get_uid(outdat)

Expand All @@ -595,11 +597,13 @@ def remove(self, uid: str, filename: str = "") -> None:
uid = uid.split("@")[0]

with self._lock:
rem = open(filename).readlines()
with open(filename, encoding="utf-8") as infile:
rem = infile.readlines()
for (index, line) in enumerate(rem):
if uid == md5(line.strip().encode("utf-8")).hexdigest():
del rem[index]
open(filename, "w").writelines(rem)
with open(filename, "w", encoding="utf-8") as outfile:
outfile.writelines(rem)
break

def replace_vobject(self, uid: str, ical: Component, filename: str = "") -> str:
Expand All @@ -610,12 +614,14 @@ def replace_vobject(self, uid: str, ical: Component, filename: str = "") -> str:
uid = uid.split("@")[0]

with self._lock:
rem = open(filename).readlines()
with open(filename, encoding="utf-8") as infile:
rem = infile.readlines()
for (index, line) in enumerate(rem):
if uid == md5(line.strip().encode("utf-8")).hexdigest():
rem[index] = self.to_reminders(ical)
new_uid = self._get_uid(rem[index])
open(filename, "w").writelines(rem)
with open(filename, "w", encoding="utf-8") as outfile:
outfile.writelines(rem)
return new_uid
raise ValueError(f"Failed to find uid {uid} in {filename}")

Expand All @@ -624,15 +630,19 @@ def move_vobject(self, uid: str, from_file: str, to_file: str) -> None:
uid = uid.split("@")[0]

with self._lock:
rem = open(from_file).readlines()
with open(from_file, encoding="utf-8") as infile:
rem = infile.readlines()
for (index, line) in enumerate(rem):
if uid == md5(line.strip().encode("utf-8")).hexdigest():
del rem[index]
open(from_file, "w").writelines(rem)
open(to_file, "a").write(line)
with open(from_file, "w", encoding="utf-8") as outfile:
outfile.writelines(rem)
with open(to_file, "a", encoding="utf-8") as outfile:
outfile.writelines(rem)
break

def get_meta(self) -> dict[str, str]:
@staticmethod
def get_meta() -> dict[str, str]:
"""Meta tags of the vObject collection."""
return {"tag": "VCALENDAR", "C:supported-calendar-component-set": "VEVENT"}

Expand All @@ -641,7 +651,8 @@ def last_modified(self) -> float:
self._update()
return self._mtime

def get_etag(self, vobject: Component) -> str:
@staticmethod
def get_etag(vobject: Component) -> str:
"""Generate an etag for the given vobject.
This sets the dtstamp to epoch 0 to generate a deterministic result as
Expand All @@ -656,7 +667,7 @@ def get_etag(self, vobject: Component) -> str:
vevent.dtstamp.value = datetime.fromtimestamp(0)
etag = md5()
etag.update(vobject_copy.serialize().encode("utf-8"))
return '"%s"' % etag.hexdigest()
return f'"{etag.hexdigest()}"'


def rem2ics() -> None:
Expand Down
59 changes: 29 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
from setuptools import setup

setup(name='remind',
version='0.17.0',
description='Remind Python library',
long_description=open('README.rst').read(),
author='Jochen Sprickerhof',
author_email='remind@jochen.sprickerhof.de',
license='GPLv3+',
url='https://github.com/jspricke/python-remind',
keywords=['Remind'],
classifiers=[
'Programming Language :: Python',
'Development Status :: 4 - Beta',
'Environment :: Console',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Topic :: Office/Business :: Scheduling',
'Topic :: Software Development :: Libraries :: Python Modules',
],

setup_requires=['nose>=1.3', 'coverage'],
install_requires=['python-dateutil', 'vobject'],
py_modules=['remind', 'ics_compare'],

entry_points={
'console_scripts': [
'rem2ics = remind:rem2ics',
'ics2rem = remind:ics2rem',
]
},

test_suite='nose.collector',)
setup(
name="remind",
version="0.17.0",
description="Remind Python library",
long_description=open("README.rst").read(),
author="Jochen Sprickerhof",
author_email="remind@jochen.sprickerhof.de",
license="GPLv3+",
url="https://github.com/jspricke/python-remind",
keywords=["Remind"],
classifiers=[
"Programming Language :: Python",
"Development Status :: 4 - Beta",
"Environment :: Console",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Topic :: Office/Business :: Scheduling",
"Topic :: Software Development :: Libraries :: Python Modules",
],
setup_requires=["nose>=1.3", "coverage"],
install_requires=["python-dateutil", "vobject"],
py_modules=["remind", "ics_compare"],
entry_points={
"console_scripts": [
"rem2ics = remind:rem2ics",
"ics2rem = remind:ics2rem",
]
},
test_suite="nose.collector",
)

0 comments on commit 087d46b

Please sign in to comment.