Exemplo n.º 1
0
def build_init(module, source, infname, outfname):
    version = tools.get_module_version(module.name, source)
    with open(outfname, 'w') as outf:
        if os.path.exists(infname):
            with open(infname) as inf:
                shutil.copyfileobj(inf, outf)

        # Add standard module functions
        outf.write("""

def get_module_version():
    '''Return the version of this module, as a string'''
    return "%s"

def get_module_name():
    '''Return the fully-qualified name of this module'''
    return "IMP::%s"

def get_data_path(fname):
    '''Return the full path to one of this module's data files'''
    import IMP
    return IMP._get_module_data_path("%s", fname)

def get_example_path(fname):
    '''Return the full path to one of this module's example files'''
    import IMP
    return IMP._get_module_example_path("%s", fname)
""" % (version, module.name, module.name, module.name))
Exemplo n.º 2
0
def make_version_check(options):
    dir= os.path.join("lib", "IMP", options.name)
    tools.mkdir(dir, clean=False)
    version = tools.get_module_version(options.name, options.source)
    outf= os.path.join(dir, "_version_check.py")
    template="""def check_version(myversion):
  def _check_one(name, expected, found):
    if expected != found:
      message = "Expected version " + expected + " but got " + found + " when loading module " + name + ". Please make sure IMP is properly built and installed and that matching python and C++ libraries are used."
      raise RuntimeError(message)
  version = '%s'
  _check_one('%s', version, myversion)
  """
    tools.rewrite(outf, template%(version, version))
Exemplo n.º 3
0
def make_version_check(options):
    dir = os.path.join("lib", "IMP", options.name)
    tools.mkdir(dir, clean=False)
    version = tools.get_module_version(options.name, options.source)
    outf = os.path.join(dir, "_version_check.py")
    template = """def check_version(myversion):
  def _check_one(name, expected, found):
    if expected != found:
      message = "Expected version " + expected + " but got " + found + " when loading module " + name + ". Please make sure IMP is properly built and installed and that matching python and C++ libraries are used."
      raise RuntimeError(message)
  version = '%s'
  _check_one('%s', version, myversion)
  """
    tools.rewrite(outf, template % (version, version))
Exemplo n.º 4
0
def make_cpp(options):
    dir= os.path.join("src")
    file=os.path.join(dir, "%s_config.cpp"%options.name)
    cpp_template = open(os.path.join(options.source, "tools", "build", "config_templates", "src.cpp"), "r").read()
    try:
        os.makedirs(dir)
    except:
        # exists
        pass
    data={}
    data["filename"]="IMP/%s/%s_config.h"%(options.name, options.name)
    data["cppprefix"]="IMP%s"%options.name.upper().replace("_", "")
    data["name"]= options.name
    data["version"]= tools.get_module_version(options.name, options.source)
    tools.rewrite(file, cpp_template%data)
Exemplo n.º 5
0
def make_cpp(options):
    dir = os.path.join("src")
    file = os.path.join(dir, "%s_config.cpp" % options.name)
    cpp_template = tools.CPPFileGenerator(
        os.path.join(TOPDIR, "config_templates", "src.cpp"))
    try:
        os.makedirs(dir)
    except:
        # exists
        pass
    data = {}
    if options.name == 'kernel':
        data["filename"] = "IMP/%s_config.h" % options.name
    else:
        data["filename"] = "IMP/%s/%s_config.h" % (options.name, options.name)
    data["cppprefix"] = "IMP%s" % options.name.upper().replace("_", "")
    data["name"] = options.name
    data["version"] = tools.get_module_version(options.name, options.source)
    cpp_template.write(file, data)
Exemplo n.º 6
0
def make_cpp(options):
    dir = os.path.join("src")
    file = os.path.join(dir, "%s_config.cpp" % options.name)
    cpp_template = tools.CPPFileGenerator(os.path.join(options.source,
                             "tools", "build", "config_templates", "src.cpp"))
    try:
        os.makedirs(dir)
    except:
        # exists
        pass
    data = {}
    if options.name == 'kernel':
        data["filename"] = "IMP/%s_config.h" % options.name
    else:
        data["filename"] = "IMP/%s/%s_config.h" % (options.name, options.name)
    data["cppprefix"] = "IMP%s" % options.name.upper().replace("_", "")
    data["name"] = options.name
    data["version"] = tools.get_module_version(options.name, options.source)
    cpp_template.write(file, data)
Exemplo n.º 7
0
def make_cpp(options):
    dir = os.path.join("src")
    file = os.path.join(dir, "%s_config.cpp" % options.name)
    cpp_template = open(
        os.path.join(
            options.source,
            "tools",
            "build",
            "config_templates",
            "src.cpp"),
        "r").read(
    )
    try:
        os.makedirs(dir)
    except:
        # exists
        pass
    data = {}
    data["filename"] = "IMP/%s/%s_config.h" % (options.name, options.name)
    data["cppprefix"] = "IMP%s" % options.name.upper().replace("_", "")
    data["name"] = options.name
    data["version"] = tools.get_module_version(options.name, options.source)
    tools.rewrite(file, cpp_template % data)