当前位置: 首页>>代码示例>>Python>>正文


Python Document.update方法代码示例

本文整理汇总了Python中Document.Document.update方法的典型用法代码示例。如果您正苦于以下问题:Python Document.update方法的具体用法?Python Document.update怎么用?Python Document.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document.Document的用法示例。


在下文中一共展示了Document.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Document import Document [as 别名]
# 或者: from Document.Document import update [as 别名]
class Query:
    '''
    The aim of this class is create and manage the query using different info in alias.txt,lastquery.txt and other argoments and 
    to send the query to the istance of DBlink class. 
    '''
    def __init__(self):
        '''
        In initialization, the class save a reference of DBlink class and two references of Document class, one for
        info of last query and one to alias. 
        '''
        self.dblink=DBlink()
        #the lastquery document must be into personal path (into HOME for Linux and MacOS, into Documents for Windows)
        self.lastquery=Document("lastquery.txt")
        #the alias document must be into class' path
        path=os.path.dirname(os.path.abspath(__file__))
        self.alias=KL_Document("alias.txt",path)
        #default table for mecordex user
        self.default_table='MEDCORDEX'
        
    def is_alias(self,name):
        '''
        This function defines the field's name into 'where' of query to send it to the database.
        @param name: string, name of field
        @return string, definitive name choosen between the same name and the alias params
        '''
        alias=name
        for field in self.alias.get_params().keys():
            if name in self.alias.get_params()[field]: alias=field
        return alias
        
    def build_where(self,args):
        '''
        Build the 'where' field of query. 
        @param args: dictionary {field:value}
        @return s: string. If args={field:value, ...} return s=where field='value' and ... 
        '''
        string=""
        for field in args.keys():
            if string!="": string+=" and"
            string+= " "+self.is_alias(field)+" = '"+args[field]+"'"
        if string!="": string=" where"+string
        return string
    
    def save_query(self,query):
        '''
        Save query in lastquery.txt
        @param query: string like "select fields from table where field=value and .."
        '''
        self.lastquery.write({"query":query})
        
    def save_datasets(self,datasets):
        #save in lastquery.txt {row:dataset name} (no delete query)
        i=1
        lq={}
        lq["query"]=self.lastquery.get_parameter("query")
        for d in datasets:
            lq[i]=d
            i+=1
        self.lastquery.update(lq)
        
    def triple2table(self,triple):
        '''
        Build a table of string type
        @param triple=((dataset1,size1,fname1),(dataset2,size2,fname2),....)
        @return table: string in format --- row N Datasets, N files, N size(MB)
        '''
        numByte={}
        numFile={}
        if len(triple)>0:
            s="row %69s %13s %14s\n"%("DATASET NAME","N FILES","N MBs")
        for dataset,size,fname in triple:
            if dataset in numByte:
                numByte[dataset]+=size
                numFile[dataset]+=1
            else:
                numByte[dataset]=size
                numFile[dataset]=1
        #save dataset in lastquery.txt
        self.save_datasets(numByte.keys())
        i=0
        for dataset in numByte:
            i+=1
            s+= "%02d %70s : %5d files %10.2f MB \n"%(i,dataset,numFile[dataset],numByte[dataset])
        return "\nFound "+str(sum(numFile.values()))+" files in "+str(len(numByte))+" Datasets, total size "+str(sum(numByte.values()))+"MB\n\n"+s
        
    def do_query(self,args={},select="*",save=True,query=""):
        '''
        This function builds the query if parameter query is void, sends the query,
        save the query in lastquery.txt and returns the result(tupla).
        This function saves only query, doesn't save dataset
        @param args: dictionary {filed:value}
        @param select: string "field1,field2,..." or "*"(all), need to select the fields in query
        @param save: boolean, need to save the query
        @param query: string, query to send at DBlink class. If query is a void string then make string query with other parameters.
        @return tuple: ((result1),(result2),...,(resultN))
        '''
        if query=="":
            table=self.dblink.get_table()
            if table=='': table=self.default_table
            query="select "+select+" from "+table+self.build_where(args)
#.........这里部分代码省略.........
开发者ID:ClaudioR3,项目名称:workspace,代码行数:103,代码来源:Query.py

示例2: __init__

# 需要导入模块: from Document import Document [as 别名]
# 或者: from Document.Document import update [as 别名]
class DBlink:
    '''
    This class links the others classes with a database. The database's informations are into the document 
    'config.txt' rappresenting by class Document called config.
    '''
    
    def __init__(self):
        '''
        Initialization of object Document for configuration data and all default info
        '''
        self.config=Document("config.txt")
        self.default_host='www.medcordex.eu'
        self.default_user='sagitta'
        self.default_passwd='sagitta'
        self.default_db='medcordex'
        
    def set_config(self,params):
        '''
        Set new params of config Document
        @param params: dictionary
        '''
        self.config.update(params)
    
    def get_config_toString(self):
        '''
        Take the params of config Document
        @return params: string, params of config Document
        '''
        return self.config.toString()
    
    def del_config(self):
        '''
        Delete all info of the config Document
        '''
        self.config.delete()
        
    def get_doc(self):
        '''
        @return config: Document object, config Document
        '''
        return self.config
    
    def get_table(self):
        '''
        @return table: string, table info into config Document
        '''
        return self.config.get_parameter("table")
    
    def get_db(self):
        '''
        @return db: string, db info into config Document
        '''
        return self.config.get_parameter("db")
    
    def get_url(self):
        '''
        @return url info: string token by 'config' Document. If url is a void string and the host info is equals 
        to www.medcordex.eu return the default url for medcordex users.
        '''
        url= self.config.get_parameter("url")
        if url=="":
            #default url for medcordex users
            if self.config.get_parameter("host")=="www.medcordex.eu":
                url="ftp://"+self.config.get_parameter("user")+":"+self.config.get_parameter("passwd")+"@"+self.config.get_parameter("host")+"/ALL/"
        return url
        
    def send_query(self,query):
        '''
        Send query using mysql.connector module. To send the query, the function needs the informations
        host, user, passwd and db token by 'config' Document. If the host and db info are void string, the function send the query
        to default info.
        @param query: string in form like SELECT fields FROM table WHERE conditions
        @return tuple: query response
        '''
        if self.config.get_parameter("host")=='' and self.config.get_parameter('db')=='':
            # default configuration for medcordex users
            database=mysql.connect(host=self.default_host,
                                     user=self.default_user,
                                     passwd=self.default_passwd,
                                     db=self.default_db)
        else:
            # personal configuration for all other cases
            database=mysql.connect(host=self.config.get_parameter("host"),
                                     user=self.config.get_parameter("user"),
                                     passwd=self.config.get_parameter("passwd"),
                                     db=self.config.get_parameter("db"))
        cursore=database.cursor()
        cursore.execute(query)
        return cursore.fetchall()
开发者ID:ClaudioR3,项目名称:workspace,代码行数:91,代码来源:DBlink.py


注:本文中的Document.Document.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。