Exemplo n.º 1
0
def newApp(args, options):
    from j25.Configuration import Configuration

    if len(args) < 2:
        print >> sys.stderr, "you must supply the name of the app"
        exit(1)
    _checkProject(AUTO_PROJECT_DIRS)
    appName = args[1]
    appDirectory = os.path.join('apps', appName)
    print Server.getBanner()
    print COLOR_SEQ % 33
    try:
        _createPythonPackage(HERE, appDirectory, True)
        f = open(os.path.join(appDirectory, 'config.py'), 'w')
        f.write(app_config_template)
        f.close()
        f = open(os.path.join(appDirectory, 'routing.py'), 'w')
        f.write(app_routing_template % appName)
        f.close()
        for directory, is_python_package in AUTO_APP_DIRS:
            _createPythonPackage(appDirectory, directory, is_python_package)
        #update configuration
        config = Configuration.load_file("server.ini", False)
        currentApps = eval(config.main.applications)
        assert isinstance(currentApps, list)
        currentApps.append('apps.%s' % appName)
        config.main.applications = str(list(set(currentApps)))
        Configuration.dump_file("server.ini", config)
        logger.info("Application %s has been created. Current project has been configured." % appName)
    finally:
        print RESET_SEQ
Exemplo n.º 2
0
def newProject(args, options):
    from j25.Configuration import Configuration

    if len(args) < 2:
        print >> sys.stderr, "Please supply a project name"
        exit(1)
    appName = options.withapp
    projectName = args[1]
    print Server.getBanner()
    print COLOR_SEQ % 33
    print "Creating project: %s" % projectName
    _createPythonPackage(HERE, projectName, False)
    #creating project structure
    for directory, is_python_package in AUTO_PROJECT_DIRS:
        _createPythonPackage(projectName, directory, is_python_package)
    #creating templates
    config = Configuration.create_empty_config()
    s1 = config.add_section('main')
    s1.add_option('project_name', projectName)
    s1.add_option('applications', [])
    s1.add_option('excluded_applications_from_worker', [])
    s1.add_option("mode", "DEV")
    s1.add_option("ip", "0.0.0.0")
    s1.add_option("port", "8800")
    s1.add_option("is_subdomain_aware", True) 
    
    s2 = config.add_section('session')
    s1.add_option('project_name', projectName)
    s2.add_option('secret', uuid4().hex + uuid4().hex)
    s2.add_option('url', ('%s/c9#session' % Constants.MONGODB_URL))
    s2.add_option('secure', 'False')
    s2.add_option('timeout', '600')
    s3 = config.add_section('store')
    s3.add_option("db_name", "c9_%s" % projectName)
    s3.add_option("ip", "127.0.0.1")
    s3.add_option("auto_create_collections", None)  
    Configuration.dump_file(os.path.join(projectName, 'server.ini'), config)
    f = open(os.path.join(projectName, 'routing.py'), 'w')
    f.write(project_routing_template)
    f.close()
    f = open(os.path.join(projectName, 'workerconfig.py'), 'w')
    f.write(app_workerconfig)
    f.close()
    if options.withapp:
        config = Configuration.load_file(os.path.join(projectName, 'server.ini'), False)
        builtin_Apps = eval(config.main.applications)
        assert isinstance(builtin_Apps, list)
        if not appName in builtin_Apps:
            builtin_Apps.append(appName)
            config.main.applications = str(builtin_Apps)
            Configuration.dump_file(os.path.join(projectName, 'server.ini'), config)
            logger.info("\033[1;33mProject %s Created with Application %s.\033[0m"% (projectName, appName))
        else:
            logger.info("\033[1;33mApplication %s already installed in the project by Default.\033[0m" % appName)
    print RESET_SEQ
Exemplo n.º 3
0
def installApp(args, options):
    from j25.Configuration import Configuration
    if len(args) < 2:
        print >> sys.stderr, "you must supply the name of the app"
        exit(1)
    _checkProject(AUTO_PROJECT_DIRS)
    appName = args[1]
    print Server.getBanner()
    print COLOR_SEQ % 33
    config = Configuration.load_file('server.ini', False)
    currentApps = eval(config.main.applications)
    assert isinstance(currentApps, list)
    if not appName in currentApps:
        currentApps.append(appName)
        config.main.applications = str(currentApps)
        Configuration.dump_file('server.ini', config)
        logger.info("\033[1;33mApplication %s added to project.\033[0m"% appName)
    else:
        logger.info("\033[1;33mApplication %s already installed in the project.\033[0m" % appName)
Exemplo n.º 4
0
 def testDumpFile(self):
     fileObj = tempfile.NamedTemporaryFile()
     fileName = fileObj.name
     configObj = TestConfiguration.create_instance()
     Configuration.dump_file(fileName, configObj)
     loadedCfg = Configuration.load_file(fileName)        
     # comparing cfg and configObj        
     self.assertEquals(sorted(loadedCfg.sections()), sorted(configObj.sections()))
     
     configObjDict = {}
     ConfigFileDict = {}
     configObjOptions = []
     ConfigFileOptions = []
     
     for section in configObj.sections():
         secObj = configObj.get_section(section)
         configObjOptions.extend(secObj.options())
         tempOptionsDict = {}
         for option in secObj.options():
             tempOptionsDict[option] =  secObj.get_option(option)
         configObjDict[section] = tempOptionsDict
                             
     for section in loadedCfg.sections():
         secObj = configObj.get_section(section)
         ConfigFileOptions.extend(secObj.options())
         tempOptionsDict = {}
         for option in secObj.options():
             tempOptionsDict[option] =  secObj.get_option(option)
         ConfigFileDict[section] = tempOptionsDict
     
     self.assertTrue(configObjOptions)
     self.assertTrue(ConfigFileOptions)  
     self.assertTrue(ConfigFileDict)
     self.assertTrue(configObjDict)
     self.assertEquals(sorted(configObjOptions), sorted(ConfigFileOptions))     
     self.assertEquals(len(ConfigFileDict), len(configObjDict))
     
     for k, v in configObjDict.iteritems():
         self.assertEquals(v, ConfigFileDict[k])
     
     for k, v in ConfigFileDict.iteritems():
         self.assertEquals(v, configObjDict[k])
Exemplo n.º 5
0
def dumpConfig(args, options):
    from j25.Configuration import Configuration
    if len(args) < 2:
        print >> sys.stderr, "Please supply a configuration filename"
        exit(1)
    Configuration.dump_file(args[1])