3
.gitignore
vendored
3
.gitignore
vendored
@@ -87,5 +87,6 @@ secrets.json
|
|||||||
*.bak
|
*.bak
|
||||||
|
|
||||||
# Just in case
|
# Just in case
|
||||||
|
.~*
|
||||||
report.odt
|
report.odt
|
||||||
.~lock.*.odt#
|
report.csv
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from .config import Config
|
|||||||
from .client import fetch_issues_with_spent_time
|
from .client import fetch_issues_with_spent_time
|
||||||
from .formatter import format_compact, format_table
|
from .formatter import format_compact, format_table
|
||||||
from .formatter_odt import format_odt
|
from .formatter_odt import format_odt
|
||||||
|
from .formatter_csv import format_csv
|
||||||
|
|
||||||
|
|
||||||
def parse_date_range(date_arg: str) -> tuple[str, str]:
|
def parse_date_range(date_arg: str) -> tuple[str, str]:
|
||||||
@@ -75,25 +76,35 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|||||||
print(f"✅ Total issues: {len(issue_hours)} [{args.date}]")
|
print(f"✅ Total issues: {len(issue_hours)} [{args.date}]")
|
||||||
|
|
||||||
if args.output:
|
if args.output:
|
||||||
if not args.output.endswith(".odt"):
|
if not (args.output.endswith(".odt") or args.output.endswith(".csv")):
|
||||||
print("❌ Output file must end with .odt", file=sys.stderr)
|
print("❌ Output file must end with .odt or .csv", file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
try:
|
|
||||||
doc = format_odt(
|
|
||||||
issue_hours,
|
|
||||||
author=Config.get_author(args.author),
|
|
||||||
from_date=from_date,
|
|
||||||
to_date=to_date,
|
|
||||||
fill_time=not args.no_time
|
|
||||||
)
|
|
||||||
|
|
||||||
doc.save(args.output)
|
try:
|
||||||
|
if args.output.endswith(".odt"):
|
||||||
|
doc = format_odt(
|
||||||
|
issue_hours,
|
||||||
|
author=Config.get_author(args.author),
|
||||||
|
from_date=from_date,
|
||||||
|
to_date=to_date,
|
||||||
|
fill_time=not args.no_time
|
||||||
|
)
|
||||||
|
doc.save(args.output)
|
||||||
|
elif args.output.endswith(".csv"):
|
||||||
|
csv_content = format_csv(issue_hours, fill_time=not args.no_time)
|
||||||
|
with open(args.output, "w", encoding="utf-8", newline="") as f:
|
||||||
|
f.write(csv_content)
|
||||||
|
|
||||||
print(f"✅ Report saved to {args.output}")
|
print(f"✅ Report saved to {args.output}")
|
||||||
except ImportError:
|
except ImportError as e:
|
||||||
print("❌ odfpy is not installed. Install with: pip install odfpy", file=sys.stderr)
|
if args.output.endswith(".odt"):
|
||||||
|
print("❌ odfpy is not installed. Install with: pip install odfpy", file=sys.stderr)
|
||||||
|
else:
|
||||||
|
print(f"❌ Import error: {e}", file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"❌ ODT export error: {e}", file=sys.stderr)
|
fmt = "ODT" if args.output.endswith(".odt") else "CSV"
|
||||||
|
print(f"❌ {fmt} export error: {e}", file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|||||||
40
redmine_reporter/formatter_csv.py
Normal file
40
redmine_reporter/formatter_csv.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import csv
|
||||||
|
import io
|
||||||
|
from typing import List, Tuple
|
||||||
|
from redminelib.resources import Issue
|
||||||
|
from .formatter import get_version, hours_to_human, STATUS_TRANSLATION
|
||||||
|
|
||||||
|
|
||||||
|
def format_csv(
|
||||||
|
issue_hours: List[Tuple[Issue, float]],
|
||||||
|
fill_time: bool = True,
|
||||||
|
dialect: str = "excel"
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
Formats the list of issues with spent time into CSV.
|
||||||
|
Returns a string containing the CSV content.
|
||||||
|
"""
|
||||||
|
|
||||||
|
output = io.StringIO()
|
||||||
|
writer = csv.writer(output, dialect=dialect)
|
||||||
|
|
||||||
|
# Header
|
||||||
|
writer.writerow(["Project", "Version", "Issue ID", "Subject", "Status", "Spent Time"])
|
||||||
|
|
||||||
|
for issue, hours in issue_hours:
|
||||||
|
project = str(issue.project)
|
||||||
|
version = get_version(issue)
|
||||||
|
status_en = str(issue.status)
|
||||||
|
status_ru = STATUS_TRANSLATION.get(status_en, status_en)
|
||||||
|
time_text = hours_to_human(hours) if fill_time else ""
|
||||||
|
|
||||||
|
writer.writerow([
|
||||||
|
project,
|
||||||
|
version,
|
||||||
|
issue.id,
|
||||||
|
issue.subject,
|
||||||
|
status_ru,
|
||||||
|
time_text
|
||||||
|
])
|
||||||
|
|
||||||
|
return output.getvalue()
|
||||||
Reference in New Issue
Block a user