Skip to content

Commit

Permalink
pylint issues cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
da4089 committed Mar 28, 2024
1 parent 992b8b7 commit ae0d211
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 69 deletions.
3 changes: 3 additions & 0 deletions vobject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@
from .base import newFromBehavior, readComponents, readOne


# Master package version number.
__version__ = "0.9.8"


def iCalendar():
"""Return an iCalendar 2.0 VCALENDAR component."""
return newFromBehavior("vcalendar", "2.0")


def vCard():
"""Return a vCard 3.0 VCARD component."""
return newFromBehavior("vcard", "3.0")
2 changes: 0 additions & 2 deletions vobject/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def validate(cls, obj, raiseException=False, complainUnrecognized=False):
@classmethod
def lineValidate(cls, line, raiseException, complainUnrecognized):
"""Examine a line's parameters and values, return True if valid."""
# todo: remove used param line, raiseException, complainUnrecognized
print(line, raiseException, complainUnrecognized)
return True

@classmethod
Expand Down
3 changes: 1 addition & 2 deletions vobject/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ def getrruleset(self, addRDate=False):
except IndexError:
# it's conceivable that an rrule has 0 datetimes
added = False
print(added) # todo: remove unused vars

return rruleset

Expand Down Expand Up @@ -1032,7 +1031,7 @@ def serialize(cls, obj, buf, lineLength, validate=True):
transformed = obj # FIXME: never used
undoTransform = False
out = None
print(transformed, out) # todo: remove unused vars

outbuf = buf or six.StringIO()
if obj.group is None:
groupString = ""
Expand Down
129 changes: 64 additions & 65 deletions vobject/ics_diff.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""
Compare VTODOs and VEVENTs in two iCalendar sources.
"""

from __future__ import print_function

from optparse import OptionParser
from optparse import OptionParser # pylint: disable=W4901

from vobject import __version__
from vobject.base import Component, getBehavior, newFromBehavior, readOne

"""
Compare VTODOs and VEVENTs in two iCalendar sources.
"""
from vobject.base import Component, newFromBehavior, readOne


def getSortKey(component):
"""Return a string sort-key for the component."""

def getUID(component):
return component.getChildValue("uid", "")

Expand All @@ -25,13 +27,14 @@ def getRecurrenceID(component):
recurrence_id = component.getChildValue("recurrence_id", None)
if recurrence_id is None:
return "0000-00-00"
else:
return recurrence_id.isoformat()

return recurrence_id.isoformat()

return getUID(component) + getSequence(component) + getRecurrenceID(component)


def sortByUID(components):
"""Sort the components by UID."""
return sorted(components, key=getSortKey)


Expand Down Expand Up @@ -81,9 +84,9 @@ def processComponentLists(leftList, rightList):
if rightIndex >= rightListSize:
output.append((comp, None))
break
else:
rightComp = rightList[rightIndex]
rightKey = getSortKey(rightComp)

rightComp = rightList[rightIndex]
rightKey = getSortKey(rightComp)

if leftKey < rightKey:
output.append((comp, None))
Expand All @@ -95,15 +98,6 @@ def processComponentLists(leftList, rightList):

return output

def newComponent(name, body):
if body is None:
return None
else:
c = Component(name)
c.behavior = getBehavior(name)
c.isNative = True
return c

def processComponentPair(leftComp, rightComp):
"""
Return None if a match, or a pair of components including UIDs and
Expand Down Expand Up @@ -135,34 +129,34 @@ def processComponentPair(leftComp, rightComp):

if len(differentContentLines) == 0 and len(differentComponents) == 0:
return None
else:
left = newFromBehavior(leftComp.name)
right = newFromBehavior(leftComp.name)
# add a UID, if one existed, despite the fact that they'll always be
# the same
uid = leftComp.getChildValue("uid")
if uid is not None:
left.add("uid").value = uid
right.add("uid").value = uid

for name, childPairList in differentComponents.items():
leftComponents, rightComponents = zip(*childPairList)
if len(leftComponents) > 0:
# filter out None
left.contents[name] = filter(None, leftComponents)
if len(rightComponents) > 0:
# filter out None
right.contents[name] = filter(None, rightComponents)

for leftChildLine, rightChildLine in differentContentLines:
nonEmpty = leftChildLine or rightChildLine
name = nonEmpty[0].name
if leftChildLine is not None:
left.contents[name] = leftChildLine
if rightChildLine is not None:
right.contents[name] = rightChildLine

return left, right

left = newFromBehavior(leftComp.name)
right = newFromBehavior(leftComp.name)
# add a UID, if one existed, despite the fact that they'll always be
# the same
uid = leftComp.getChildValue("uid")
if uid is not None:
left.add("uid").value = uid
right.add("uid").value = uid

for name, childPairList in differentComponents.items():
leftComponents, rightComponents = zip(*childPairList)
if len(leftComponents) > 0:
# filter out None
left.contents[name] = filter(None, leftComponents)
if len(rightComponents) > 0:
# filter out None
right.contents[name] = filter(None, rightComponents)

for leftChildLine, rightChildLine in differentContentLines:
nonEmpty = leftChildLine or rightChildLine
name = nonEmpty[0].name
if leftChildLine is not None:
left.contents[name] = leftChildLine
if rightChildLine is not None:
right.contents[name] = rightChildLine

return left, right

vevents = processComponentLists(
sortByUID(getattr(left, "vevent_list", [])), sortByUID(getattr(right, "vevent_list", []))
Expand All @@ -176,6 +170,7 @@ def processComponentPair(leftComp, rightComp):


def prettyDiff(leftObj, rightObj):
"""Print prettily-formatted differences between left and right objects."""
for left, right in diff(leftObj, rightObj):
print("<<<<<<<<<<<<<<<")
if left is not None:
Expand All @@ -184,28 +179,17 @@ def prettyDiff(leftObj, rightObj):
if right is not None:
right.prettyPrint()
print(">>>>>>>>>>>>>>>")
print


def main():
options, args = getOptions()
if args:
ignore_dtstamp = options.ignore
ics_file1, ics_file2 = args
with open(ics_file1) as f, open(ics_file2) as g:
cal1 = readOne(f)
cal2 = readOne(g)
deleteExtraneous(cal1, ignore_dtstamp=ignore_dtstamp)
deleteExtraneous(cal2, ignore_dtstamp=ignore_dtstamp)
prettyDiff(cal1, cal2)
print("")


def getOptions():
# Configuration options
"""Parse command line options.
@returns (options, remaining_args)"""

usage = "usage: %prog [options] ics_file1 ics_file2"
parser = OptionParser(usage=usage, version=__version__)
parser.set_description("ics_diff will print a comparison of two iCalendar files ")
parser.set_description("Print a comparison of two iCalendar files")

parser.add_option(
"-i",
Expand All @@ -219,13 +203,28 @@ def getOptions():
(cmdline_options, args) = parser.parse_args()
if len(args) < 2:
print("error: too few arguments given")
print
print("")
print(parser.format_help())
return False, False

return cmdline_options, args


def main():
"""Main function."""

options, args = getOptions()
if args:
ignore_dtstamp = options.ignore
ics_file1, ics_file2 = args
with open(ics_file1) as f, open(ics_file2) as g:
cal1 = readOne(f)
cal2 = readOne(g)
deleteExtraneous(cal1, ignore_dtstamp=ignore_dtstamp)
deleteExtraneous(cal2, ignore_dtstamp=ignore_dtstamp)
prettyDiff(cal1, cal2)


if __name__ == "__main__":
try:
main()
Expand Down

0 comments on commit ae0d211

Please sign in to comment.