Index: Mattricks/Commandline.py
===================================================================
RCS file: /cvsroot/mattricks/Mattricks/Mattricks/Commandline.py,v
retrieving revision 1.6
diff -u -d -b -w -u -r1.6 Commandline.py
--- Mattricks/Commandline.py	24 Jan 2004 12:02:12 -0000	1.6
+++ Mattricks/Commandline.py	27 Jan 2004 15:00:40 -0000
@@ -424,12 +424,11 @@
 
     import os, re
     import string, time
-    import HRFData, MatchInfo, Terms, Fixtures
+    import HRFData, MatchInfo, Terms, Fixtures, CommonData, XMLParse
 
     player_usage = _("""Usage: %s players [args]
 Options:
 
-  -l LEAGUE  --league-id=LEAGUE  The league id of the table.
   -s SEASON  --season=SEASON     Which season to use.
   -t TEAM    --team-id=TEAM      Print the info for this TEAM.
 """) % (sys.argv[0])
@@ -439,27 +438,18 @@
         sys.exit()
 
     try:
-        (options, args) = getopt.getopt(args, "l:t:s:", ["league-id=",
-                                                         "team-id=",
+        (options, args) = getopt.getopt(args, "t:s:", ["team-id=",
                                                          "season="])
     except getopt.GetoptError, e:
         sys.stdout.write(str(e) + "\n\n")
         sys.stdout.write(player_usage)
         sys.exit(2)
 
-    league_id = -1
-    team_id = -1
-    season = -1
+    league_id = None
+    team_id = None
+    season = None
 
     for o, a in options:
-        if o in ["-l", "--league-id"]:
-            try:
-                league_id = int(a)
-            except ValueError, e:
-                sys.stdout.write(_("Id %s is not a valid league id.") % a + "\n\n")
-                sys.stdout.write(player_usage)
-                sys.exit(2)
-    for o, a in options:
         if o in ["-t", "--team-id"]:
             try:
                 team_id = int(a)
@@ -476,57 +466,77 @@
                 sys.stdout.write(player_usage)
                 sys.exit(2)
 
-    if league_id is -1 or team_id is -1 or season is -1:
-        sys.stdout.write(_("%s is not a valid season.") % a + "\n\n")
+    """ Get the default team_id """
+    if team_id is None:
+        team_id = CommonData.get_current_teamid()
+        sys.stdout.write(_("Setting default for %s: %d.") % ("team", team_id) + "\n")
+    
+    """ Use the team_id to get the league_id and season, unless specified """
+    data = XMLParse.get(["team details", team_id],
+                        ["Team.League.LeagueID",
+                        "Team.LeagueLevelUnit.LeagueLevelUnitID"])
+
+    league_id = data.get("Team.LeagueLevelUnit.LeagueLevelUnitID")
+
+    if season is None:
+        lid = data.get("Team.League.LeagueID")
+        if lid is not None:
+            season = CommonData.get_league_season(lid)
+            sys.stdout.write(_("Setting default for %s: %d.") % ("season", season) + "\n")
+
+    if league_id is None or team_id is None or season is None:
+        sys.stdout.write(_("Unable to find specified team, league or season.") + "\n\n")
         sys.stdout.write(player_usage)
         sys.exit(2)
 
     players = {}
 
     fixture = Fixtures.Fixtures(league_id, season)
-    sys.stdout.write(fixture.league_name + "(" + str(league_id) +
-                     "), Season " + str(fixture.season) + "\n")
+    sys.stdout.write(_("Team %d %s(%d) Season %d") % 
+                    (team_id, fixture.league_name, league_id, fixture.season) + "\n")
 
+    """ Loop thru every round this season. Should gather data from matchlist instead """
     for round in range(0, 14):
         for match_id, match_info in fixture.matches[round + 1].iteritems():
             if not match_info[3]:
                 continue
 
+            """ Check if Im one of the teams """
             if match_info[1][0] == team_id or match_info[2][0] == team_id:
+                """ Print each match as we see them """
                 match_lineup = MatchInfo.MatchLineup(match_id, team_id)
-                sys.stdout.write("    " + time.strftime("%Y-%m-%d",
-                                                        time.gmtime(match_lineup.match_date)) +
-                                 ": " + match_info[1][1] + " - " + match_info[2][1] +
-                                 " " + str(match_lineup.total_rating) + "\n")
+                sys.stdout.write("    %s: %s - %s %.1f\n" % 
+                                (time.strftime("%Y-%m-%d", time.gmtime(match_lineup.match_date)),
+                                 match_info[1][1], match_info[2][1],
+                                 match_lineup.total_rating))
 
+                """ Loop thru every position """
                 for i in range(1,22):
                     (id, name, rating, position, behaviour) = match_lineup.lineup[i]
 
                     if id is None or id is 0 or rating is None:
                         continue
 
-                    position_text = Terms.team_role[i]
-                    if behaviour is not None:
-                        position_text += ", " + Terms.individual_order[behaviour]
-
+                    """ Save the info. The players var is a map where each id points at
+                        a array of arrays. Each top array is one match-performance and
+                        it contains date, rating, position and behaviour """
                     if players.has_key(id):
-                        #sys.stdout.write("Append: " + name + " " + str(rating) + "\n")
                         players[id]["matches"] += [[match_lineup.match_date, rating,
                                                     position, behaviour]]
                     else:
-                        #sys.stdout.write("New: " + name + " " + str(rating) + "\n")
                         players[id] = {"name":name, "matches":[[match_lineup.match_date, rating,
                                                                 position, behaviour]]}
 
     sys.stdout.write("\n\n")
+    """ Repeat thru the players we have found """
     for playerid, playerinfo in players.iteritems():
         sys.stdout.write(playerinfo["name"] + " (" + str(playerid) + "):\n")
         for match in playerinfo["matches"]:
             match_date, rating, position, behaviour = match
             sys.stdout.write("    " + time.strftime("%Y-%m-%d", time.gmtime(match_date)) +
                              ": " + str(rating) + "*")
-            if position is None or behaviour is None:
-                sys.stdout.write(" (Replaced)\n")
+            if position is None:
+                sys.stdout.write(" (" + _("Unknown") + ")\n")
             else:
                 sys.stdout.write(" at " + Terms.team_role[position] + ", " +
                                  Terms.individual_order[behaviour] + "\n")
