Beispiel #1
0
 def save_content(self, content, file_name, file_property):
     mongo_helper = MongodbHelper(self.host, self.port)
     file_bucket_fs = mongo_helper.pub_file_bucket(self.db, self.collection,
                                                   file_name, file_property)
     file_bucket_fs.write(content.encode(encoding="utf-8"))
     file_bucket_fs.close()
     return file_bucket_fs._id
Beispiel #2
0
class CITaskConfigManager(object):
    def __init__(self, mongo_host, mongo_port, db, collection):
        self.host = mongo_host
        self.port = mongo_port
        self.db = db
        self.collection = collection
        self.default_db = "doraemon"
        self.default_collection = "ci"
        self.mongo_helper = MongodbHelper(self.host, self.port)

    def save(self, value):
        return self.mongo_helper.save(self.db, self.collection, value)

    def remove(self, doc_id):
        result = self.mongo_helper.remove(self.db, self.collection, doc_id)
        if result == None:
            result = self.mongo_helper.remove(self.default_db,
                                              self.default_collection, doc_id)
        return result

    def get(self, doc_id):
        result = self.mongo_helper.get(self.db, self.collection, doc_id)
        if result == None:
            result = self.mongo_helper.get(self.default_db,
                                           self.default_collection, doc_id)
        return result
Beispiel #3
0
 def get_replace_config(self, doc_id):
     mongo_helper = MongodbHelper(CIDeployServiceManager.host, CIDeployServiceManager.port)
     result = mongo_helper.get(CIDeployServiceManager.db, CIDeployServiceManager.collection, doc_id)
     if result == None:
         result = mongo_helper.get(CIDeployServiceManager.default_db, CIDeployServiceManager.default_collection,
                                   doc_id)
     return result
 def save_bucket(self,file_chunks,file_name,file_property):
     mongo_helper=MongodbHelper(self.host,self.port)
     file_bucket_fs=mongo_helper.pub_file_bucket(self.db,self.collection,file_name,file_property)
     for chunk in file_chunks:
         file_bucket_fs.write(chunk)
     file_bucket_fs.close()
     return file_bucket_fs._id
Beispiel #5
0
 def get(db, collection, doc_id):
     HOST = MONGODB['default']['HOST']
     PORT = MONGODB['default']['PORT']
     mongo_helper = MongodbHelper(HOST, PORT)
     result = mongo_helper.get(db, collection, doc_id)
     if result == None:
         result = mongo_helper.get('doraemon', 'ci', doc_id)
     return result
Beispiel #6
0
 def __init__(self, mongo_host, mongo_port, db, collection):
     self.host = mongo_host
     self.port = mongo_port
     self.db = db
     self.collection = collection
     self.default_db = "doraemon"
     self.default_collection = "ci"
     self.mongo_helper = MongodbHelper(self.host, self.port)
Beispiel #7
0
 def get(self, file_id):
     mongo_helper = MongodbHelper(self.host, self.port)
     grid_out = mongo_helper.get_file_bucket(self.db, self.collection,
                                             file_id)
     if grid_out == None:
         grid_out = mongo_helper.get_file_bucket(self.default_db,
                                                 self.default_collection,
                                                 file_id)
     return grid_out
Beispiel #8
0
 def copy_bucket(self, grid_out):
     mongo_helper = MongodbHelper(self.host, self.port)
     file_bucket_fs = mongo_helper.pub_file_bucket(self.db, self.collection,
                                                   grid_out.name,
                                                   grid_out.metadata)
     while True:
         chunk = grid_out.read(size=1024 * 1024 * 10)
         if chunk:
             file_bucket_fs.write(chunk)
         else:
             break
     file_bucket_fs.close()
     return file_bucket_fs._id
 def delete_file(self,file_id):
     try:
         mongo_helper=MongodbHelper(self.host,self.port)
         mongo_helper.delete_file(self.db,self.collection, file_id)
         mongo_helper.delete_file(self.default_db,self.default_collection, file_id)
     except Exception as ex:
         SimpleLogger.exception(ex)
 def save_value(self, value):
     mongo_helper = MongodbHelper(self.host, self.port)
     doc_id = mongo_helper.save(self.db, self.collection, value)
     return doc_id
Beispiel #11
0
 def get_value(self, doc_id):
     mongo_helper = MongodbHelper(self.host, self.port)
     grid_out = mongo_helper.get(self.db, self.collection, doc_id)
     return grid_out
Beispiel #12
0
 def save_replace_config(self, value):
     mongo_helper = MongodbHelper(CIDeployServiceManager.host,
                                  CIDeployServiceManager.port)
     return mongo_helper.save(CIDeployServiceManager.db,
                              CIDeployServiceManager.collection, value)
 def get(db, collection, doc_id):
     HOST = MONGODB['default']['HOST']
     PORT = MONGODB['default']['PORT']
     mongo_helper = MongodbHelper(HOST, PORT)
     result = mongo_helper.get(db, collection, doc_id)
     return result
 def save(db, collection, value):
     HOST = MONGODB['default']['HOST']
     PORT = MONGODB['default']['PORT']
     mongo_helper = MongodbHelper(HOST, PORT)
     return mongo_helper.save(db, collection, value)
Beispiel #15
0
 def delete_value(self, file_id):
     mongo_helper = MongodbHelper(self.host, self.port)
     file_id = mongo_helper.remove(self.db, self.collection, file_id)
     file_id = mongo_helper.remove(self.default_db, self.default_collection,
                                   file_id)
     return file_id
Beispiel #16
0
 def save(self, file_bytes, file_property):
     mongo_helper = MongodbHelper(self.host, self.port)
     file_id = mongo_helper.put_file(self.db, self.collection, file_bytes,
                                     file_property)
     return file_id
 def update_value(self, doc_id, value):
     mongo_helper = MongodbHelper(self.host, self.port)
     doc_id = mongo_helper.update(self.db, self.collection, doc_id, value)
     return doc_id