class SavannahFormatter(object):
    """Class to format information into human readable format, and interact with SavannahBrowser class"""
    def __init__(self, username, password, taskID, opts):
        """Creates SavannahBrowser object and initialises dictionary as well as several important fields, also passes unformatted metadata to SavannahBrowser
    	
    	'username' takes users NICE username
    	'password' takes users NICE password
    	'opts' takes the list of metadata options to be passed to SavannahBrowser first, these do not require formatting"""
        self._savannahBrowser = SavannahBrowser(username, password, taskID)
        self._taskID = taskID
        self._opts = opts
        savOpts = self._savannahBrowser.getOpts()
        self.mainField = ""
        for i in self._opts:
            if savOpts is not None:
                if savOpts[i] is not None:
                    self._savannahBrowser.addOption(i, self._opts[i])

    def appendField(self, field):
        """Appends extra required information onto the end of the main section on Savannah
    	
    	'Extra' takes the required data as a string int float dict or list and passes it to the recursive read function before appending to an the userFields variable as a string
    	"""
        self.mainField += field + "\n\n"

    def publish(self):
        """Fill in the details section with the compiled data"""
        if self._taskID is None:
            self._savannahBrowser.addOption("details", self.mainField)
        else:
            self._savannahBrowser.addOption("comment", self.mainField)

        return self._savannahBrowser.post(self._opts['assigned_to'])
Esempio n. 2
0
class SavannahFormatter(object):
    """Class to format information into human readable format, and interact with SavannahBrowser class"""
	
    def __init__(self, username, password, taskID, opts):
    	"""Creates SavannahBrowser object and initialises dictionary as well as several important fields, also passes unformatted metadata to SavannahBrowser
    	
    	'username' takes users NICE username
    	'password' takes users NICE password
    	'opts' takes the list of metadata options to be passed to SavannahBrowser first, these do not require formatting"""
        self._savannahBrowser = SavannahBrowser(username,password, taskID)
        self._taskID=taskID
        self._opts = opts
        savOpts = self._savannahBrowser.getOpts()
        self.mainField = ""
        for i in self._opts:
            if savOpts is not None:
            	if savOpts[i] is not None:
                	self._savannahBrowser.addOption(i, self._opts[i])
    
    def appendField(self, field): 
    	"""Appends extra required information onto the end of the main section on Savannah
    	
    	'Extra' takes the required data as a string int float dict or list and passes it to the recursive read function before appending to an the userFields variable as a string
    	"""
    	self.mainField+=field+"\n\n"
        
    def publish(self):
    	"""Fill in the details section with the compiled data"""
        if self._taskID is None:
            self._savannahBrowser.addOption("details", self.mainField)
        else: self._savannahBrowser.addOption("comment", self.mainField)
        
        return self._savannahBrowser.post(self._opts['assigned_to'])
 def __init__(self, username, password, taskID, opts):
     """Creates SavannahBrowser object and initialises dictionary as well as several important fields, also passes unformatted metadata to SavannahBrowser
 	
 	'username' takes users NICE username
 	'password' takes users NICE password
 	'opts' takes the list of metadata options to be passed to SavannahBrowser first, these do not require formatting"""
     self._savannahBrowser = SavannahBrowser(username, password, taskID)
     self._taskID = taskID
     self._opts = opts
     savOpts = self._savannahBrowser.getOpts()
     self.mainField = ""
     for i in self._opts:
         if savOpts is not None:
             if savOpts[i] is not None:
                 self._savannahBrowser.addOption(i, self._opts[i])
Esempio n. 4
0
 def __init__(self, username, password, taskID, opts):
 	"""Creates SavannahBrowser object and initialises dictionary as well as several important fields, also passes unformatted metadata to SavannahBrowser
 	
 	'username' takes users NICE username
 	'password' takes users NICE password
 	'opts' takes the list of metadata options to be passed to SavannahBrowser first, these do not require formatting"""
     self._savannahBrowser = SavannahBrowser(username,password, taskID)
     self._taskID=taskID
     self._opts = opts
     savOpts = self._savannahBrowser.getOpts()
     self.mainField = ""
     for i in self._opts:
         if savOpts is not None:
         	if savOpts[i] is not None:
             	self._savannahBrowser.addOption(i, self._opts[i])
Esempio n. 5
0
def unPublish(dsName, fileown, user, password, development=False):

    if re.search("---", dsName):
        fileown = getDbsUser(dsName)
        dsName2 = getCastor(dsName)
        if dsName2 is None:
            print "\nError, " + dsName + " is not valid, please use valid name\n"
            return None
        else:
            dsName = dsName2

    if len(dsName.lstrip(os.sep).rstrip(os.sep).split(os.sep)) < 3:
        print "Error, " + dsName + " is not valid, please use valid name"
        return None
    elif len(dsName.lstrip(os.sep).rstrip(os.sep).split(os.sep)) < 4:
        print "Dataset " + dsName + "is a CMS base dataset and cannot be published, please use DAS."
        return None

    taskID = None
    loginClear = False
    if not validLogin(user, password):
        print "Authentication Failed, exiting\n\n"
        sys.exit(1)

    dataset = None
    try:
        dataset = Dataset(dsName, fileown)  #create the dataset
    except:
        print "Dataset does not exist on eos, proceeding to unpublish"

    cmgdbName = getCMGDBWithUser(dsName, fileown)
    print "\n------DataSet------\n"
    print "CMGDB NAME  : " + cmgdbName
    if dataset:
        dataset.printInfo()
        if dataset.files:  #check if the dataset has root files
            print "\nERROR: Dataset has root files present, you can only unpublish empty datasets!"
            #if it does cancel the unpublishing
            exit(-1)

    print "\n------Savanah------\n"

    try:
        if taskID is None:
            taskID = getTaskID(cmgdbName, opts['category_id'], user, password,
                               False)
    except:
        taskID = getTaskID(cmgdbName, '103', user, password, False)
    if taskID is not None:
        browser = SavannahBrowser(user, password, taskID)
        browser.closeTask()
        print "Task closed on Savannah"
        print "URL: https://savannah.cern.ch/task/?" + taskID
    else:
        print "No task was found, no closing neccesary"

    print "\n-------CMGDB-------\n"
    ID = None
    cmgdbAPI = CmgdbToolsApi(development)
    cmgdbAPI.connect()
    ID = cmgdbAPI.getDatasetIDWithName(cmgdbName)
    if ID is not None:
        try:
            cmgdbAPI.closeDataset(cmgdbName)
            print "Dataset closed on CMGDB"
        except:
            print "Dataset failed to close"
    else:
        print "Dataset not found on CMGDB"
Esempio n. 6
0
def unPublish( dsName, fileown, user, password, development=False ):
    
    if re.search("---",dsName):
        fileown = getDbsUser(dsName)
        dsName2 = getCastor(dsName)
        if dsName2 is None:
            print "\nError, "+dsName+" is not valid, please use valid name\n"
            return None
        else:
            dsName = dsName2
    	
    if len(dsName.lstrip(os.sep).rstrip(os.sep).split(os.sep)) < 3:
    	print "Error, "+dsName+" is not valid, please use valid name"
    	return None
    elif len(dsName.lstrip(os.sep).rstrip(os.sep).split(os.sep)) < 4:
    	print "Dataset "+ dsName + "is a CMS base dataset and cannot be published, please use DAS."
    	return None
    
    taskID = None
    loginClear = False
    if not validLogin(user, password):
        print "Authentication Failed, exiting\n\n"
        sys.exit(1)

    dataset = None
    try:
        dataset = Dataset( dsName, fileown ) #create the dataset
    except: 
        print "Dataset does not exist on eos, proceeding to unpublish"

    cmgdbName = getCMGDBWithUser( dsName, fileown )
    print "\n------DataSet------\n"
    print "CMGDB NAME  : " + cmgdbName
    if dataset:
	dataset.printInfo()
    	if dataset.files:               #check if the dataset has root files
        	print "\nERROR: Dataset has root files present, you can only unpublish empty datasets!" 
#if it does cancel the unpublishing
        	exit( -1 ) 
    	
    print "\n------Savanah------\n"
    	
    try:
        if taskID is None: taskID = getTaskID( cmgdbName, opts['category_id'], user, password, False)
    except:
        taskID = getTaskID( cmgdbName, '103', user, password, False)
    if taskID is not None:
        browser = SavannahBrowser( user, password, taskID )
        browser.closeTask()
        print "Task closed on Savannah"
        print "URL: https://savannah.cern.ch/task/?"+taskID
    else:
        print "No task was found, no closing neccesary"
    	 
    print "\n-------CMGDB-------\n"
    ID = None    
    cmgdbAPI=CmgdbToolsApi(development)
    cmgdbAPI.connect()
    ID = cmgdbAPI.getDatasetIDWithName( cmgdbName )
    if ID is not None:
        try:
            cmgdbAPI.closeDataset( cmgdbName )
            print "Dataset closed on CMGDB"
        except:
            print "Dataset failed to close"
    else:
        print "Dataset not found on CMGDB"