[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/utils/charm
From: Mirko Boehm <mirko () kde ! org>
Date: 2009-05-07 21:30:32
Message-ID: 1241731832.539948.18498.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 965069 by mirko:
r56649@cutiepie: mirko | 2009-05-04 23:27:48 +0200
- parse the date as a command line option
- generate real time sheets
_M . (directory)
M +23 -5 trunk/Tools/TimesheetGenerator/Options.cpp
M +15 -6 trunk/Tools/TimesheetGenerator/main.cpp
--- trunk/playground/utils/charm/trunk/Tools/TimesheetGenerator/Options.cpp \
#965068:965069 @@ -17,7 +17,7 @@
{
opterr = 0;
int ch;
- while ((ch = getopt(argc, argv, "hf:")) != -1)
+ while ((ch = getopt(argc, argv, "hf:d:")) != -1)
{
if (ch == '?')
{
@@ -26,6 +26,8 @@
if (option == 'f')
{
throw UsageException(QObject::tr( "Option -f requires a filename \
argument" ) ); + } else if ( option == 'd' ) {
+ throw UsageException(QObject::tr( "Option -d requires a date \
argument (e.g. 2009-01-01)" ) ); } else {
int code = static_cast<int> ( option );
throw UsageException(QObject::tr("Unknown character %1").arg( code ) \
); @@ -37,7 +39,18 @@
mFile = QString::fromLocal8Bit(optarg);
break;
}
+ case 'd': {
+ const QString text = QString::fromLocal8Bit( optarg );
+ QDate date = QDate::fromString( text, "yyyy-MM-dd" );
+ if ( date.isValid() ) {
+ mDate = date;
+ } else {
+ throw UsageException(QObject::tr("Cannot parse date \"%1\"").arg( \
text ) ); + }
+ break;
+ }
case 'h':
+ throw UsageException();
default:
break;
}
@@ -46,15 +59,14 @@
if ( mFile.isEmpty() ) {
throw UsageException(QObject::tr( "No filename specified (-f), aborting." ) \
); }
+ if ( ! mDate.isValid() ) {
+ throw UsageException( QObject::tr( "No date specified (-d), aborting." ) );
+ }
using namespace std;
- cout << "Parsing file \"" << qPrintable( mFile ) << "\"... ";
QFile file( mFile );
if ( ! file.exists() ) {
- cout << "not found." << endl;
throw UsageException(QObject::tr( "Specified file not found, aborting." ) );
- } else {
- cout << "found." << endl;
}
}
@@ -62,3 +74,9 @@
{
return mFile;
}
+
+QDate Options::date() const
+{
+ return mDate;
+}
+
--- trunk/playground/utils/charm/trunk/Tools/TimesheetGenerator/main.cpp \
#965068:965069 @@ -16,7 +16,7 @@
try {
using namespace TimesheetGenerator;
- cout << "Timesheet Generator" << endl;
+ cout << "Timesheet Generator, (C) 2009 Mirko Boehm, KDAB" << endl;
Options options( argc, argv );
// create a QDomDocument from the file content:
@@ -47,7 +47,6 @@
if ( !ok ) {
throw Exception( QObject::tr( "Mis-spelled or missing user id in \
timesheet entry." ) ); }
- cout << "Generating time sheet for user " << userId << "." << endl;
// read event entries:
EventList events;
@@ -58,7 +57,7 @@
eventElem = eventElem.nextSiblingElement( eventTagName ) ) {
try {
Event event = Event::fromXml( eventElem );
- event.dump();
+ // event.dump();
events << event;
} catch( XmlSerializationException& e ) {
throw Exception( QObject::tr( "Error reading event: " ) + \
e.what() ); @@ -74,8 +73,10 @@
Q_ASSERT( !root.isNull() && !metadata.isNull() && !report.isNull() );
// extend metadata tag: add year, and serial (week) number:
// temp:
- const int year = 2009;
- const int week = 17;
+ // the start date of the week, specified on the command line:
+ const QDateTime start( options.date(), QTime(), Qt::UTC );
+ int year;
+ const int week = start.date().weekNumber( &year );
{
QDomElement yearElement = document.createElement( "year" );
@@ -88,12 +89,16 @@
QDomText weektext = document.createTextNode( QString::number( week ) \
); weekElement.appendChild( weektext );
}
+
{ // effort
// make effort element:
QDomElement effort = document.createElement( "effort" );
report.appendChild( effort );
// create elements:
Q_FOREACH( Event event, events ) {
+ const QDateTime end = start.addSecs( event.duration() );
+ event.setStartDateTime( start );
+ event.setEndDateTime( end );
effort.appendChild( event.toXml( document ) );
}
}
@@ -114,7 +119,11 @@
return 0;
} catch( TimesheetGenerator::UsageException& e ) {
cerr << e.what() << endl;
- // FIXME print usage
+ cout << "Usage: " << endl
+ << " * TimesheetGenerator -h <-- get \
help" + << endl
+ << " * TimesheetGenerator -f template-filename -d date <-- \
generate timesheets from template for that date" + << endl;
return 1;
} catch( TimesheetGenerator::Exception& e ) {
cerr << e.what() << endl;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic