Exemplo n.º 1
0
 def test_encode_class_name(self):
     """Test encoding of class names."""
     for (class_name, encoded_class_name) in self.class_names:
         self.assertEqual(ft.encode_class_name(class_name),
                          encoded_class_name)
         self.assertEqual(
             ft.encode_class_name(ft.decode_class_name(encoded_class_name)),
             encoded_class_name)
Exemplo n.º 2
0
    def make_module_extra(self):
        \"\"\"Custom extra module file entries for %(name)s.\"\"\"

        txt = super(%(class_name)s, self).make_module_extra()

        txt += self.module_generator.set_environment("VARIABLE", 'value')
        txt += self.module_generator.prepend_paths("PATH_VAR", ['path1', 'path2'])

        return txt
"""

txt = tmpl % {
    'year': datetime.date.today().year,
    'name': name,
    'class_name': encode_class_name(name),
    'parent_import': parent_import,
    'parent': options.parent,
}

print "Writing template easyblock for %s to %s ..." % (name, easyblock_path)
try:
    dirpath = os.path.dirname(easyblock_path)
    if not os.path.exists(dirpath):
        os.makedirs(dirpath)
    f = open(easyblock_path, "w")
    f.write(txt)
    f.close()
except (IOError, OSError), err:
    sys.stderr.write(
        "ERROR! Writing template easyblock for %s to %s failed: %s" %
    def make_module_extra(self):
        \"\"\"Custom extra module file entries for %(name)s.\"\"\"

        txt = super(%(class_name)s, self).make_module_extra()

        txt += self.module_generator.set_environment("VARIABLE", 'value')
        txt += self.module_generator.prepend_paths("PATH_VAR", ['path1', 'path2'])

        return txt
"""

txt = tmpl % {
              'year': datetime.date.today().year,
              'name': name,
              'class_name': encode_class_name(name),
              'parent_import': parent_import,
              'parent': options.parent,
             }

print("Writing template easyblock for %s to %s ..." % (name, easyblock_path))
try:
    dirpath = os.path.dirname(easyblock_path)
    if not os.path.exists(dirpath):
        os.makedirs(dirpath)
    f = open(easyblock_path, "w")
    f.write(txt)
    f.close()
except (IOError, OSError) as err:
    sys.stderr.write("ERROR! Writing template easyblock for %s to %s failed: %s" % (name, easyblock_path, err))
    sys.exit(1)
            else:
                # if we only get the class name, most likely we're dealing with a generic easyblock
                try:
                    modulepath = get_module_path(easyblock, generic=True)
                    cls = get_class_for(modulepath, class_name)
                except ImportError, err:
                    # we might be dealing with a non-generic easyblock, e.g. with --easyblock is used
                    modulepath = get_module_path(easyblock)
                    cls = get_class_for(modulepath, class_name)
                _log.info("Derived full easyblock module path for %s: %s" % (class_name, modulepath))
        else:
            # if no easyblock specified, try to find if one exists
            if name is None:
                name = "UNKNOWN"
            # The following is a generic way to calculate unique class names for any funny software title
            class_name = encode_class_name(name)
            # modulepath will be the namespace + encoded modulename (from the classname)
            modulepath = get_module_path(class_name)
            if not os.path.exists("%s.py" % modulepath):
                _log.deprecated("Determine module path based on software name", "2.0")
                modulepath = get_module_path(name, decode=False)

            # try and find easyblock
            try:
                _log.debug("getting class for %s.%s" % (modulepath, class_name))
                cls = get_class_for(modulepath, class_name)
                _log.info("Successfully obtained %s class instance from %s" % (class_name, modulepath))
            except ImportError, err:

                # when an ImportError occurs, make sure that it's caused by not finding the easyblock module,
                # and not because of a broken import statement in the easyblock module
Exemplo n.º 5
0
 def test_encode_class_name(self):
     """Test encoding of class names."""
     for (class_name, encoded_class_name) in self.class_names:
         self.assertEqual(ft.encode_class_name(class_name), encoded_class_name)
         self.assertEqual(ft.encode_class_name(ft.decode_class_name(encoded_class_name)), encoded_class_name)
Exemplo n.º 6
0
    def make_module_extra(self):
        \"\"\"Custom extra module file entries for %(name)s.\"\"\"

        txt = super(%(class_name)s, self).make_module_extra()

        txt += self.module_generator.set_environment("VARIABLE", 'value')
        txt += self.module_generator.prepend_paths("PATH_VAR", ['path1', 'path2'])

        return txt
"""

txt = tmpl % {
    "year": datetime.date.today().year,
    "name": name,
    "class_name": encode_class_name(name),
    "parent_import": parent_import,
    "parent": options.parent,
}

print "Writing template easyblock for %s to %s ..." % (name, easyblock_path)
try:
    dirpath = os.path.dirname(easyblock_path)
    if not os.path.exists(dirpath):
        os.makedirs(dirpath)
    f = open(easyblock_path, "w")
    f.write(txt)
    f.close()
except (IOError, OSError), err:
    sys.stderr.write("ERROR! Writing template easyblock for %s to %s failed: %s" % (name, easyblock_path, err))
    sys.exit(1)