Back to index

python3.2  3.2.2
Functions
untabify Namespace Reference

Functions

def main
def process

Function Documentation

def untabify.main ( void  )

Definition at line 10 of file untabify.py.

00010 
00011 def main():
00012     tabsize = 8
00013     try:
00014         opts, args = getopt.getopt(sys.argv[1:], "t:")
00015         if not args:
00016             raise getopt.error("At least one file argument required")
00017     except getopt.error as msg:
00018         print(msg)
00019         print("usage:", sys.argv[0], "[-t tabwidth] file ...")
00020         return
00021     for optname, optvalue in opts:
00022         if optname == '-t':
00023             tabsize = int(optvalue)
00024 
00025     for filename in args:
00026         process(filename, tabsize)
00027 

Here is the call graph for this function:

Here is the caller graph for this function:

def untabify.process (   filename,
  tabsize,
  verbose = True 
)

Definition at line 28 of file untabify.py.

00028 
00029 def process(filename, tabsize, verbose=True):
00030     try:
00031         with tokenize.open(filename) as f:
00032             text = f.read()
00033             encoding = f.encoding
00034     except IOError as msg:
00035         print("%r: I/O error: %s" % (filename, msg))
00036         return
00037     newtext = text.expandtabs(tabsize)
00038     if newtext == text:
00039         return
00040     backup = filename + "~"
00041     try:
00042         os.unlink(backup)
00043     except os.error:
00044         pass
00045     try:
00046         os.rename(filename, backup)
00047     except os.error:
00048         pass
00049     with open(filename, "w", encoding=encoding) as f:
00050         f.write(newtext)
00051     if verbose:
00052         print(filename)
00053 

Here is the call graph for this function:

Here is the caller graph for this function: