예제 #1
0
def main(argv=None):
    """script main.

    parses command line options in sys.argv, unless *argv* is given.
    """

    if argv == None: argv = sys.argv

    parser = E.OptionParser(
        version=
        "%prog version: $Id: cgat_make2help.py 2781 2009-09-10 11:33:14Z andreas $"
    )

    parser.add_option("-m",
                      "--method",
                      dest="method",
                      type="choice",
                      help="method to use [t-test=t-test]",
                      choices=("t-test", ))
    parser.set_defaults(filename="Makefile", )

    (options, args) = E.Start(parser, quiet=True, add_pipe_options=True)

    src_dir = os.path.dirname(os.path.abspath(__file__))

    makefiles = getMakefiles((options.filename, ),
                             source_directory=src_dir,
                             ignore_missing=True)

    ## variables starting with "PARAM"
    parameters = {}
    ## main targets: no patterns or no dependencies
    targets = []
    ## contain patterns and dependencies
    rules = []

    options.stdout.write("Help for makefile %s\n\n" %
                         os.path.abspath(options.filename))

    options.stdout.write("""This file is organized in three sections.

1. Primary Targets

   Primary targets are targets to be run by the users. Usually includes "all".

2. Parameters

   Parameters defined in the makefile.

3. Secondary targets and rules

   Rules defined in the makefile to build the primary targets.

""")

    for makefile in makefiles:

        infile = open(makefile, "r")
        comment = []
        last_line = None

        first = True
        for line in infile:

            if last_line:
                line = last_line + line
                last_line = None

            if not re.sub("\s+", "", line):
                first = False
                continue

            if line[-2] == "\\":
                last_line = line[:-2]
                continue

            if line[0] == "\t": continue

            if line[0] == "#":
                l = re.sub("^#+\s*", "", line[:-1])
                if l and not first:
                    comment.append(l)
                continue

            x = re.match("(PARAM_\S+[^?:])\s*\?*\s*=(.+)", line)
            if x:
                param, value = x.groups()
                if param not in parameters:
                    p = Parameter(param, comment, value)
                    parameters[param] = p
                else:
                    p = parameters[param]
                    p.mComment += comment
                    p.mDefaultValue = value

            x = re.match("(PARAM_\S+[^?])\s*=(.+)", line)
            if x:
                param, value = x.groups()
                if param not in parameters:
                    p = Parameter(param, comment)
                    parameters[param] = p
                else:
                    p = parameters[param]
                    p.mComment += comment

                p.mValue = value

            x = re.match("(\S+)\s*:\s*(.*)", line)
            if x:
                target, dependencies = x.groups()
                if "=" in target or "=" in dependencies: continue
                if target[0] in ".$": continue
                if "hook" in target: continue
                dependencies = re.sub("\s+", " ", dependencies)
                if "." in target:
                    rules.append(Target(target, dependencies, comment))
                else:
                    targets.append(Target(target, dependencies, comment))

            comment = []
            first = False

        infile.close()

    options.stdout.write("\n\n Section 1: Primary targets\n")
    options.stdout.write(" --------------------------\n\n")
    options.stdout.write(
        """ Primary targets are targets to be run by the users. Usually includes "all".\n\n"""
    )

    for x in targets:
        options.stdout.write(x.printPretty() + "\n\n")

    options.stdout.write("\n\n Section 2: Parameters\n")
    options.stdout.write(" --------------------------\n\n")
    options.stdout.write(
        """ A list of parameters defined in the makefile.\n\n""")

    for x, y in sorted(parameters.items()):
        options.stdout.write(y.printPretty() + "\n\n\n")

    for x in targets:
        options.stdout.write(x.printPretty() + "\n\n")

    options.stdout.write("\n\n Section 3: Secondary targets and rules\n")
    options.stdout.write(" --------------------------\n\n")
    options.stdout.write(""" Secondary targets are run by the pipeline.\n\n""")

    for x in rules:
        options.stdout.write(x.printPretty() + "\n\n")

    options.stdout.write("\n\n Section 4: Contents\n")
    options.stdout.write(" --------------------------\n\n")
    options.stdout.write(
        " This help was created by scanning the contents of the following makefiles.\n"
    )

    for makefile in makefiles:
        options.stdout.write("    %s\n" % makefile)

    E.Stop()
예제 #2
0
def main(argv=None):
    """script main.

    parses command line options in sys.argv, unless *argv* is given.
    """

    if argv is None:
        argv = sys.argv

    parser = E.OptionParser(
        version="%prog version: $Id: cgat_make2help.py 2781 2009-09-10 11:33:14Z andreas $")

    parser.add_option("-m", "--method", dest="method", type="choice",
                      help="method to use [t-test=t-test]",
                      choices=("t-test", ))
    parser.set_defaults(
        filename="Makefile",
    )

    (options, args) = E.Start(parser,
                              quiet=True,
                              add_pipe_options=True)

    src_dir = os.path.dirname(os.path.abspath(__file__))

    makefiles = getMakefiles(
        (options.filename,), source_directory=src_dir, ignore_missing=True)

    # variables starting with "PARAM"
    parameters = {}
    # main targets: no patterns or no dependencies
    targets = []
    # contain patterns and dependencies
    rules = []

    options.stdout.write("Help for makefile %s\n\n" %
                         os.path.abspath(options.filename))

    options.stdout.write( """This file is organized in three sections.

1. Primary Targets

   Primary targets are targets to be run by the users. Usually includes "all".

2. Parameters

   Parameters defined in the makefile.

3. Secondary targets and rules

   Rules defined in the makefile to build the primary targets.

""")

    for makefile in makefiles:

        infile = open(makefile, "r")
        comment = []
        last_line = None

        first = True
        for line in infile:

            if last_line:
                line = last_line + line
                last_line = None

            if not re.sub("\s+", "", line):
                first = False
                continue

            if line[-2] == "\\":
                last_line = line[:-2]
                continue

            if line[0] == "\t":
                continue

            if line[0] == "#":
                l = re.sub("^#+\s*", "", line[:-1])
                if l and not first:
                    comment.append(l)
                continue

            x = re.match("(PARAM_\S+[^?:])\s*\?*\s*=(.+)", line)
            if x:
                param, value = x.groups()
                if param not in parameters:
                    p = Parameter(param, comment, value)
                    parameters[param] = p
                else:
                    p = parameters[param]
                    p.mComment += comment
                    p.mDefaultValue = value

            x = re.match("(PARAM_\S+[^?])\s*=(.+)", line)
            if x:
                param, value = x.groups()
                if param not in parameters:
                    p = Parameter(param, comment)
                    parameters[param] = p
                else:
                    p = parameters[param]
                    p.mComment += comment

                p.mValue = value

            x = re.match("(\S+)\s*:\s*(.*)", line)
            if x:
                target, dependencies = x.groups()
                if "=" in target or "=" in dependencies:
                    continue
                if target[0] in ".$":
                    continue
                if "hook" in target:
                    continue
                dependencies = re.sub("\s+", " ", dependencies)
                if "." in target:
                    rules.append(Target(target, dependencies, comment))
                else:
                    targets.append(Target(target, dependencies, comment))

            comment = []
            first = False

        infile.close()

    options.stdout.write("\n\n Section 1: Primary targets\n")
    options.stdout.write(" --------------------------\n\n")
    options.stdout.write(
        """ Primary targets are targets to be run by the users. Usually includes "all".\n\n""")

    for x in targets:
        options.stdout.write(x.printPretty() + "\n\n")

    options.stdout.write("\n\n Section 2: Parameters\n")
    options.stdout.write(" --------------------------\n\n")
    options.stdout.write(
        """ A list of parameters defined in the makefile.\n\n""")

    for x, y in sorted(parameters.items()):
        options.stdout.write(y.printPretty() + "\n\n\n")

    for x in targets:
        options.stdout.write(x.printPretty() + "\n\n")

    options.stdout.write("\n\n Section 3: Secondary targets and rules\n")
    options.stdout.write(" --------------------------\n\n")
    options.stdout.write(""" Secondary targets are run by the pipeline.\n\n""")

    for x in rules:
        options.stdout.write(x.printPretty() + "\n\n")

    options.stdout.write("\n\n Section 4: Contents\n")
    options.stdout.write(" --------------------------\n\n")
    options.stdout.write(
        " This help was created by scanning the contents of the following makefiles.\n")

    for makefile in makefiles:
        options.stdout.write("    %s\n" % makefile)

    E.Stop()
예제 #3
0
def main( argv = None ):
    """script main.

    parses command line options in sys.argv, unless *argv* is given.
    """

    if argv == None: argv = sys.argv

    parser = E.OptionParser( version = "%prog version: $Id: gpipe/export_code.py 2781 2009-09-10 11:33:14Z andreas $")

    parser.add_option("-t", "--tool-set", dest="tool_set",
                      help="set to use.", type="choice",
                      choices=("geneprediction", "codonbias", "geneprediction",
                               "codeml_benchmark" ) )

    parser.add_option( "--test", dest="test", action = "store_true",
                       help = "testing mode [%default]" )

    parser.add_option( "--release", dest="version", type="string",
                       help = "the version string [%default]" )
                       

    parser.set_defaults(
        tool_set = "geneprediction",
        libdirs = ("/home/andreas/cgat/", ),
        scriptdirs = ("/home/andreas/cgat/", ),
        name = None,
        version = "0.0.1",
        test = False,
        )

    (options, args) = E.Start( parser )

    source_directory = os.path.realpath(os.path.dirname(sys.argv[0])) + "/"
    
    if options.tool_set == "geneprediction":
        makefiles = set( ("Makefile.gpipe",) )
        method = "gpipe"
        readme = README_GPIPE
        if options.name == None: options.name = "gpipe"
    elif os.path.exists( "%s/Makefile.%s" % (source_directory, options.tool_set) ):
        makefiles = set( ("Makefile.%s" % options.tool_set,) )
        method = options.tool_set
        readme = README_GENERIC
        if options.name == None: options.name = options.tool_set
    else: 
        raise ValueError( "unknown toolset %s" % options.tool_set)

    if options.test:
        tmp_dir = "tmp"
        os.mkdir(tmp_dir)
    else:
        tmp_dir = tempfile.mkdtemp()
        
    nmissed_makefiles, nmissed_scripts, nmissed_modules = 0, 0, 0

    makefiles = getMakefiles( makefiles, os.path.join( source_directory, "makefiles" ) )
    target_directory= "%s/%s-%s/makefiles/" % ( tmp_dir, options.name, options.version )
    os.makedirs( target_directory )

    for makefile in makefiles:

        src = os.path.join( source_directory, makefile )

        if os.path.exists( src ):
            shutil.copy( src, target_directory )
            E.info( "makefile added: %s" % makefile )
        else:
            E.warn( "makefile missed: %s" % makefile )
            nmissed_makefiles += 1
            
    scripts = getScripts( makefiles, source_directory )
    target_directory= "%s/%s-%s/" % ( tmp_dir, options.name, options.version )
    modules = set()
    for language, script in scripts:

        ## remove any path name variables
        script = os.path.basename( script )        
        script = script[script.find(")")+1:]

        for d in (source_directory,) + options.scriptdirs:
            src = os.path.join( source_directory, script )

            if os.path.exists( src ):
                shutil.copy( src, target_directory )
                if language == "python":
                    modules.add( script )
                E.info( "script added: %s from %s" % (script, dir) )
                break
        else:
            E.warn( "script missed: %s" % (script) )
            nmissed_scripts += 1

    modules, system_modules = getModules( modules,
                                 (source_directory,) + options.scriptdirs,
                                 options.libdirs )

    for lib in modules:

        ## remove any path name variables
        for dir in (source_directory,) + options.scriptdirs + options.libdirs:
            if os.path.exists( dir + lib ):
                shutil.copy( dir + lib,
                             target_directory + lib )

                if options.loglevel >= 1:
                    options.stdout.write("module added: %s from %s\n" % (lib, dir) )
                break
        else:
            if options.loglevel >= 1:
                options.stdout.write("module missed: %s\n" % (lib) )
            nmissed_scripts += 1

    ## Writing setup check file
    outfile = open( target_directory + "check_gpipe/setup.py", "w")
    for module in system_modules:
        outfile.write("import %s\n" % module[:-3] )

    outfile.write("print 'check successfull - all python modules required are present.'\n")
        
    outfile.close()

    ## Writing setup file.
    outfile = open( target_directory + "gpipe/setup.py", "w")
    infile = open( source_directory + "gpipe/setup.py" )
    for line in infile:
        if re.search("method = None", line):
            line = line[line.find(method):] + "method = '%s',\n" % method
        outfile.write(line)

    outfile.close()


    ## Writing the README file
    params = { 'dir':"%s-%s" % (options.name, options.version),
               }
    
    outfile = open( target_directory + "README", "w")
    outfile.write( PREAMBL + "\n" )
    outfile.write( README_INSTALLATION % params + "\n")
    outfile.write( readme % params + "\n" )
    outfile.close()
    
    ## Wrap the whole thing up
    os.system( "tar -C %s -czf %s/%s-%s.tgz %s-%s" % (tmp_dir, tmp_dir, options.name, options.version,
                                                      options.name, options.version, ) )
    
    E.info( "nmissed: makefiles=%i, scripts=%i, modules=%i" % (nmissed_makefiles, nmissed_scripts, nmissed_modules ) )

    if not options.test:
        shutil.copy( "%s/%s-%s.tgz" % (tmp_dir, options.name, options.version) , "." )
        shutil.rmtree( tmp_dir )
        
    E.Stop()
예제 #4
0
def main(argv=None):
    """script main.

    parses command line options in sys.argv, unless *argv* is given.
    """

    if argv is None:
        argv = sys.argv

    parser = E.OptionParser(
        version=
        "%prog version: $Id: gpipe/export_code.py 2781 2009-09-10 11:33:14Z andreas $"
    )

    parser.add_option("-t",
                      "--tool-set",
                      dest="tool_set",
                      help="set to use.",
                      type="choice",
                      choices=("geneprediction", "codonbias", "geneprediction",
                               "codeml_benchmark"))

    parser.add_option("--test",
                      dest="test",
                      action="store_true",
                      help="testing mode [%default]")

    parser.add_option("--release",
                      dest="version",
                      type="string",
                      help="the version string [%default]")

    parser.set_defaults(
        tool_set="geneprediction",
        libdirs=("/home/andreas/cgat/", ),
        scriptdirs=("/home/andreas/cgat/", ),
        name=None,
        version="0.0.1",
        test=False,
    )

    (options, args) = E.Start(parser)

    source_directory = os.path.realpath(os.path.dirname(sys.argv[0])) + "/"

    if options.tool_set == "geneprediction":
        makefiles = set(("Makefile.gpipe", ))
        method = "gpipe"
        readme = README_GPIPE
        if options.name is None:
            options.name = "gpipe"
    elif os.path.exists("%s/Makefile.%s" %
                        (source_directory, options.tool_set)):
        makefiles = set(("Makefile.%s" % options.tool_set, ))
        method = options.tool_set
        readme = README_GENERIC
        if options.name is None:
            options.name = options.tool_set
    else:
        raise ValueError("unknown toolset %s" % options.tool_set)

    if options.test:
        tmp_dir = "tmp"
        os.mkdir(tmp_dir)
    else:
        tmp_dir = tempfile.mkdtemp()

    nmissed_makefiles, nmissed_scripts, nmissed_modules = 0, 0, 0

    makefiles = getMakefiles(makefiles,
                             os.path.join(source_directory, "makefiles"))
    target_directory = "%s/%s-%s/makefiles/" % (tmp_dir, options.name,
                                                options.version)
    os.makedirs(target_directory)

    for makefile in makefiles:

        src = os.path.join(source_directory, makefile)

        if os.path.exists(src):
            shutil.copy(src, target_directory)
            E.info("makefile added: %s" % makefile)
        else:
            E.warn("makefile missed: %s" % makefile)
            nmissed_makefiles += 1

    scripts = getScripts(makefiles, source_directory)
    target_directory = "%s/%s-%s/" % (tmp_dir, options.name, options.version)
    modules = set()
    for language, script in scripts:

        # remove any path name variables
        script = os.path.basename(script)
        script = script[script.find(")") + 1:]

        for d in (source_directory, ) + options.scriptdirs:
            src = os.path.join(source_directory, script)

            if os.path.exists(src):
                shutil.copy(src, target_directory)
                if language == "python":
                    modules.add(script)
                E.info("script added: %s from %s" % (script, dir))
                break
        else:
            E.warn("script missed: %s" % (script))
            nmissed_scripts += 1

    modules, system_modules = getModules(modules, (source_directory, ) +
                                         options.scriptdirs, options.libdirs)

    for lib in modules:

        # remove any path name variables
        for dir in (source_directory, ) + options.scriptdirs + options.libdirs:
            if os.path.exists(dir + lib):
                shutil.copy(dir + lib, target_directory + lib)

                if options.loglevel >= 1:
                    options.stdout.write("module added: %s from %s\n" %
                                         (lib, dir))
                break
        else:
            if options.loglevel >= 1:
                options.stdout.write("module missed: %s\n" % (lib))
            nmissed_scripts += 1

    # Writing setup check file
    outfile = open(target_directory + "check_gpipe/setup.py", "w")
    for module in system_modules:
        outfile.write("import %s\n" % module[:-3])

    outfile.write(
        "print 'check successfull - all python modules required are present.'\n"
    )

    outfile.close()

    # Writing setup file.
    outfile = open(target_directory + "gpipe/setup.py", "w")
    infile = open(source_directory + "gpipe/setup.py")
    for line in infile:
        if re.search("method = None", line):
            line = line[line.find(method):] + "method = '%s',\n" % method
        outfile.write(line)

    outfile.close()

    # Writing the README file
    params = {
        'dir': "%s-%s" % (options.name, options.version),
    }

    outfile = open(target_directory + "README", "w")
    outfile.write(PREAMBL + "\n")
    outfile.write(README_INSTALLATION % params + "\n")
    outfile.write(readme % params + "\n")
    outfile.close()

    # Wrap the whole thing up
    os.system("tar -C %s -czf %s/%s-%s.tgz %s-%s" % (
        tmp_dir,
        tmp_dir,
        options.name,
        options.version,
        options.name,
        options.version,
    ))

    E.info("nmissed: makefiles=%i, scripts=%i, modules=%i" %
           (nmissed_makefiles, nmissed_scripts, nmissed_modules))

    if not options.test:
        shutil.copy("%s/%s-%s.tgz" % (tmp_dir, options.name, options.version),
                    ".")
        shutil.rmtree(tmp_dir)

    E.Stop()
예제 #5
0
파일: export_code.py 프로젝트: siping/cgat
        makefiles = set( ("Makefile.%s" % options.tool_set,) )
        method = options.tool_set
        readme = README_GENERIC
        if options.name == None: options.name = options.tool_set
    else: 
        raise ValueError( "unknown toolset %s" % options.tool_set)

    if options.test:
        tmp_dir = "tmp"
        os.mkdir(tmp_dir)
    else:
        tmp_dir = tempfile.mkdtemp()
        
    nmissed_makefiles, nmissed_scripts, nmissed_modules = 0, 0, 0

    makefiles = getMakefiles( makefiles, os.path.join( source_directory, "makefiles" ) )
    target_directory= "%s/%s-%s/makefiles/" % ( tmp_dir, options.name, options.version )
    os.makedirs( target_directory )

    for makefile in makefiles:

        src = os.path.join( source_directory, makefile )

        if os.path.exists( src ):
            shutil.copy( src, target_directory )
            E.info( "makefile added: %s" % makefile )
        else:
            E.warn( "makefile missed: %s" % makefile )
            nmissed_makefiles += 1
            
    scripts = getScripts( makefiles, source_directory )