def main(IceCommon, args, sys, outputWriter):
    shortOptionNames = {"h":"help", "f":"file", "d":"directory", "dir":"directory",
                        "converter":"convert", "v":"verbose", "test":"testing"}
    flags = ["help", "convert", "atompub", "atomconvertpub", "upgrade",
             "verbose", "asserviceonly", "enableexternalaccess", "test"]
    progName = args.pop(0)
    options = IceCommon.getOptions(args, shortOptionNames, flags)
    iceWebServer(IceCommon, options, outputWriter)
    outputWriter("\n")
    return 0
def main(IceCommon, args, sys, outputWriter):
    shortOptionNames = {
        "h": "help",
        "f": "file",
        "d": "directory",
        "dir": "directory",
        "converter": "convert",
        "v": "verbose",
        "test": "testing"
    }
    flags = [
        "help", "convert", "atompub", "atomconvertpub", "upgrade", "verbose",
        "asserviceonly", "enableexternalaccess", "test"
    ]
    progName = args.pop(0)
    options = IceCommon.getOptions(args, shortOptionNames, flags)
    iceWebServer(IceCommon, options, outputWriter)
    outputWriter("\n")
    return 0
def main(args, sys, outputWriter):
    shortOptionNames = {
        "h": "help",
        "f": "file",
        "d": "directory",
        "dir": "directory",
        "converter": "convert",
        "v": "verbose",
        "test": "testing"
    }
    flags = [
        "help", "convert", "atompub", "atomconvertpub", "upgrade", "verbose",
        "asserviceonly", "enableexternalaccess", "test", "open"
    ]
    progName = args.pop(0)
    options = IceCommon.getOptions(args, shortOptionNames, flags)
    fs = IceCommon.FileSystem(IceCommon.workingDirectory)
    convert = options.get("convert", False)
    atompub = options.get("atompub", False) or options.get(
        "atomconvertpub", False)
    if convert or atompub:
        file = options.get("file")
        directory = options.get("directory")
        template = options.get("template")
        if file is not None:
            options["file"] = fs.absolutePath(file)
        if directory is not None:
            options["directory"] = fs.absolutePath(directory)
        if template is not None:
            options["template"] = fs.absolutePath(template)

        class OurOutput(object):
            def __init__(self):
                import tempfile
                self.__f = open(tempfile.gettempdir() + "/ice.log", "wb")

            def write(self, data):
                sys.stdout.write(data)
                self.__f.write(data.replace("\n", "\r\n"))

            def close(self):
                self.__f.close()

        output = OurOutput()
        stderr = sys.stderr
        sys.stderr = output
        converterAppMain(progName, options, fs=fs, output=output)
        output.close()
        sys.stderr = stderr
    elif options.get("svn", None) is not None:
        # SVN command
        usageMessage = "Usage: -svn:export -path:UrlOrAbsolutePathToExport -dir:exportToDirectory"
        svnCommand = options.get("svn").lower()
        if options.get("help") is not None:
            outputWriter("%s\n" % usageMessage)
            return (1)
        if svnCommand == "export":
            # from 'path' to 'dir'
            path = options.get("path")
            toDir = options.get("directory")
            if path is None or toDir is None:
                outputWriter("%s\n" % usageMessage)
            else:
                try:
                    outputWriter("Exporting '%s' to '%s'.  Please wait...\n" %
                                 (path, toDir))
                    import pysvn
                    client = pysvn.Client()
                    #path = fs.absolutePath(path)
                    #toDir = fs.absolutePath(toDir)
                    result = client.export(path,
                                           toDir,
                                           force=True,
                                           revision=pysvn.Revision(
                                               pysvn.opt_revision_kind.head),
                                           recurse=True)

                    outputWriter("Exported: %s\n" % str(result))
                    outputWriter("Export completed.\n")
                except Exception, e:
                    outputWriter("Error exporting: %s\n" % str(e))
        else:
            outputWriter("%s\n" % usageMessage)
def main(args, sys, outputWriter):
    shortOptionNames = {"h":"help", "f":"file", "d":"directory", "dir":"directory",
                        "converter":"convert", "v":"verbose", "test":"testing"}
    flags = ["help", "convert", "atompub", "atomconvertpub", "upgrade",
             "verbose", "asserviceonly", "enableexternalaccess", "test", "open"]
    progName = args.pop(0)
    options = IceCommon.getOptions(args, shortOptionNames, flags)
    fs = IceCommon.FileSystem(IceCommon.workingDirectory)
    convert = options.get("convert", False)
    atompub = options.get("atompub", False) or options.get("atomconvertpub", False)
    if convert or atompub:
        file = options.get("file")
        directory = options.get("directory")
        template = options.get("template")
        if file is not None:
            options["file"] = fs.absolutePath(file)
        if directory is not None:
            options["directory"] = fs.absolutePath(directory)
        if template is not None:
            options["template"] = fs.absolutePath(template)
        class OurOutput(object):
            def __init__(self):
                import tempfile
                self.__f = open(tempfile.gettempdir() + "/ice.log", "wb")
            def write(self, data):
                sys.stdout.write(data)
                self.__f.write(data.replace("\n", "\r\n"))
            def close(self):
                self.__f.close()
        output = OurOutput()
        stderr = sys.stderr
        sys.stderr = output
        converterAppMain(progName, options, fs=fs, output=output)
        output.close()
        sys.stderr = stderr
    elif options.get("svn", None) is not None:
        # SVN command
        usageMessage = "Usage: -svn:export -path:UrlOrAbsolutePathToExport -dir:exportToDirectory"
        svnCommand = options.get("svn").lower()
        if options.get("help") is not None:
            outputWriter("%s\n" % usageMessage)
            return(1)
        if svnCommand=="export":
            # from 'path' to 'dir'
            path = options.get("path")
            toDir = options.get("directory")
            if path is None or toDir is None:
                outputWriter("%s\n" % usageMessage)
            else:
                try:
                    outputWriter("Exporting '%s' to '%s'.  Please wait...\n" % (path, toDir))
                    import pysvn
                    client = pysvn.Client()
                    #path = fs.absolutePath(path)
                    #toDir = fs.absolutePath(toDir)
                    result = client.export(path, toDir, force=True, revision=pysvn.Revision(pysvn.opt_revision_kind.head), recurse=True)

                    outputWriter("Exported: %s\n" % str(result))
                    outputWriter("Export completed.\n")
                except Exception, e:
                    outputWriter("Error exporting: %s\n" % str(e))
        else:
            outputWriter("%s\n" % usageMessage)