Ejemplo n.º 1
0
def release(db = None, docId = False, version = False):
    ""
    # TODO: create core.release(db,docId,version)
    # Check if DB is provided else get the project DB
    if (not db)  or db=="" :
        db=utils.getDb()

    # Get task document
    doc=db[docId]

    review=doc["review"]
    version=str(int(version))
    reviewVersion=review[version]
    if not ("release" in reviewVersion):
        reviewVersion["release"]=list()

    release=doc["release"]
    last=str(len(release)+1)
    releaseVersion=dict()
    releaseVersion["description"]=reviewVersion["description"]
    releaseVersion["review"]=version
    releaseVersion["path"]=getPathFromId(doc_id = docId, vtype = "release")
    releaseVersion["path"]=os.path.join(releaseVersion["path"], "%03d"%int(last))
    releaseVersion["created"]=time.time()
    releaseVersion["creator"]=utils.getCurrentUser()
    release[last]=releaseVersion
    doc["release"]=release

    released=reviewVersion["release"]
    released.append(last)
    reviewVersion["release"]=released
    review[version]=reviewVersion
    doc["review"]=review

    src=reviewVersion["path"]
    dst=releaseVersion["path"]
    shutil.copytree(src, dst)
    _id, _rev=db.save (doc)
Ejemplo n.º 2
0
Archivo: project.py Proyecto: pixo/hk
def lsProjectServer (serveradress):
    """
    This function return a list of all DbServer homeworks projects.

    :param serveradress: The database adress.
    :type serveradress: str
    :returns:  list -- Return the list of authorised project users.

    **Example:**

    >>> lsProjectServer ( serveradress = "admin:[email protected]:5984" )
    >>> [ 'prod1', 'prod2', 'prod3' ]
    
    """

    # Get db server from adress
    server=utils.getServer (serveradress)
    projects=list ()
    user=utils.getCurrentUser()

    # Iterate over all databases contained in the DB server
    for db_name in server :
        if not db_name in ("_replicator", "_users"):
            db=server [ db_name ]

            # Check if the current db is a HK project
            if isProject (db) :

                # Get project authorized users
                users=getProjectUsers (db)

                # If current user is in the user list append project in the project list
                if user in users:
                    projects.append (db_name)

    # Return a list of projects name (str)
    return projects
Ejemplo n.º 3
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
Ejemplo n.º 4
0
Archivo: asset.py Proyecto: pixo/hk
def createTask (db = None, doc_id = "", description = "", overdoc = dict(), debug = False):
    """
    This function create a **task** into the provided database.

    :param db: The database.
    :type db: couchdb.client.Database
    :param doc_id: The asset code.
    :type doc_id: str
    :param description: The asset description.
    :type description: str
    :param overdoc: A dictionnary that contains extra document attributes.
    :type overdoc: dict
    :returns:  document -- The database document.
    :raises: AttributeError, KeyError

    **Example:**
    
    >>> db = pipeline.utils.getDb ( dbname = "prod" , serveradress = "127.0.0.1:5984" )
    >>> createTask ( db = db, doc_id = "prod_ch_mickey_mod_a", "This is the mickey modeling task 'a'" )
    
    """

    # If db isn't provided, get the current project database
    if db==None:
        db=utils.getDb()

    # Get datas from doc_id
    project, typ, slug, task, fork=doc_id.split ("_")
    asset_id="%s_%s_%s"%(project, typ, slug)
    asset="%s_%s_%s_%s"%(typ, slug, task, fork)

    # Check if project name is right
    if not (project in db) :
        print "createTask: %s project doesn't exist"%project
        return False

    # Check if the asset exist
    if not (asset_id in db):
        print "createTask: Asset '%s' doesn't exist"%asset_id
        return False

    # If task doesn't exist create it
    if doc_id in db :
        print "createTask: %s already exist"%asset
        return False

    # Create the task structure
    doc={
        "_id" : doc_id,
        "project" : project,
        "type" : typ,
        "name" : slug,
        "task" : task,
        "fork" : fork,
        "review" : dict(),
        "release" : dict(),
        "masters":{},
        "tags":{},
        "inactive" : False,
        "parents": {},
        "children": {},
        "comments":{},
        "description" : description,
        "creator" : utils.getCurrentUser(),
        "created" : time.time(),  # time.strftime ( "%Y %b %d %H:%M:%S", time.localtime() ),
        "status": { "art":"ns", "tec":"ns" },
        "infos": { "bid":1, "delivery": 20140611.5, "spent":0, "assigned":"" },
        "subscribers": {}
        }

    # Add extra data if needed
    doc.update(overdoc)

    # Save data structure into the database
    _id, _rev=db.save (doc)
    if not debug :
        print "createTask: Added %r to project %r"%(asset , project)
    return db[_id]