bin/pypngtile
author Tero Marttila <terom@fixme.fi>
Mon, 25 Jan 2010 04:34:02 +0200
changeset 88 5cc2d044d368
parent 79 016c20a15283
permissions -rwxr-xr-x
pypngtile: --out
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#!/usr/bin/env python
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
"""
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
    Python clone of the pngtile binary.
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
"""
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
     7
import optparse, sys
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
import pypngtile as pt
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
# CLI options
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
options = None
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    14
def log (fmt, args) :
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    15
    print >>sys.stderr, fmt % args
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    16
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
def log_debug (fmt, *args) :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
    if options.debug or options.verbose :
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    19
        log(fmt, args)
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
def log_info (fmt, *args) :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
    if not options.quiet :
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    23
        log(fmt, args)
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
def log_warn (fmt, *args) :
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    26
    log(fmt, args)
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
def parse_hex (hex) :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
        Parse a 0xHH.. style string as a raw bytestring
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
    if not hex.startswith("0x") :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
        raise ValueError(hex)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
    return hex[2:].decode("hex")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
def parse_args (args) :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
        Parse given argv[1:]
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
    global options
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
    parser = optparse.OptionParser(
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
            usage   = "Usage: %prog [options] <image file> [...]",
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
    )
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
    # build opts list
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
    parser.add_option('-q', "--quiet",          help="Supress informational output",                        action='store_true')
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
    parser.add_option('-v', "--verbose",        help="Display more output",                                 action='store_true')
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
    parser.add_option('-D', "--debug",          help="Equivalent to -v",                                    action='store_true')
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
    parser.add_option('-U', "--force-update",   help="Unconditionally update the image caches",             action='store_true')
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
    parser.add_option('-N', "--no-update",      help="Do not update the image caches, even if unusable",    action='store_true')
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
    parser.add_option('-B', "--background",     help="Background pattern for sparse cache file",            metavar="0xHH..")
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    57
    parser.add_option('-W', "--width",          help="Output tile width",                                   metavar="PX",       type='int', default=800)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    58
    parser.add_option('-H', "--height",         help="Output tile height",                                  metavar="PX",       type='int', default=600)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    59
    parser.add_option('-x', "--x",              help="Tile x offset",                                       metavar="PX",       type='int', default=0)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    60
    parser.add_option('-y', "--y",              help="Tile y offset",                                       metavar="PX",       type='int', default=0)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    61
    parser.add_option('-z', "--zoom",           help="Tile zoom level, -n",                                 metavar="ZL",       type='int', default=0)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    62
    parser.add_option('-o', "--out",            help="Render tile to output file, or -",                    metavar="FILE")
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    63
    
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
    # parse
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
    options, args = parser.parse_args(args=args)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
    # decode
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
    if options.background :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
        try :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    70
            options.background = parse_hex(options.background)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    71
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
        except ValueError :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    73
            raise ValueError("Invalid value for --background: %s" % options.background)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    75
    return args
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    78
def process_tile (image) :
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    79
    """
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    80
        Process output tile for given image
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    81
    """
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    82
    
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    83
    # parse out
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    84
    if options.out == '-' :
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    85
        log_debug("\tUsing stdout as output...")
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    86
        
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    87
        # use stdout
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    88
        out = sys.stdout
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    89
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    90
    else :
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    91
        log_debug("\tOpening file for output: %s", options.out)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    92
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    93
        # open file
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    94
        out = open(options.out, "wb")
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    95
    
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    96
    log_info("\tRender tile %dx%d@(%d:%d)@%d -> %s...", options.width, options.height, options.x, options.y, options.zoom, options.out)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    97
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    98
    # render
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    99
    image.tile_file(options.width, options.height, options.x, options.y, options.zoom, out)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   100
    
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   101
    log_debug("Rendered tile: %s", options.out)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   102
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   103
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   104
def process_image (image) :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   105
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   106
        Process given image
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   107
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   108
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   109
    # check cache status
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
    status = image.status()
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   111
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
    # update if stale?
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   113
    if status != pt.CACHE_FRESH or options.force_update :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
        # decode status
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
        if status == pt.CACHE_NONE :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
            log_info("\tImage cache is missing")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
        
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   118
        elif status == pt.CACHE_STALE :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   119
            log_info("\tImage cache is stale")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   120
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   121
        elif status == pt.CACHE_INCOMPAT :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   122
            log_info("\tImage cache is incompatible")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   123
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   124
        elif status == pt.CACHE_FRESH :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
            log_info("\tImage cache is fresh")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   126
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
        else :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
            log_warn("\tImage cache status unknown: %d", status)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   129
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   130
        
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   131
        # update unless supressed
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   132
        if not options.no_update :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   133
            log_info("\tUpdating image cache...")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   134
            
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   135
            # update with optional background color
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   136
            image.update(background_color=options.background)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   137
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
            log_debug("\tUpdated image cache")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   139
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   140
        else :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   141
            # warn
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   142
            log_warn("\tSupressing cache update even though it is needed")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   143
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   144
    else: 
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   145
        log_debug("\tImage cache is fresh")
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   146
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   147
        # open it
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   148
        image.open()
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   149
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   150
    # show info
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   151
    info = image.info()
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   152
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   153
    log_info("\tImage dimensions: %d x %d (%d bpp)", info['img_width'], info['img_height'], info['img_bpp'])
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   154
    log_info("\tImage mtime=%d, bytes=%d", info['image_mtime'], info['image_bytes'])
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   155
    log_info("\tCache mtime=%d, bytes=%d, blocks=%d (%d bytes), version=%d", 
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   156
            info['cache_mtime'], info['cache_bytes'], info['cache_blocks'], info['cache_blocks'] * 512, info['cache_version']
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   157
    )
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   158
    
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   159
88
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   160
    # render tile?
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   161
    if options.out :
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   162
        log_debug("\tRendering output tile")
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   163
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   164
        process_tile(image)
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   165
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   166
    else :
5cc2d044d368 pypngtile: --out
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   167
        log_debug("\tNot rendering output tile")
79
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   168
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   169
def process_images (image_paths) :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   170
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
        Open up each image_path and process using process_image
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   172
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   173
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   174
    for image_path in image_paths :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   175
        log_debug("Loading image: %s", image_path)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   176
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   177
        # open up
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   178
        image = pt.Image(image_path, pt.OPEN_UPDATE)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   179
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   180
        log_info("Opened image: %s", image_path);
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   181
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   182
        # process
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   183
        process_image(image)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   184
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   185
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   186
def main (args) :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   187
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   188
        Operate on given argv[1:]
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   189
    """
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   190
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   191
    # parse opts/args
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   192
    args = parse_args(args)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   193
    
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   194
    # handle each image
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   195
    process_images(args)
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   196
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   197
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   198
if __name__ == '__main__' :
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   199
    from sys import argv
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   200
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   201
    main(argv[1:])
016c20a15283 implement a python clone of the pngtile CLI
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   202