예제 #1
0
파일: examples.py 프로젝트: pixo/hk
def pushfile ( path, description ):
    
    if not os.path.isabs ( path ) :
        path = os.path.abspath ( path )   

    if not os.path.exists ( path ):
        print "hk-texture-publish: %s doesn't exists" % path
        return 1

    db = utils.getDb ()
    doc_id = core.getIdFromPath ( path )
        
    if not ( doc_id in db ) :
        print "hk-push: %s isn't in the  database" % doc_id
        return 1

    if os.path.isdir ( path ) :
        core.pushDir ( db, doc_id, path, description )
            
    else :
        basename = os.path.basename ( path )
        if basename.find ( doc_id ) == 0 :
            core.pushFile ( db, doc_id, path, description )
    
        else:
            print "wrong naming convention"
예제 #2
0
파일: repository.py 프로젝트: pixo/hk
def getVersions (db = None, doc_id = "", vtype = "review"):
    """
    This function return all versions in a dictionnary of a particular asset.

    :param db: the database
    :type db: Database
    :param doc_id: The asset code.
    :type doc_id: str
    :param vtype: Version type *trial/stock*
    :type vtype: str
    :returns:  dict -- a dictionary with all versions of the asset,
                the key is a string with the version number without padding.

    **Example:**
    
    >>> db = utils.getDb()
    >>> getVersions ( db = db, doc_id = "bls_chr_belanus_mod_main" )
    >>> {'1': {'files': ['bls_chr_belanus_mod_main.mb'], 'path': '/homeworks/projects/bls/chr/belanus/mod/main/001',
        'created': '2013 Mar 08 21:16:34', 'description': 'names cleaned\nnormal softened', 'creator': 'pixo'},
        '3': {'files': ['bls_chr_belanus_mod_main.mb'], 'path': '/homeworks/projects/bls/chr/belanus/mod/main/003',
        'created': '2013 Mar 08 23:13:54', 'description': 'test export gproject etc', 'creator': 'pixo'},
        '2': {'files': ['bls_chr_belanus_mod_main.mb'] ... and so ... }
    """

    if utils.checkVersionType (vtype) :
        return False

    # If db is not provided get the current project DB
    if db==None :
        db=utils.getDb()

    # Get Versions from document
    versions=db [ doc_id ][ vtype ]

    return versions
예제 #3
0
파일: examples.py 프로젝트: pixo/hk
def getAllAssetVersions ():
    """
    This is a simple example to get all asset versions.
    """
    db = utils.getDb()
    versions = core.getVersions ( db = db, doc_id = "bls_chr_belanus_mod_main" )
    print versions
    return versions
예제 #4
0
파일: examples.py 프로젝트: pixo/hk
def pullAnAssetVersion ():
    """
    This is a simple example to pull to workspace a particular asset version.
    """
    db = utils.getDb ()
    version = 2
    result = core.pull ( db = db, doc_id = "bls_chr_belanus_mod_main", version = version )
    print result
예제 #5
0
파일: examples.py 프로젝트: pixo/hk
def getAnAssetVersion ():
    """
    This is a simple example to get a particular asset version path.
    """
    db = utils.getDb()
    version = core.getVersionPath ( db = db, doc_id = "cpt_chr_jdoe_mod_a", version = "last" )
    print version
    return version
예제 #6
0
파일: asset.py 프로젝트: pixo/hk
def setAssetAttr(db = None, docId = "", attr = None, value = None):
    if docId=="" or not attr:
        print ("setAssetAttr(): please provide proper attributes.")
        return

    if not db :
        db=utils.getDb ()

    doc=db[docId]
    doc[attr]=value
    _id, _rev=db.save (doc)
예제 #7
0
파일: repository.py 프로젝트: pixo/hk
def pushFile (db = None, doc_id = False, path = list (), description = "", rename = True, vtype = "review"):
    """
    This function copy the desired file from local workspace to repository.

    :param db: the database
    :type db: Database
    :param doc_id: The asset code
    :type doc_id: str
    :param path: The list of files to push
    :type path: str/list of str
    :param description: This is the description of the push
    :type description: str
    :param rename: Rename the file (default True)
    :type rename: bool -- if True rename the file(s)
    :param vtype: Version type *trial/stock*
    :type vtype: str
    :returns: str -- Return the directory of the pushed files

    **Example:**
    
    >>> db = utils.getDb()
    >>> push ( db = db, doc_id = "bls_chr_belanus_mod_main",
    >>>        path = "/homeworks/users/jdoe/projects/bls/chr/belanus/mod/main/file_to_push.mb" )

    """
    # Make sure vtype exists
    if utils.checkVersionType (vtype) :
        return False

    # Check if DB is provided else get the project DB
    if (not db)  or db=="" :
        db=utils.getDb()

    # Check if 'path' is a string
    if type (path)==str:

        # If 'path' is a string then append it in a list
        path=list ([ path ])

    # If doc_id not provided
    if not doc_id:

        # Get doc_id from path
        doc_id=getIdFromPath (path = path[0])

    # Return the directory of the pushed files
    result=push (db = db , doc_id = doc_id , path = path ,
                  description = description, progressbar = False,
                  msgbar = False, rename = rename, vtype = vtype)
    return result
예제 #8
0
파일: repository.py 프로젝트: pixo/hk
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)
예제 #9
0
파일: project.py 프로젝트: 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
예제 #10
0
파일: asset.py 프로젝트: pixo/hk
def createAsset ( db = None, doc_id = "", description = "", overdoc = dict() ): 
    """
    This function create an **asset** 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" )
    >>> createAsset ( db = db, doc_id = "prod_ch_mickey", "This is the mickey characters" )
    
    """
    
    # Check if db exist if not, get the current project db
    if db == None:
        db = utils.getDb ()
        
    # Get data from doc_id
    project, typ, asset = doc_id.split ( "_" )
    name = "%s_%s" % ( typ, asset )
    
    #Check if project name is right
    if not ( project in db ) :
        print "createAsset: %s project doesn't exist" % project
        return False
    
    # If asset doesn't exist create the asset
    if not ( doc_id in db ) :
        
        #Create the asset structure
        doc = {
            "type" : typ,
            "_id" : doc_id,
            "project_id" : project,
            "name" : name,
            "description" : description,
            "creator" : os.getenv ( "USER" ),
            "created" : time.strftime ( "%Y %b %d %H:%M:%S", time.localtime() ),
            "state" : "na"
            }
        
        #Add extra data if needed
        doc.update ( overdoc )
        
        # Save data structure into the database
        _id, _rev = db.save (doc )
        
        print "createAsset: Added %r to project %r" % ( name , project )
        return db[_id]
    
    else:        
        print "createAsset: %s already exist" % name
        return False
예제 #11
0
파일: asset.py 프로젝트: 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]
예제 #12
0
파일: examples.py 프로젝트: pixo/hk
    if not os.path.exists ( path ):
        print "hk-texture-publish: %s doesn't exists" % path
        return 1

    db = utils.getDb ()
    doc_id = core.getIdFromPath ( path )
        
    if not ( doc_id in db ) :
        print "hk-push: %s isn't in the  database" % doc_id
        return 1

    if os.path.isdir ( path ) :
        core.pushDir ( db, doc_id, path, description )
            
    else :
        basename = os.path.basename ( path )
        if basename.find ( doc_id ) == 0 :
            core.pushFile ( db, doc_id, path, description )
    
        else:
            print "wrong naming convention"

if __name__ == '__main__':
#     path = "/homeworks/users/pixo/projects/test/chr/mickey/mod/a/test_chr_mickey_mod_a.ma"
#     description = "test asset"
#     pushfile ( path, description )
#     getAnAssetVersion ()
    db = utils.getDb()
    versions = db [ "cpt_chr_jdoe_mod_a" ]["versions"]
    print (versions)
예제 #13
0
파일: examples.py 프로젝트: pixo/hk
def createTaskOnDB(doc_id):
    db=utils.getDb()
    description="Test"
    stat=core.createTask(db = db, doc_id = doc_id, description = description, debug = True)
예제 #14
0
파일: examples.py 프로젝트: pixo/hk
def lsAllType():
    db=utils.getDb()
    typ="asset"
    startkey="loc"
    asset_ls=utils.lsDb(db, typ, startkey)
    return asset_ls
예제 #15
0
    def __init__( self, fpath = "", parent = None ):
        super ( UiCheckDependencies, self ).__init__( parent )

        self.fpath = fpath
        self.paths = self.getPaths ()
        self.db = utils.getDb ()

        self.setObjectName( "MainWindow" )
        self.resize ( 642, 726 )
        self.centralwidget = QtGui.QWidget ( self )
        self.centralwidget.setObjectName( "centralwidget" )
        self.horizontalLayout_2 = QtGui.QHBoxLayout( self.centralwidget )
        self.horizontalLayout_2.setObjectName( "horizontalLayout_2" )
        self.verticalLayout_main = QtGui.QVBoxLayout()
        self.verticalLayout_main.setObjectName( "verticalLayout_main" )
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName( "horizontalLayout" )
        self.verticalLayout = QtGui.QVBoxLayout()
        self.verticalLayout.setSizeConstraint( QtGui.QLayout.SetDefaultConstraint )
        self.verticalLayout.setObjectName( "verticalLayout" )
        self.horizontalLayout_6 = QtGui.QHBoxLayout()
        self.horizontalLayout_6.setObjectName( "horizontalLayout_6" )
        self.label_sys = QtGui.QLabel( self.centralwidget )
        self.label_sys.setMaximumSize( QtCore.QSize( 21, 16777215 ) )
        self.label_sys.setObjectName( "label_sys" )
        self.horizontalLayout_6.addWidget( self.label_sys )
        self.label_proj = QtGui.QLabel( self.centralwidget )
        self.label_proj.setObjectName( "label_proj" )
        self.horizontalLayout_6.addWidget( self.label_proj )
        self.verticalLayout.addLayout( self.horizontalLayout_6 )

        self.horizontalLayout.addLayout( self.verticalLayout )
        self.verticalLayout_2 = QtGui.QVBoxLayout()
        self.verticalLayout_2.setObjectName( "verticalLayout_2" )
        self.labelImage = QtGui.QLabel( self.centralwidget )
        self.labelImage.setMinimumSize( QtCore.QSize( 300, 300 ) )
        self.labelImage.setText( "" )
        self.labelImage.setObjectName( "labelImage" )
        self.verticalLayout_2.addWidget( self.labelImage )
        self.plainTextEdit_description = QtGui.QPlainTextEdit( self.centralwidget )
        self.plainTextEdit_description.setEnabled ( False )
        self.plainTextEdit_description.setPlainText( "" )
        self.plainTextEdit_description.setObjectName ( "plainTextEdit_description" )
        self.verticalLayout_2.addWidget( self.plainTextEdit_description )
        self.horizontalLayout.addLayout( self.verticalLayout_2 )
        self.verticalLayout_main.addLayout( self.horizontalLayout )
        self.horizontalLayout_2.addLayout( self.verticalLayout_main )
        self.setCentralWidget( self.centralwidget )
        self.statusbar = QtGui.QStatusBar( self )
        self.statusbar.setObjectName( "statusbar" )
        self.setStatusBar( self.statusbar )
        self.setWindowTitle( "Check Dependencies" )
        self.label_sys.setPixmap ( utils.getIconPath( self.launcher ) )
        self.label_proj.setText( """<html><head/><body><p><span style=\" font-size:12pt;
                                    font-weight:600;\">Asset Updater </span><span style=\" font-size:12pt;
                                    \"/><span style=\" font-size:12pt;font-weight:600;
                                    \">:</span><span style=\" font-size:12pt;
                                    \"> '%s'</span></p></body></html>""" % ( os.getenv ( "HK_PROJECT" ) ) )

        self.tableWidget = QtGui.QTableWidget ( len ( self.paths ), 2 )
        self.tableWidget.setHorizontalScrollBarPolicy ( QtCore.Qt.ScrollBarAlwaysOff )
        self.tableWidget.setAlternatingRowColors ( True )
        self.tableWidget.horizontalHeader().setStretchLastSection ( True )
        self.tableWidget.horizontalHeader().setMinimumSectionSize ( 200 )
        self.tableWidget.verticalHeader().hide ()
        self.tableWidget.horizontalHeader().hide ()
        self.tableWidget.setSelectionMode ( QtGui.QAbstractItemView.SingleSelection )
        self.tableWidget.resizeColumnToContents ( True )
        self.tableWidget.setMouseTracking ( False )
        self.verticalLayout.addWidget( self.tableWidget )
        self.tableWidget.itemClicked.connect ( self.tableClicked )
        self.tableWidget.cellClicked.connect ( self.comboxChanged )

        self.horizontalLayout_3 = QtGui.QHBoxLayout()
        self.horizontalLayout_3.setObjectName( "horizontalLayout_3" )
        spacerItem1 = QtGui.QSpacerItem( 40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum )
        self.horizontalLayout_3.addItem( spacerItem1 )
        self.pushButton_2 = QtGui.QPushButton( self.centralwidget )
        self.pushButton_2.setFixedSize ( QtCore.QSize ( 80, 27 ) )
        self.pushButton_2.setObjectName( "pushButton_2" )
        self.horizontalLayout_3.addWidget( self.pushButton_2 )
        self.pushButton = QtGui.QPushButton( self.centralwidget )
        self.pushButton.setFixedSize( QtCore.QSize ( 60, 27 ) )
        self.pushButton.setObjectName( "pushButton" )
        self.horizontalLayout_3.addWidget( self.pushButton )
        self.verticalLayout.addLayout( self.horizontalLayout_3 )
        self.pushButton_2.setText ( "Update All" )
        self.pushButton_2.setIcon ( QtGui.QIcon ( utils.getIconPath( "refresh" ) ) )
        self.pushButton_2.clicked.connect ( self.updateAllClicked )
        self.pushButton.clicked.connect ( self.doneClicked )
        self.pushButton.setText ( "Done" )
        self.pushButton.setIcon ( QtGui.QIcon ( utils.getIconPath( "done" ) ) )

        self.buildTable()
        QtCore.QMetaObject.connectSlotsByName( self )
예제 #16
0
파일: repository.py 프로젝트: pixo/hk
def pull (db = None, doc_id = "", version = "last", extension = False,
           progressbar = False, msgbar = False, vtype = "review"):

    """
    This function copy the desired file from repository to local workspace.

    :param db: the database
    :type db: Database
    :param doc_id: The asset code
    :type doc_id: str
    :param version: The asset version
    :type version: int/str
    :param extension: The file extension
    :type extension: int/str
    :param progressbar: The pyside progress bar
    :type progressbar: PySide progressbar
    :param msg: The pyside message bar
    :type progressbar: PySide messagebar
    :param vtype: Version type *trial/stock*
    :type vtype: str
    :returns: list -- a list of the pulled file.

    **Example:**
    
    >>> db = utils.getDb()
    >>> pull ( db = db, doc_id = "bls_chr_belanus_mod_main", version = 2 )
    >>> ['/homeworks/users/jdoe/projects/bls/chr/belanus/mod/main/bls_chr_belanus_mod_main.v002.base/bls_chr_belanus_mod_main.jpg',
    >>> '/homeworks/users/jdoe/projects/bls/chr/belanus/mod/main/bls_chr_belanus_mod_main.v002.base/bls_chr_belanus_mod_main.mb']

    """
    # Make sure vtype exists
    if utils.checkVersionType (vtype) :
        return False

    def echoMsg (msg = "", msgbar = None):
        print msg
        if msgbar :
            msgbar (msg)

    # If db is not provided get the current project DB
    if db==None :
        db=utils.getDb()

    # Check id is respecting the homeworks naming convention
    docsplit=doc_id.split("_")
    if len (docsplit)<5:
        echoMsg (msg = "pull(): Wrong asset id", msgbar = msgbar)
        return False

    # Get asset repository and local asset path
    src=getVersionPath (doc_id = doc_id, version = version, db = db, vtype = vtype)
    dst=getLocalVersionPath (doc_id = doc_id, version = version, vtype = vtype)

    # Add/Check files to pull
    lsdir=list ()
    for root, subFolders, files in os.walk (src):

        for fil in files:
            curfile=os.path.join (root, fil)

            if extension and extension!="" :
                if os.path.splitext (curfile)[-1]==extension :
                    lsdir.append (curfile)
            else :
                lsdir.append (curfile)

    # Prepare the progress bar
    if progressbar :
        progress_value=0
        progress_step=100.0/len(lsdir) if len(lsdir)!=0 else 1

    # Check there is something to pull
    if len (lsdir)>0 :
        os.makedirs (dst, 0775)
        if not os.path.exists (dst):
            raise RepositoryError ("Pull(): cannot create %s "%dst)

    # Pull lsdir file
    pulled=list()
    for fil in lsdir:
        fulldst=fil.replace (src, dst)
        shutil.copyfile (fil, fulldst)
        pulled.append (fulldst)

        # Echo message
        msg="core.Pull(): %s"%fulldst
        echoMsg (msg = msg, msgbar = msgbar)

        if progressbar :
            progress_value+=progress_step
            progressbar.setProperty ("value", progress_value)

    return pulled