コード例 #1
0
def bootstrap_project(addon, config, addons_dir=defaults['addon_dir']):
  '''Bootstraps a project.

  For a project to be valid, it has to have

  '''
  if not(addon in valid_projects()):
    print "Invalid project: " , addon
    exit(2)
  deb("Valid bootstrap project: %s" % addon)
  deb("Project Dir: %s" % addons_dir)
  deb("Projects: " + ', '.join(valid_projects()) )
  bash_filename = addons_dir + addon + ".bash"
  if os.path.exists(bash_filename):   # i.e.: 'projects/sakura.sh'
    # Execute the common before, the addon and the common after!
    os.system("addon_dir='%s' bash addon/%s.addon" % (addon,addon))
    print "Bash Script executed. "
  # search for python as well
  python_filename = addons_dir + addon + ".py"
  deb("Looking for py: {}".format(python_filename))
  if os.path.exists(python_filename):   # i.e.: 'projects/sakura.py'
    deb("Great! executing python as well: {}".format(python_filename))
    # TODO(ricc) Substitute this code with a dynamic import:
    module = (addons_dir + addon).strip("./").replace('/','.')
    try:
      # http://stackoverflow.com/questions/951124/dynamic-loading-of-python-modules/951678#951678
      print "+ Module Name: ", module
      importlib.import_module(module)
      myaddon = __import__(module, fromlist=['main'])
      print "+ mod: ", myaddon
      print "+ DIR(mod): ", dir(myaddon)
      myaddon.main()
    except ImportError as e:
      print "Module '{}' not found: {}".format(module,e)
    #except Exception as e:
    #  print "Exception '{}' not found: {}".format(module,e)
    #  exit(11)
    # ret = os.system("python %s" % python_filename)
    # print "Python Script executed. ret={}".format(ret)
    print "Program terminating.."
    exit(0)
コード例 #2
0
def init():
  '''Initialization.'''
  sys.path.append(os.path.abspath(defaults['addon_dir']))
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
  #print "sys.path: ", sys.path
  deb("sys.version: {v}".format(v=sys.version))