Commits

Andrew Peterson  committed f4c0d00

Convert most print messages to logging messages. Some messages are left as prints because they only make sense as console output.

  • Participants
  • Parent commits a1b68dc

Comments (0)

Files changed (8)

File pyshipcommand_gui/__init__.py

 from twisted.internet import reactor, task
 import pygame
 from ocempgui.widgets import TwistedRenderer
+
+# PYSHIPCOMMAND
 from djlib.game import GameClass
 import djlib.logger as logger
 log = logger.getLogger('pyshipcommand.gui')
 
-# PYSHIPCOMMAND
 from cscripts import ClientScriptMgr
 from client import GUIClient
 from viewer import StarGenerator
         # Load the default font
         self.dfont = pygame.font.Font(pygame.font.get_default_font(), 12)
         if not self.dfont:
-            print "Default Font not loaded!"
+            log.error("Default Font not loaded!")
 
         # Be sure to initialize base GameClass
         GameClass.initialize(self)

File pyshipcommand_gui/client.py

 from cscripts import ClientScriptMgr
 from pyshipcommand.network import PBClient, NetVector, NetShip, NetInit, NetScript, NetCelestialBody
 
+from djlib.logger import getLogger
+log = getLogger('pyshipcommand.gui.client')
+
 class BaseClient(PBClient):
     def __init__(self):
         PBClient.__init__(self)
         # Sanity check
         if not net_ships:
             return
-        print "Received %d ship updates!" % (len(net_ships))
+        log.debug("Received %d ship updates!", len(net_ships))
 
         # We only use ship updates when we are in the ViewerState
         state = self.gc.getActiveState()
     def setClientInit(self, init_data):
         # Load player scripts
         self.scripts.setActivePlayer(init_data.player)
-        print "Scripts:", self.scripts.getScriptList()
+        log.info("Scripts: %s", self.scripts.getScriptList())
 
         # Cache current server scripts for player
         self.scripts.setServerScripts(init_data.scripts)

File pyshipcommand_gui/cscripts.py

 
-from pyshipcommand.scripts import Script, ScriptMgr
+# SYSTEM
 import os.path
 
+# ADDITIONAL LIBRARIES
+
+# PYSHIPCOMMAND
+from djlib.logger import getLogger
+log = getLogger('pyshipcommand.gui.cscripts')
+
+from pyshipcommand.scripts import Script, ScriptMgr
+
 # CONSTANTS
 SCRIPT_DIR = "cscripts"
 
 				if ls.lastHash == s.last_hash:
 					ls.version = s.version
 				else:
-					print "Script %s[%s] not in sync with server [%s]!" % (ls.name, ls.lastHash, s.last_hash)
+					log.error("Script %s[%s] not in sync with server [%s]!", ls.name, ls.lastHash, s.last_hash)
 
 	def setActivePlayer(self, player):
 
 			name = os.path.splitext(os.path.basename(scriptfile))[0]
 			data = f.read()
 
-			print "importing script:" + name
+			log.debug("importing script: %s", name)
 			self.giveScript(name, data)
 			return self.getScript(name)
 		return None
 
 		player_dir = os.path.join(self.smgr.script_dir, self.curr_player)
 		return self.smgr._loadPlayerScripts(self.curr_player, player_dir)
-
-
 #end ClientScriptMgr
 
 

File pyshipcommand_gui/dialogs.py

 
+# ADDITIONAL LIBRARIES
 from ocempgui import widgets
 from ocempgui.widgets.Constants import *
 
+# LOCAL
+from djlib.logger import getLogger
+log = getLogger('pyshipcommand.gui.dialogs')
+
 class ShipInfoWidget(widgets.Table):
     
     FRAME_WIDTH = 200
         widgets.Table.notify(self, event)
         
     def _buttonCB(self, button):
-        print button.text
+        log.debug(button.text)
 #end MovementWidget
 
 
     def select_script(self, script):
         for i in self.scrollWnd.items:
             if i.text == script:
-                print "Selecting " + script
+                log.debug("Selecting %s", script)
                 self.scrollWnd.select(i)
                 return
 
     def _upload_item(self, slist, button):
         for s in slist.get_selected():
             self.upload_cb(s.text.split()[0])
-            print s.text
         button.sensitive = False
 
     def _update_button(self, slist, button):

File pyshipcommand_gui/states/loading.py

 import pygame
 
 # LOCAL
+
 from djlib.game import GameState
 from djlib.primitives import Vector
+from djlib.logger import getLogger
+log = getLogger('pyshipcommand.gui.state.loading')
 
 from viewer import ViewerState
 

File pyshipcommand_gui/states/login.py

 import pygame
 
 # LOCAL
-from djlib.game import GameState
 from pyshipcommand_gui.dialogs import LoginDialog
-from djlib.primitives import Circle, Point, Rect
-
-#REMOVE
 from pyshipcommand_gui.client import RegisterClient
 
+from djlib.game import GameState
+from djlib.primitives import Circle, Point, Rect
+from djlib.logger import getLogger
+log = getLogger('pyshipcommand.gui.state.login')
+
 # CONSTANTS
 TITLE_POS = (100, 50)
 ORBIT_RADIUS = 500

File pyshipcommand_gui/states/viewer.py

 from pyshipcommand_gui.viewer import ShipViewer
 import pyshipcommand_gui.dialogs as dialogs
 
+from djlib.logger import getLogger
+log = getLogger('pyshipcommand.gui.state.viewer')
+
 # TestState
 class ViewerState(GameState, INotifyable):
 
                 self.sel_ship = self.ship_view.pickShip(real_pos)
                 self.ship_wnd.setShip(self.sel_ship)
                 self.script_wnd.setShip(self.sel_ship)
-                print str(self.sel_ship)
+                log.debug("Selected %s", str(self.sel_ship))
 
         elif event.signal == SIG_MOUSEMOVE:
             # Set scroll direction
 
         # Remove any expired delay text
         while len(self.delay_text) > 0 and self.gc.time > self.delay_text[0][0]:
-            print "Removing Text", self.gc.time, self.delay_text[0]
             del self.delay_text[0]
 
     def render(self):
             text = [str(text)]
             
         for t in text:
-            print t
             self.delay_text.append( (self.gc.time+delay, t) )
-        print self.delay_text
+        log.debug(self.delay_text)
 
     def leave(self):
         """Called whenever we switch from this state to another."""
             body_count[body.type] += 1
             #print "Body[%d] %s(%d)" % (body.type, str(body.pos), body.radius)
 
-        print "Universe contains %d Suns, %d Planets, %d Asteroids, %d Unknowns" % tuple(body_count)
+        log.info("Universe contains %d Suns, %d Planets, %d Asteroids, %d Unknowns", *tuple(body_count))
 
     def updateShips(self, net_ships):
         self.ship_view.updateShips(net_ships)
             pos = self.ships[self.ship_view.mship].pos
 
         d = pos - self.view_rect.center()
-        print "%s -> %s" % (self.view_rect.center(), pos)
+        log.debug("%s -> %s", self.view_rect.center(), pos)
         self.view_rect.move(d)
-        print str(self.view_rect)
+        log.debug(self.view_rect)
         self.gc.stars.setView(self.view_rect, True)
 
     def _createDialogs(self):
-        print "CREATING VIEWER DIALOGS!!!!"
         (w,h) = self.gc.rsurf.get_size()
         
         # CLI Entry
             try:
                 method(*args)
             except Exception, e:
-                    print 'Error', str(e)
+                    log.error('Error %s', str(e))
 
     def cmd_help(self, command=None):
         """help [command]: List commands, or show help on the given command"""
 
         s = self.gc.client.scripts.getScript(scriptfile)
         if s:
-            print "sending script:", s.name
+            log.info("sending script: %s", s.name)
             self.gc.client.giveScript(s.name, s.source)
             return
 
-        print scriptfile + " not found!"
+        log.error("%s not found!", scriptfile)
 
 
     def cmd_import(self, scriptPath = None):
             #self.script_wnd.select_script(s.name)
             return
 
-        print "Could not import:" + scriptFiles
+        log.error("Could not import: %s", scriptFiles)
 
     def cmd_reload(self):
 
 
 
     def cmd_ship(self, cmd, *args):
-        print "cmd_ship", cmd, ":", args
+        log.debug("cmd_ship %s : %s", cmd, str(args))
         if cmd == "create":
             pos = Vector(0.0, 0.0)
             if len(args) == 2:
                 pos = Vector(float(args[0]), float(args[1]))
-            print pos
+            log.debug(pos)
             self.gc.client.addShip(pos)
         elif cmd == "move":
             ship_id = int(args[0])
             target_pos = Vector(float(args[1]), float(args[2]))
-            print target_pos
+            log.debug(target_pos)
             self.gc.client.moveShip(ship_id, target_pos)
         elif cmd == "orbit":
             ship_id = int(args[0])
         ship_view.SCROLL_SPEED = scroll_speed
 
     def cmd_msg(self, *args):
-        print "cmd_msg, ", args
+        log.debug("cmd_msg: %s", str(args))
         self.gc.client.giveMessage(args)
 
     def cmd_home(self):
     def cmd_players(self):
         self.gc.client.getPlayers()
         
-
-#end TestState
+#end ViewerState
 

File pyshipcommand_gui/viewer.py

 
+# ADDITIONAL LIBRARIES
 import pygame
+
+# LOCAL
 from djlib.primitives import Vector, Rect
 from djlib.spatial import ExpandingRectTree
+from djlib.logger import getLogger
+log = getLogger('pyshipcommand.gui.viewer')
 
 class ShipViewer:
     
 
     def setClientInit(self, init_data):
 
-        print "ClientInit Received with Player ID %d" % (self.player_id)
-        print "Server Step: %f" % (init_data.server_step)
-        print "View Position: %s" % (str(init_data.start_pos))
+        log.info("ClientInit Received with Player ID %d", self.player_id)
+        log.info("Server Step: %f", init_data.server_step)
+        log.info("View Position: %s", str(init_data.start_pos))
 
         self.player_id = init_data.player_id
         self.setServerStep(init_data.server_step)
     def updateShips(self, net_ships):
 
         # delete any ships not updated last frame
-        print self.destroyed_ships
+        log.debug(self.destroyed_ships)
         for ship_id in self.destroyed_ships:
             self.tree.remove(self.ships[ship_id])
             del self.ships[ship_id]
 
         self.destroyed_ships = self.ships.keys()
-        print self.destroyed_ships
+        log.debug(self.destroyed_ships)
 
         for nship in net_ships:
             ship = self.ships.get(nship.id)
         if not new_node:
             new_node = self.tree
         if new_node != self.view_node:
-            print "New view node has %d ships." % (new_node.count())
+            log.debug("New view node has %d ships.", new_node.count())
             self.view_node = new_node
         self.drawTree(rs, self.view_node, pos)
 
         rs.blit(surf, pos)
 
     def setServerStep(self, dt):
-        print "Server time step set to %f seconds" % (dt)
+        log.info("Server time step set to %f seconds", dt)
         self.server_step = dt
 
     def pickShip(self, real_pos):
-        
-
         # Compare mouse pos against all visible ships
         close_ship = None
         close_dist = self.SHIP_RADIUS
             star_pos = Vector((star_size[0]-screen_size[0])/-2, (star_size[1]-screen_size[1])/-2)
 
             self.star_bounds = Rect(star_pos, star_size)
-            print self.star_bounds
+            log.debug(self.star_bounds)
             
             # create initial sectors
             self.sectors = []
                     self.star_bounds.move(Vector(-self.sector_size[0], 0))
                     for y in range(self.repeat[1]):
                         self.sectors.append(self._generateSector(self.star_bounds.pos + Vector(0, y*self.sector_size[1])))
-                    print "Gen Left"
+                    log.debug("Gen Left")
 
                 # Gen Right
                 elif view_corner[0] > star_corner[0]:
                     start = Vector(star_corner[0], self.star_bounds.pos[1])
                     for y in range(self.repeat[1]):
                         self.sectors.append(self._generateSector(start + Vector(0, y*self.sector_size[1])))
-                    print "Gen Right"
+                    log.debug("Gen Right")
 
                 # Gen Up
                 if view_rect.pos[1] < self.star_bounds.pos[1]:
                     self.star_bounds.move(Vector(0, -self.sector_size[1]))
                     for x in range(self.repeat[0]):
                         self.sectors.append(self._generateSector(self.star_bounds.pos + Vector(x*self.sector_size[0], 0)))
-                    print "Gen Up"
+                    log.debug("Gen Up")
 
                 # Gen Down
                 elif view_corner[1] > star_corner[1]:
                     start = Vector(self.star_bounds.pos[0], star_corner[1])
                     for x in range(self.repeat[0]):
                         self.sectors.append(self._generateSector(start + Vector(x*self.sector_size[0], 0)))
-                    print "Gen Down"
+                    log.debug("Gen Down")
 
             else: #full_gen
                 # create initial sectors
                 self.sectors = []
-                print str(self.star_bounds)
+                log.debug(self.star_bounds)
                 star_overlap = Vector((self.star_bounds.size[0]-view_rect.size[0])/-2,
                                       (self.star_bounds.size[1]-view_rect.size[1])/-2)
                 self.star_bounds.setPosition(view_rect.pos + star_overlap)
                         self.sectors.append(self._generateSector(
                             self.star_bounds.pos + Vector(x*self.sector_size[0], y*self.sector_size[1])))
 
-                print "Full Generation of %d sectors" % (len(self.sectors))
-                print str(self.star_bounds)
+                log.debug("Full Generation of %d sectors", len(self.sectors))
+                log.debug(self.star_bounds)
             #end if
 
-            print "Generated %d sectors" % (len(self.sectors) - sect_count)
+            log.debug("Generated %d sectors", len(self.sectors) - sect_count)
             sect_count = len(self.sectors)
 
             # Delete any sectors that are no longer visible
             self.sectors = [sector for sector in self.sectors if self.star_bounds.contains(sector.pos)]
-            print "Deleted %d sectors" % (sect_count - len(self.sectors))
+            log.debug("Deleted %d sectors", sect_count - len(self.sectors))
 
     def draw(self, rs, view_rect = None):
         pos = Vector(0,0)