Package pysql :: Module pysqlhelpers
[hide private]
[frames] | no frames]

Module pysqlhelpers

source code

This module defines some common useful helper functions


Author: Sébastien Renard (sebastien.renard@digitalfox.org)

License: GNU GPL V3

Classes [hide private]
  WaitCursor
A waiting cursor for long operation that catch output and flush it after waiting
Functions [hide private]
 
addWildCardIfNeeded(aString, wildcard="%")
If aString does not have any wildcard, add one at the begining and one at the end
source code
 
colorDiff(diff)
Transforms poorly readable ndiff output into colored diff
source code
 
convert(value, unit)
Converts an number in Bytes into a bigger unit.
source code
 
getProg(availables, given, default)
Checks if 'given' graphviz program is in the 'availables' list Raises an exception if program is not available or return the prog (default if given is 'auto'
source code
 
itemLength(item)
Compute length of a result set item
source code
 
generateWhere(keyword, filterClause)
Generate where clause from pysql syntax to filter Oracle object Pysql syntax : pattern1 or (pattern2 and pattern3).
source code
 
removeComment(line, comment=False)
Removes SQL comments from line
source code
 
which(progName)
Mimics the Unix which command
source code
 
warn(message)
Just print a formated warning message on screen if PYSQL_WARNING env var is set (whatever value)
source code
 
printStackTrace()
Print stack trace with debug information
source code
 
setTitle(title, codec)
Sets the window title
source code
 
getTitle()
Gets the window title
source code
 
getTermWidth()
Gets the terminal width.
source code
 
upperIfNoQuotes(aString)
Used for Oracle owner and name case policy
source code
Function Details [hide private]

colorDiff(diff)

source code 

Transforms poorly readable ndiff output into colored diff

Parameters:
  • diff - generator returned by difflib.ndiff() function
Returns:
list of string diffs with color to highlight diff

convert(value, unit)

source code 

Converts an number in Bytes into a bigger unit. Beware of any data loss

getProg(availables, given, default)

source code 

Checks if 'given' graphviz program is in the 'availables' list Raises an exception if program is not available or return the prog (default if given is 'auto'

Parameters:
  • availables - dict of graphviz availables program as return by find_graphivz()
  • given - program choose by user
  • default - program used if user choose default

generateWhere(keyword, filterClause)

source code 

Generate where clause from pysql syntax to filter Oracle object Pysql syntax : pattern1 or (pattern2 and pattern3). Pattern are all accepted Oracle like pattern

Parameters:
  • filter - pysql where clause syntax as a list of words
  • keyword - the database object name on which filter apply
Returns:
SQL where clause

removeComment(line, comment=False)

source code 

Removes SQL comments from line

Parameters:
  • line (str) - SQL line from which we want to remove comment
  • comment (bool) - flag to indicate if we are in the middle of a multiline comment (default is false)
Returns:
line modified (str) and a flag (bool) that indicate if we are in a multiline comment

which(progName)

source code 

Mimics the Unix which command

Parameters:
  • progName - program name that will be search through PATH
Returns:
full path to program or None if not find in PATH

warn(message)

source code 

Just print a formated warning message on screen if PYSQL_WARNING env var is set (whatever value)

Parameters:
  • message - unicode or str message. Conversion will done with print and default encoding

setTitle(title, codec)

source code 

Sets the window title

Parameters:
  • title (unicode string) - window title
  • codec - codec used to encode string

getTitle()

source code 

Gets the window title

Returns:
str

getTermWidth()

source code 

Gets the terminal width. Works only on Unix system.

Returns:
terminal width or "120" is system not supported

upperIfNoQuotes(aString)

source code 

Used for Oracle owner and name case policy

Parameters:
  • aString - input string to parse
Returns:
Upper case string if no quotes are given, else remove quotes and leave string as is