icalreporting 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {icalreporting-0.2.0 → icalreporting-0.3.0}/PKG-INFO +2 -1
- icalreporting-0.3.0/icalreporting/__init__.py +1 -0
- icalreporting-0.3.0/icalreporting/_cli.py +62 -0
- icalreporting-0.3.0/icalreporting/icaltools.py +119 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/icalreporting.egg-info/PKG-INFO +2 -1
- {icalreporting-0.2.0 → icalreporting-0.3.0}/icalreporting.egg-info/SOURCES.txt +6 -1
- icalreporting-0.3.0/icalreporting.egg-info/entry_points.txt +3 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/pyproject.toml +7 -2
- icalreporting-0.3.0/tests/test_cli.py +25 -0
- icalreporting-0.3.0/tests/test_icaltools.py +58 -0
- icalreporting-0.2.0/icalreporting/__init__.py +0 -1
- {icalreporting-0.2.0 → icalreporting-0.3.0}/LICENSE +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/README.md +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/icalreporting/reporting.py +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/icalreporting.egg-info/dependency_links.txt +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/icalreporting.egg-info/requires.txt +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/icalreporting.egg-info/top_level.txt +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/setup.cfg +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/tests/test_Hyperplanning.py +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/tests/test_Project.py +0 -0
- {icalreporting-0.2.0 → icalreporting-0.3.0}/tests/test_icalimport.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: icalreporting
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Reporting tools from ical files
|
|
5
5
|
Author-email: "J. Gressier" <jeremie.gressier@isae-supaero.fr>
|
|
6
6
|
License: MIT License
|
|
@@ -33,6 +33,7 @@ Classifier: Programming Language :: Python
|
|
|
33
33
|
Classifier: Programming Language :: Python :: 3.9
|
|
34
34
|
Classifier: Programming Language :: Python :: 3.10
|
|
35
35
|
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
36
37
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
37
38
|
Requires-Python: >=3.9
|
|
38
39
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from icalreporting.icaltools import IcalFile
|
|
3
|
+
|
|
4
|
+
def _parseargs(argv, helpmsg=""):
|
|
5
|
+
try:
|
|
6
|
+
if argv is None:
|
|
7
|
+
argv = sys.argv[1:] # mimic argparse
|
|
8
|
+
filename = argv[0]
|
|
9
|
+
except IndexError:
|
|
10
|
+
print(helpmsg)
|
|
11
|
+
return True, argv
|
|
12
|
+
return False, argv
|
|
13
|
+
|
|
14
|
+
def icalcheck(argv=None): # argv for tests
|
|
15
|
+
error, argv = _parseargs(argv, helpmsg="usage: icalcheck <filename>")
|
|
16
|
+
if error:
|
|
17
|
+
return not error
|
|
18
|
+
filename = argv[0]
|
|
19
|
+
_default_engine = 'icalendar'
|
|
20
|
+
if _default_engine not in IcalFile._engines:
|
|
21
|
+
raise NotImplementedError(f"{_default_engine} engine not available")
|
|
22
|
+
# some info/stats/check with default engine
|
|
23
|
+
print(f"> checking ICAL file: {filename}")
|
|
24
|
+
file = IcalFile(filename, engine=_default_engine, verbose=False)
|
|
25
|
+
try:
|
|
26
|
+
file.read()
|
|
27
|
+
except FileNotFoundError as e:
|
|
28
|
+
print(f"Error reading file: {e}")
|
|
29
|
+
return False
|
|
30
|
+
print(f". number of events: {file.nevents()}")
|
|
31
|
+
# check all engine can read file
|
|
32
|
+
print("> check all reader engines")
|
|
33
|
+
for engine in IcalFile._engines:
|
|
34
|
+
print(f"- engine: {engine}")
|
|
35
|
+
file = IcalFile(filename, engine=engine, verbose=False)
|
|
36
|
+
try:
|
|
37
|
+
file.read()
|
|
38
|
+
except Exception as e:
|
|
39
|
+
print(f"Error reading file with engine {engine}: {e}")
|
|
40
|
+
error = True
|
|
41
|
+
print("> done")
|
|
42
|
+
return not error # for pytest
|
|
43
|
+
|
|
44
|
+
def icalclean(argv=None):
|
|
45
|
+
error, argv = _parseargs(argv, helpmsg="usage: icalcheck <filename>")
|
|
46
|
+
if error:
|
|
47
|
+
return not error
|
|
48
|
+
filename = argv[0]
|
|
49
|
+
file = IcalFile(filename, engine='icalendar')
|
|
50
|
+
try:
|
|
51
|
+
file.read()
|
|
52
|
+
except FileNotFoundError as e:
|
|
53
|
+
print(f"Error reading file: {e}")
|
|
54
|
+
return False
|
|
55
|
+
print(f"- number of events: {file.nevents()}")
|
|
56
|
+
print(f"- normalizing timezones if necessary")
|
|
57
|
+
file.normalize_vtimezone()
|
|
58
|
+
print(f"- cleaning useless fields")
|
|
59
|
+
file.clean_events()
|
|
60
|
+
file.write(file._filename.with_suffix('.cleaned.ics'))
|
|
61
|
+
print("> done")
|
|
62
|
+
return not error # for pytest
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import importlib
|
|
3
|
+
from icalendar import Calendar
|
|
4
|
+
from ical.calendar_stream import IcsCalendarStream
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
class IcalFile:
|
|
8
|
+
_engines = ['icalendar', 'ical']
|
|
9
|
+
|
|
10
|
+
def __init__(self, filename, engine='icalendar', verbose=True):
|
|
11
|
+
self._engine = engine
|
|
12
|
+
self._filename = Path(filename)
|
|
13
|
+
self._calendar = None
|
|
14
|
+
if verbose:
|
|
15
|
+
print(f"Initializing IcalFile with engine {engine} and file {filename}")
|
|
16
|
+
|
|
17
|
+
def _read_icalendar(self):
|
|
18
|
+
with self._filename.open('r') as icsfile:
|
|
19
|
+
self._calendar = Calendar.from_ical(icsfile.read())
|
|
20
|
+
# for item in self._calendar.walk('VALARM'):
|
|
21
|
+
# print(item)
|
|
22
|
+
# self._calendar.subcomponents.remove(item)
|
|
23
|
+
# print(len(self._calendar.subcomponents))
|
|
24
|
+
print("Calendar read successfully using icalendar")
|
|
25
|
+
|
|
26
|
+
def _read_ical(self):
|
|
27
|
+
with self._filename.open('r') as icsfile:
|
|
28
|
+
self._calendar = IcsCalendarStream.calendar_from_ics(icsfile.read())
|
|
29
|
+
print("Calendar read successfully using ical")
|
|
30
|
+
|
|
31
|
+
def read(self):
|
|
32
|
+
if not self._filename.exists():
|
|
33
|
+
raise FileNotFoundError(f"File {self._filename} not found")
|
|
34
|
+
if self._engine == 'icalendar':
|
|
35
|
+
self._read_icalendar()
|
|
36
|
+
elif self._engine == 'ical':
|
|
37
|
+
self._read_ical()
|
|
38
|
+
else:
|
|
39
|
+
raise ValueError(f"Unsupported engine: {self._engine}")
|
|
40
|
+
|
|
41
|
+
def nevents(self):
|
|
42
|
+
if self._calendar is None:
|
|
43
|
+
raise ValueError("Calendar not loaded")
|
|
44
|
+
if self._engine == 'icalendar':
|
|
45
|
+
return len(self._calendar.walk('VEVENT'))
|
|
46
|
+
elif self._engine == 'ical':
|
|
47
|
+
return len(self._calendar.events)
|
|
48
|
+
else:
|
|
49
|
+
raise ValueError(f"Unsupported engine: {self._engine}")
|
|
50
|
+
|
|
51
|
+
def filter_summary(self, keywords: list):
|
|
52
|
+
if self._calendar is None:
|
|
53
|
+
raise ValueError("Calendar not loaded")
|
|
54
|
+
if self._engine == 'icalendar':
|
|
55
|
+
events = self._calendar.walk('VEVENT')
|
|
56
|
+
filtered_events = [event for event in events if any(key.lower() in event.get('SUMMARY').lower() for key in keywords)]
|
|
57
|
+
print(len(self._calendar.subcomponents))
|
|
58
|
+
for event in events:
|
|
59
|
+
self._calendar.subcomponents.remove(event)
|
|
60
|
+
print(len(self._calendar.subcomponents))
|
|
61
|
+
for event in filtered_events:
|
|
62
|
+
self._calendar.add_component(event)
|
|
63
|
+
print(len(self._calendar.subcomponents))
|
|
64
|
+
elif self._engine == 'ical':
|
|
65
|
+
events = self._calendar.events
|
|
66
|
+
filtered_events = [event for event in events if any(key.lower() in event.summary.lower() for key in keywords)]
|
|
67
|
+
self._calendar.events = filtered_events
|
|
68
|
+
else:
|
|
69
|
+
raise ValueError(f"Unsupported engine: {self._engine}")
|
|
70
|
+
print(f"Filtered {len(filtered_events)} events with keywords {keywords}")
|
|
71
|
+
return filtered_events
|
|
72
|
+
|
|
73
|
+
def clean_events(self):
|
|
74
|
+
_useless_attributes = ['DESCRIPTION', 'TRANSP', '']
|
|
75
|
+
if self._calendar is None:
|
|
76
|
+
raise ValueError("Calendar not loaded")
|
|
77
|
+
if self._engine == 'icalendar':
|
|
78
|
+
self._calendar.walk('VEVENT').clear()
|
|
79
|
+
elif self._engine == 'ical':
|
|
80
|
+
self._calendar.events = []
|
|
81
|
+
else:
|
|
82
|
+
raise ValueError(f"Unsupported engine: {self._engine}")
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def normalize_to_full_minutes(delta):
|
|
86
|
+
"""
|
|
87
|
+
Ensures a timedelta is represented in full minutes.
|
|
88
|
+
Rounds seconds to the nearest minute and returns a new timedelta.
|
|
89
|
+
"""
|
|
90
|
+
# Calculate total seconds and round to the nearest minute
|
|
91
|
+
total_seconds = delta.total_seconds()
|
|
92
|
+
full_minutes = round(total_seconds / 60) # Convert to minutes and round
|
|
93
|
+
# Create a new timedelta with the normalized minutes
|
|
94
|
+
return timedelta(minutes=full_minutes)
|
|
95
|
+
|
|
96
|
+
def normalize_vtimezone(self):
|
|
97
|
+
if self._calendar is None:
|
|
98
|
+
raise ValueError("Calendar not loaded")
|
|
99
|
+
if self._engine == 'icalendar':
|
|
100
|
+
for vtzone in self._calendar.walk('VTIMEZONE'):
|
|
101
|
+
for tz in vtzone.subcomponents:
|
|
102
|
+
tz['TZOFFSETFROM'].td = self.normalize_to_full_minutes(tz['TZOFFSETFROM'].td)
|
|
103
|
+
tz['TZOFFSETTO'].td = self.normalize_to_full_minutes(tz['TZOFFSETTO'].td)
|
|
104
|
+
else:
|
|
105
|
+
raise ValueError(f"Unsupported engine: {self._engine}")
|
|
106
|
+
|
|
107
|
+
def write(self, filename):
|
|
108
|
+
filename = Path(filename)
|
|
109
|
+
if self._calendar is None:
|
|
110
|
+
raise ValueError("Calendar not loaded")
|
|
111
|
+
if self._engine == 'icalendar':
|
|
112
|
+
with filename.open('wb') as icsfile:
|
|
113
|
+
icsfile.write(self._calendar.to_ical())
|
|
114
|
+
elif self._engine == 'ical':
|
|
115
|
+
with filename.open('w') as icsfile:
|
|
116
|
+
icsfile.write(IcsCalendarStream.calendar_to_ics(self._calendar))
|
|
117
|
+
else:
|
|
118
|
+
raise ValueError(f"Unsupported engine: {self._engine}")
|
|
119
|
+
print(f"Calendar written successfully to {filename}")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: icalreporting
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Reporting tools from ical files
|
|
5
5
|
Author-email: "J. Gressier" <jeremie.gressier@isae-supaero.fr>
|
|
6
6
|
License: MIT License
|
|
@@ -33,6 +33,7 @@ Classifier: Programming Language :: Python
|
|
|
33
33
|
Classifier: Programming Language :: Python :: 3.9
|
|
34
34
|
Classifier: Programming Language :: Python :: 3.10
|
|
35
35
|
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
36
37
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
37
38
|
Requires-Python: >=3.9
|
|
38
39
|
Description-Content-Type: text/markdown
|
|
@@ -2,12 +2,17 @@ LICENSE
|
|
|
2
2
|
README.md
|
|
3
3
|
pyproject.toml
|
|
4
4
|
icalreporting/__init__.py
|
|
5
|
+
icalreporting/_cli.py
|
|
6
|
+
icalreporting/icaltools.py
|
|
5
7
|
icalreporting/reporting.py
|
|
6
8
|
icalreporting.egg-info/PKG-INFO
|
|
7
9
|
icalreporting.egg-info/SOURCES.txt
|
|
8
10
|
icalreporting.egg-info/dependency_links.txt
|
|
11
|
+
icalreporting.egg-info/entry_points.txt
|
|
9
12
|
icalreporting.egg-info/requires.txt
|
|
10
13
|
icalreporting.egg-info/top_level.txt
|
|
11
14
|
tests/test_Hyperplanning.py
|
|
12
15
|
tests/test_Project.py
|
|
13
|
-
tests/
|
|
16
|
+
tests/test_cli.py
|
|
17
|
+
tests/test_icalimport.py
|
|
18
|
+
tests/test_icaltools.py
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "icalreporting"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Reporting tools from ical files"
|
|
5
5
|
authors = [{name="J. Gressier", email="jeremie.gressier@isae-supaero.fr"}]
|
|
6
6
|
readme = "README.md"
|
|
@@ -14,6 +14,7 @@ classifiers = [
|
|
|
14
14
|
"Programming Language :: Python :: 3.9",
|
|
15
15
|
"Programming Language :: Python :: 3.10",
|
|
16
16
|
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
17
18
|
"Topic :: Software Development :: Libraries :: Python Modules" ]
|
|
18
19
|
requires-python = ">=3.9"
|
|
19
20
|
dependencies = [
|
|
@@ -37,6 +38,10 @@ dev = [
|
|
|
37
38
|
requires = ["setuptools>=61.0.0", "wheel"]
|
|
38
39
|
build-backend = "setuptools.build_meta"
|
|
39
40
|
|
|
41
|
+
[project.scripts]
|
|
42
|
+
icalcheck = 'icalreporting._cli:icalcheck'
|
|
43
|
+
icalclean = 'icalreporting._cli:icalclean'
|
|
44
|
+
|
|
40
45
|
[tool.pytest.ini_options]
|
|
41
46
|
minversion = "6.0"
|
|
42
47
|
addopts = "--cov -v"
|
|
@@ -45,7 +50,7 @@ testpaths = [
|
|
|
45
50
|
]
|
|
46
51
|
|
|
47
52
|
[tool.bumpver]
|
|
48
|
-
current_version = "v0.
|
|
53
|
+
current_version = "v0.3.0"
|
|
49
54
|
version_pattern = "vMAJOR.MINOR.PATCH"
|
|
50
55
|
commit_message = "bump version {old_version} to {new_version}"
|
|
51
56
|
commit = true
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from icalreporting._cli import icalcheck
|
|
2
|
+
|
|
3
|
+
def test_icalcheck_noarg(capsys):
|
|
4
|
+
check = icalcheck([])
|
|
5
|
+
captured = capsys.readouterr()
|
|
6
|
+
assert "usage: icalcheck <filename>" in captured.out
|
|
7
|
+
assert not check
|
|
8
|
+
|
|
9
|
+
def test_icalcheck_nofile(capsys):
|
|
10
|
+
try:
|
|
11
|
+
check = icalcheck(["examples/bad_file.ics"])
|
|
12
|
+
except FileNotFoundError:
|
|
13
|
+
pass
|
|
14
|
+
captured = capsys.readouterr()
|
|
15
|
+
assert "not found" in captured.out
|
|
16
|
+
assert not check
|
|
17
|
+
|
|
18
|
+
def test_icalcheck(capsys):
|
|
19
|
+
check = icalcheck(["examples/example_variations.ics"])
|
|
20
|
+
captured = capsys.readouterr()
|
|
21
|
+
assert "number of events" in captured.out
|
|
22
|
+
assert "successfully using icalendar" in captured.out
|
|
23
|
+
assert "successfully using ical" in captured.out
|
|
24
|
+
assert check
|
|
25
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from icalreporting.icaltools import IcalFile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
def test_icalfile_init():
|
|
6
|
+
icalfile = IcalFile('examples/example_variations.ics')
|
|
7
|
+
# test default engine
|
|
8
|
+
assert icalfile._engine == 'icalendar'
|
|
9
|
+
assert icalfile._filename == Path('examples/example_variations.ics')
|
|
10
|
+
# without read, calendar should be None
|
|
11
|
+
assert icalfile._calendar is None
|
|
12
|
+
|
|
13
|
+
def test_icalfile_read_icalendar():
|
|
14
|
+
icalfile = IcalFile('examples/example_variations.ics', engine='icalendar')
|
|
15
|
+
icalfile.read()
|
|
16
|
+
assert icalfile._calendar is not None
|
|
17
|
+
assert icalfile._engine == 'icalendar'
|
|
18
|
+
assert icalfile.nevents() == 7
|
|
19
|
+
|
|
20
|
+
def test_icalfile_read_ical():
|
|
21
|
+
icalfile = IcalFile('examples/example_variations.ics', engine='ical')
|
|
22
|
+
icalfile.read()
|
|
23
|
+
assert icalfile._calendar is not None
|
|
24
|
+
assert icalfile._engine == 'ical'
|
|
25
|
+
assert icalfile.nevents() == 7
|
|
26
|
+
|
|
27
|
+
@pytest.mark.parametrize("engine", ['icalendar', 'ical'])
|
|
28
|
+
def test_icalfile_filter_summary(engine):
|
|
29
|
+
icalfile = IcalFile('examples/example_variations.ics', engine=engine)
|
|
30
|
+
icalfile.read()
|
|
31
|
+
keywords = ['team']
|
|
32
|
+
filtered_events = icalfile.filter_summary(keywords)
|
|
33
|
+
assert len(filtered_events) == 2
|
|
34
|
+
assert icalfile.nevents() == 2
|
|
35
|
+
|
|
36
|
+
@pytest.mark.parametrize("engine", ['icalendar', 'ical'])
|
|
37
|
+
def test_icalfile_write(engine):
|
|
38
|
+
icalfile = IcalFile('examples/example_variations.ics', engine=engine)
|
|
39
|
+
icalfile.read()
|
|
40
|
+
icalfile.write('output.ics')
|
|
41
|
+
assert Path('output.ics').exists()
|
|
42
|
+
|
|
43
|
+
def test_icalfile_invalid_engine():
|
|
44
|
+
with pytest.raises(ValueError):
|
|
45
|
+
icalfile = IcalFile('examples/example_variations.ics', engine='invalid')
|
|
46
|
+
icalfile.read()
|
|
47
|
+
|
|
48
|
+
def test_icalfile_calendar_not_loaded():
|
|
49
|
+
icalfile = IcalFile('examples/example_variations.ics')
|
|
50
|
+
with pytest.raises(ValueError):
|
|
51
|
+
icalfile.filter_summary(['test'])
|
|
52
|
+
|
|
53
|
+
def test_icalfile_empty_keywords():
|
|
54
|
+
icalfile = IcalFile('examples/example_variations.ics')
|
|
55
|
+
icalfile.read()
|
|
56
|
+
keywords = []
|
|
57
|
+
filtered_events = icalfile.filter_summary(keywords)
|
|
58
|
+
assert len(filtered_events) == 0
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|