[ditrack commit] r2311 - in src/trunk: . DITrack

Vlad Skvortsov vss at 73rus.com
Thu Nov 1 15:21:56 PST 2007


oleg at ditrack.org wrote:
> Author: oleg
> Date: 2007-10-30 09:36:56 -0800 (Tue, 30 Oct 2007)
> New Revision: 2311
>
> Modified:
>    src/trunk/DITrack/Logging.py
>    src/trunk/dt
> Log:
> implemented function for initialization debug mode and options
>
>
> Modified: src/trunk/DITrack/Logging.py
> ===================================================================
> --- src/trunk/DITrack/Logging.py	2007-10-29 13:25:48 UTC (rev 2310)
> +++ src/trunk/DITrack/Logging.py	2007-10-30 17:36:56 UTC (rev 2311)
> @@ -33,6 +33,9 @@
>  import traceback
>  import logging
>  
> +DEBUG_ON = False
> +DEBUG_OPTIONS = []
>   

Why all capitals? These are variables, not constants.


> +
>  def get_caller():
>      """
>      Returns the grand-caller of the function in a form of string "[FILE:LINE]".
>   

Since get_caller() is now invoked from DEBUG rather than from DEBUG's 
callers, it needs to go one level deeper in the stack frame to print out 
the same data.

> @@ -51,16 +54,24 @@
>      Sends STR to logging.debug(), prepending it with the file name and line of
>      the caller.
>      """
> +    global DEBUG_ON, DEBUG_OPTIONS
>   

Not really needed.

>  
> -    if not os.environ.has_key("DITRACK_DEBUG"):
> +    if DEBUG_ON == False:
>   

Python encourages just "if DEBUG_ON:".


>          return
>  
> -    level = os.environ["DITRACK_DEBUG"]
> -    if show_caller and level.startswith("c"):
> -        level = level[1:] 
> +    if show_caller and "c" in DEBUG_OPTIONS:
>   

This "c" should be documented somewhere (comments, hacking.txt?)

>          str = get_caller() + " " + str
>  
> -    level = int(level)
> +    logging.debug("%s" % str)
>  
> -    logging.basicConfig(level=level)
> -    logging.debug("%s" % str)
> +def init_debug():
>   

I thinks this should be renamed to just init() -- it effectively does 
the whole module initialization, not just the debugging part.

> +
> +    global DEBUG_ON, DEBUG_OPTIONS
>   

Not needed.

> +
> +    if "DITRACK_DEBUG" in os.environ:
> +        DEBUG_ON = True
> +
> +        if "c" in os.environ["DITRACK_DEBUG"]:
> +            DEBUG_OPTIONS.append("c")
>   

Why not just copy the whole string to DEBUG_OPTIONS? Or, alternatively, 
if we are parsing out the options here, why not add another mnemonic 
variable like debug_options["show caller"]?


> +
> +        logging.getLogger().setLevel(logging.DEBUG)
>
> Modified: src/trunk/dt
> ===================================================================
> --- src/trunk/dt	2007-10-29 13:25:48 UTC (rev 2310)
> +++ src/trunk/dt	2007-10-30 17:36:56 UTC (rev 2311)
> @@ -44,6 +44,7 @@
>  import DITrack.Command.remove
>  import DITrack.Command.status
>  import DITrack.Command.update
> +import DITrack.Logging
>  import DITrack.Util.cmdline
>  
>  ################################# GLOBALS ############################
> @@ -266,8 +267,7 @@
>      "up":           cmd_update,
>  })
>  
> -if "DITRACK_DEBUG" in os.environ:
> -    logging.getLogger().setLevel(logging.DEBUG)
> +DITrack.Logging.init_debug()
>  
>  try:
>      opts = DITrack.Util.cmdline.ParseResults([
>
> _______________________________________________
> Commit mailing list
> Commit at lists.ditrack.org
> http://lists.ditrack.org/mailman/listinfo/commit
>   


-- 
Vlad Skvortsov, vss at 73rus.com, http://vss.73rus.com



More information about the Dev mailing list