Ejemplo n.º 1
0
Archivo: examples.py Proyecto: pixo/hk
def createMassiveAssets():
    prj=utils.getProjectName()
    types=utils.getAssetTypes()
    tasks=utils.getAssetTasks()

    for i in range(0, 454):
        for t in types:
            docId="%s_%s_donald%s%d"%(prj, types[t], types[t], i)
            createAssetOnDB(docId)
            print docId

            for k in tasks:
                docId="%s_%s_donald%s%d_%s_a"%(prj, types[t], types[t], i, tasks[k])
                createTaskOnDB(docId)
Ejemplo n.º 2
0
Archivo: project.py Proyecto: pixo/hk
def createProject (name = "", description = "Default", db_server = "",
                      host_root = "", overdoc = dict (), badassversion = None):
    """
    This function create a project.

    :param name: The project name
    :type name: str
    :param description: The project description
    :type description: str
    :param db_server: The data base adress
    :type db_server: str
    :param host_root: The host data server root adress  
    :type host_root: str
    :param overdoc: A dictionnary that contains extra document attributes.
    :type overdoc: dict
    :returns:  couchdb.client.Database -- return the db.
    :raises: AttributeError, KeyError

    **Example:**

    >>> createProject ( name = "prod", description = "this is the project prod",
                        db_server = "admin:[email protected]:5984", host_root = "[email protected]:/homeworks" )
    
    """
    # Check if DB server exists
    adress="http://%s/"%db_server
    exists=utils.serverExists (adress)

    if not exists :
        print "createProject(): Wrong DB server adress,user or/and password"
        return False

    # Check args
    if name=="" :
        print "CreateProject(): Please provide a project name"
        return False

    if db_server=="" or db_server==None :
        print "CreateProject(): No server adress provided"
        return False

    # Check if DB and project already exist
    db=utils.getDb(name, adress)

    # If DB and project exists return
    if db!=False :
        return False

    # Create DB
    db=utils.createDb(name, adress)

    # Create project env and cred file
    createProjectEnv(name, badassversion)
    createProjectCred(name, db_server, host_root)

    # Adding db project documents
    assets=utils.getAssetTypes()
    tasks=utils.getAssetTasks()

    # Users
    users=dict()
    users[utils.getCurrentUser()]="admin"

    doc={
            "_id" : "%s"%name,
            "type" : "project",
            "name" : name,
            "description" : description,
            "asset_types" : assets,
            "asset_tasks" : tasks,
            "creator" : os.getenv ("USER"),
            "created" : time.time(),
            "root" : "/homeworks",
            "users" : users,
            "status": {"art":"ns", "tech":"ns"},
            "host" : host_root
            }

    doc.update(overdoc)

    _id, _rev=db.save(doc)
    print "createProject(): Project '%s' created"%(name)

    return db