# Path: opentaxforms/ut.py
# NL = '\n'
# TAB = '\t'
# def merge(bb1, bb2):
# def numerify(s):
# def compactify(multilineRegex):
#     def crunch(seg):
# def pickle(data, pickleFilePrefix):
# def unpickle(pickleFilePrefix, default=None):
# def flattened(l):
# def hasdups(l, key=None):
# def uniqify(l):
# def uniqify2(l):
# def setupLogging(loggerId, args=None):
# def unsetupLogging():
# def logg(msg, outputs=None):
# def jj(*args, **kw):
# def jdb(*args, **kw):
# def run0(cmd):
# def run(cmd, logprefix='run', loglevel='INFO'):
#     def __init__(self, pkgname, fpath=None):
#     def path(self):
#     def content(self):
#     def keys(cls):
#     def vals(cls):
#     def items(cls):
#     def __init__(self):
#     def __call__(self, **kw):
#     def __init__(self, *maps, **kw):
#     def _getGetitems(self, mapp):
#     def __getitem__(self, key):
#     def __setitem__(self, key, val):
#     def __len__(self):
#     def __call__(self, *keys):
#     def clear(self):
#     def update(self, *maps):
#     def __add__(self, *maps):
#     def __iadd__(self, *maps):
#     def __iter__(self):
#     def iterkeys(self):
#     def keys(self):
#     def values(self):
#     def items(self):
#     def iteritems(self):
#     def get(self, key, dflt=None):
#     def __str__(self):
#     def __repr__(self):
# def notequalpatch(self, o):
#     def fromstring(cls, s):
#     def __hash__(self):
# def playQnty():
# def nth(n):
# def skip(s, substr):
# def until(s, substr):
# def ensure_dir(folder):
# def now(format=None):
# def readImgSize(fname, dirName):
# def asciiOnly(s):
# class NoSuchPickle(Exception):
# class PickleException(Exception):
# class Resource(object):
# class CharEnum(object):
# class ChainablyUpdatableOrderedDict(odict):
# class Bag(object):
# class Qnty(qq):
# 
# Path: opentaxforms/version.py



import os
import os.path
import re
import shutil
import sys
        import shutil
        import doctest
from argparse import ArgumentParser
from os.path import isfile, join as joinpath
from six.moves.urllib.request import urlopen
from six.moves.urllib.error import URLError
from . import ut
from .ut import log, Bag, setupLogging, logg, NL, pathjoin
from .version import appname, appversion
        from .Form import Form
           help='number of levels to recurse thru, defaults to infinite',
           dest='maxrecurselevel', default=defaults.maxrecurselevel)
    addarg('-k', '--skip', nargs='?', default=[],
           help='steps to skip, can be any combination of: ' + ' '.join(
           '='.join((k, v)) for k, v in SkippableSteps.items()), dest='skip')
    addarg('-C', '--useCaches',
           help='recompute cached intermediate results', action="store_true")
    addarg('-P', '--postgres',
           help='use postgres database [default=sqlite]', action="store_true")
    addarg('-V', '--version', help='report version and exit',
           default=False, action="store_true")
    addarg('--calledFromCmdline',
           help='signals that script is run from commandline', default=True)
    return parser.parse_args()


def getFileList(dirName):
    # todo replace this section in task formDictionary
    allpdffname='allpdfnames.txt'
    allpdfpath = pathjoin(dirName,allpdffname)
    if not ut.exists(allpdfpath):
        if 1:  # until resolve urllib2 code below
            # todo either use allpdfnames file in place,
            #      or run all symlinking as a separate pass
            allpdfpath = ut.Resource(appname, 'static/'+allpdffname).path()
            allpdfLink = pathjoin(dirName,allpdffname)
            try:
                if not ut.exists(allpdfLink):
                    os.symlink(allpdfpath, allpdfLink)
            except Exception as e:

# Path: opentaxforms/ut.py
# NL = '\n'
# TAB = '\t'
# def merge(bb1, bb2):
# def numerify(s):
# def compactify(multilineRegex):
#     def crunch(seg):
# def pickle(data, pickleFilePrefix):
# def unpickle(pickleFilePrefix, default=None):
# def flattened(l):
# def hasdups(l, key=None):
# def uniqify(l):
# def uniqify2(l):
# def setupLogging(loggerId, args=None):
# def unsetupLogging():
# def logg(msg, outputs=None):
# def jj(*args, **kw):
# def jdb(*args, **kw):
# def run0(cmd):
# def run(cmd, logprefix='run', loglevel='INFO'):
#     def __init__(self, pkgname, fpath=None):
#     def path(self):
#     def content(self):
#     def keys(cls):
#     def vals(cls):
#     def items(cls):
#     def __init__(self):
#     def __call__(self, **kw):
#     def __init__(self, *maps, **kw):
#     def _getGetitems(self, mapp):
#     def __getitem__(self, key):
#     def __setitem__(self, key, val):
#     def __len__(self):
#     def __call__(self, *keys):
#     def clear(self):
#     def update(self, *maps):
#     def __add__(self, *maps):
#     def __iadd__(self, *maps):
#     def __iter__(self):
#     def iterkeys(self):
#     def keys(self):
#     def values(self):
#     def items(self):
#     def iteritems(self):
#     def get(self, key, dflt=None):
#     def __str__(self):
#     def __repr__(self):
# def notequalpatch(self, o):
#     def fromstring(cls, s):
#     def __hash__(self):
# def playQnty():
# def nth(n):
# def skip(s, substr):
# def until(s, substr):
# def ensure_dir(folder):
# def now(format=None):
# def readImgSize(fname, dirName):
# def asciiOnly(s):
# class NoSuchPickle(Exception):
# class PickleException(Exception):
# class Resource(object):
# class CharEnum(object):
# class ChainablyUpdatableOrderedDict(odict):
# class Bag(object):
# class Qnty(qq):
# 
# Path: opentaxforms/version.py



# Path: opentaxforms/config.py
import os
import os.path
import re
import shutil
import sys
        import shutil
        import doctest
from argparse import ArgumentParser
from os.path import isfile, join as joinpath
from six.moves.urllib.request import urlopen
from six.moves.urllib.error import URLError
from . import ut
from .ut import log, Bag, setupLogging, logg, NL, pathjoin
from .version import appname, appversion
        from .Form import Form

           help='number of levels to recurse thru, defaults to infinite',
           dest='maxrecurselevel', default=defaults.maxrecurselevel)
    addarg('-k', '--skip', nargs='?', default=[],
           help='steps to skip, can be any combination of: ' + ' '.join(
           '='.join((k, v)) for k, v in SkippableSteps.items()), dest='skip')
    addarg('-C', '--useCaches',
           help='recompute cached intermediate results', action="store_true")
    addarg('-P', '--postgres',
           help='use postgres database [default=sqlite]', action="store_true")
    addarg('-V', '--version', help='report version and exit',
           default=False, action="store_true")
    addarg('--calledFromCmdline',
           help='signals that script is run from commandline', default=True)
    return parser.parse_args()


def getFileList(dirName):
    # todo replace this section in task formDictionary
    allpdffname='allpdfnames.txt'
    allpdfpath = pathjoin(dirName,allpdffname)
    if not ut.exists(allpdfpath):
        if 1:  # until resolve urllib2 code below
            # todo either use allpdfnames file in place,
            #      or run all symlinking as a separate pass
            allpdfpath = ut.Resource(appname, 'static/'+allpdffname).path()
            allpdfLink = pathjoin(dirName,allpdffname)
            try:
                if not ut.exists(allpdfLink):
                    os.symlink(allpdfpath, allpdfLink)
            except Exception as e:

                log.warn('cannot symlink %s to %s because %s, copying instead'%(