def make_dst_dir(src, dst):
    src = os.path.normpath(src)
    dst = os.path.normpath(dst)

    if not os.path.exists(dst):
        su.createdirpath(dst)
    elif os.path.isfile(dst):
        cleanup_path(dst, 'make_dst_dir:')
        su.createdirpath(dst)

    assert(os.path.exists(dst))
    assert(os.path.isdir(dst))
def create_aux_dir(tmpdir):
    auxDir = tmpdir+'_AUXI'
    try:
        su.createdirpath(auxDir)
        ryw.db_print_info_browser('create_aux_dir: ' + auxDir, 27)
        for auxType in AUX_FIELD_TYPES:
            auxTypeDir = os.path.join(auxDir, auxType)
            su.createdirpath(auxTypeDir)
            logging.debug('create_aux_dir: ' + auxTypeDir)
    except:
        ryw.give_bad_news('create_aux_dir failed: ' + auxDir, logging.critical)
        return (False, None)

    return (True, auxDir)
def resize_thumbnails(auxDir, forced = True):

    if not os.path.exists(auxDir):
        return True

    thumbsDir = os.path.join(auxDir, 'thumbnails')
    if not os.path.exists(thumbsDir):
        return True

    thumbNames = os.listdir(thumbsDir)
    if len(thumbNames) == 0:
        return True

    for thumbName in thumbNames:
        if thumbName == 'Thumbs.db':
            continue
        thumbPath = os.path.join(thumbsDir, thumbName)
        if not ryw_view.is_image(thumbPath):
            ryw.give_bad_news(
                'resize_thumbnails: probably not an image file: ' +
                thumbPath, logging.error)
            return False

    scaledDir = os.path.join(auxDir, 'thumbs_scaled')
    if os.path.exists(scaledDir) and not forced:
        return True
    
    ryw.cleanup_path(scaledDir, 'ryw_upload.resize_thumbnails:')
    
    try:
        su.createdirpath(scaledDir)
        for thumbName in thumbNames:
            if thumbName == 'Thumbs.db':
                continue
            thumbPath = os.path.join(thumbsDir, thumbName)
            thumbDest = os.path.join(scaledDir, thumbName)
            if not ryw_view.resize_image(thumbPath, thumbDest):
                ryw.give_bad_news('resize_thumbnails: failed: ' +
                                  thumbPath + ' -> ' + thumbDest,
                                  logging.error)
                return False
    except:
        ryw.give_bad_news('failed to resize thumbnails.', logging.error)

    return True
    ##    pythonpath = _winreg.EnumValue(a, 0)[1]
    ##    print 'pythonpath =', pythonpath
    ##except:
    ##    print 'ERROR>>> Python installation not found. Quitting.'
    ##    sys.exit(1)
    ### ----

    # ---- get apache path ----

    apachepath = get_apache_path()
    if apachepath:
        create_httpd_conf(apachepath, dst)

    create_registry_entry(dst)

    ## TODO: remove pythonpath later
    pythonpath = sys.executable

    su.createdirpath(dst)

    su.copytree(common, os.path.join(dst, 'Common'))

    su.copyscripttree(os.path.join(src, 'cgi-bin', 'Nihao'),
                      os.path.join(dst, 'cgi-bin', 'Nihao'),
                      [os.path.join(dst, 'Common')],
                      "NihaoRoot = '%s'" % dst.replace('\\', '\\\\'))

    su.copytree(os.path.join(src, 'WWW', 'Nihao'),
                os.path.join(dst, 'WWW', 'Nihao'))

    sys.path.append(common)
    import su

    usage = '''

    Usage:
        * Run the script as:
		python copy-pythonscriptsforclient.py <Nihao installation directory>

	* It copies scripts from Repository/pythonscriptsforclient to their proper
		place in the target Nihao installation (village side)
    '''

    if len(sys.argv) != 2:
        print usage
        sys.exit(1)

    NihaoRoot = os.path.abspath(sys.argv[1])

    scriptdir = os.path.join(topdir, 'Repository', 'pythonscriptsforclient')
    mycgi = os.path.join(NihaoRoot, 'cgi-bin', 'repository')

    su.createdirpath(mycgi)

    scripts = os.listdir(scriptdir)
    for s in scripts:
	if s.lower() != 'cvs':
        	su.copyScript(os.path.join(scriptdir, s), os.path.join(mycgi, s), [os.path.join(NihaoRoot, 'Common')], "NihaoRoot = '%s'" % NihaoRoot.replace('\\', '\\\\'))