コード例 #1
0
def  main(proj_name, all_projects, conf, only_closed):
    first_of_july = '2013-06-30'
    today = date.today()
    couch = load_couch_server(conf)
    if all_projects:
        projects = lims.get_projects()
        for proj in projects:
            closed = proj.close_date
            if not only_closed or (only_closed and closed):
                contin = True
            else:
                contin = False
            if contin:
                proj_name = proj.name
                try:
                    proj_stage = lims_stage.get_projects(name = proj_name)
                    if len(proj_stage)==0 :
                        logging.warning("""Found no projects on Lims stage with name %s""" % proj_name)
                    else:
                        proj_stage = proj_stage[0]
                        opened = proj.open_date
                        if opened:
                            if comp_dates(first_of_july, opened):
                                obj = DB.ProjectDB(lims, proj.id, None)
                                obj_stage = DB.ProjectDB(lims_stage, proj.id, None)
                                comp_obj(obj_stage.obj, obj.obj)
                                obj=None
                                obj_stage=None
                        else:
                            logging.info('Open date missing for project %s' % proj_name)
                except:
                    logging.info('Failed comparing stage and prod for proj %s' % proj_name)    
    elif proj_name is not None:
        proj = lims.get_projects(name = proj_name)
        proj_stage = lims_stage.get_projects(name = proj_name)
        if (not proj) | (not proj_stage):
            logging.warning("""Found %s projects on Lims stage, and %s projects 
                        on Lims production with project name %s""" % (str(len(proj_stage)), str(len(proj)), proj_name))
        else:
            proj = proj[0]
            proj_stage = proj_stage[0]
            opened = proj.open_date
            if opened:
                if comp_dates(first_of_july, opened):
                    cont = 'yes'
                else:
                    cont = raw_input("""The project %s is opened before 2013-07-01. 
                    Do you still want to load the data from lims into statusdb? (yes/no): """ % proj_name)
                if cont == 'yes':
                    obj = DB.ProjectDB(lims, proj.id, None)
                    obj_stage = DB.ProjectDB(lims_stage, proj.id, None)
                    comp_obj(obj_stage.obj, obj.obj)
            else:
                logging.info('Open date missing for project %s' % proj_name)
コード例 #2
0
    def update_project(self):
        """Fetch project info and update project in the database."""
        self.log.info('Handling {proj}'.format(proj = self.name))
        project = DB.ProjectDB(self.lims, self.id, self.samp_db, self.log)

        key = find_proj_from_view(self.proj_db, self.name)
        project.obj['_id'] = find_or_make_key(key)
        if self.upload_data:
            info = save_couchdb_obj(self.proj_db, project.obj)
        else:
            info = self.print_couchdb_obj_to_file(project.obj)

        self.log.info("project {name} is handled and {info}: _id = {id}".format(
                           name=self.name, info=info, id=project.obj['_id']))
コード例 #3
0
ファイル: diff.py プロジェクト: htnani/LIMS2DB
        log.error("No such project {}".format(pj_id))

    old_project = proj_db.get(old_project_couchid)
    old_project.pop('_id', None)
    old_project.pop('_rev', None)
    old_project.pop('modification_time', None)
    old_project.pop('creation_time', None)

    if new:
        from LIMS2DB.classes import ProjectSQL
        session = get_session()
        host = get_configuration()['url']
        new_project = ProjectSQL(session, log, pj_id, host, couch)
    else:
        import LIMS2DB.objectsDB.objectsDB as DB
        new_project = DB.ProjectDB(lims, pj_id, samp_db, log)

    fediff = diff_objects(old_project, new_project.obj)

    return (fediff, old_project, new_project.obj)


def diff_objects(o1, o2, parent=''):
    diffs = {}

    for key in o1:
        if key in o2:
            if isinstance(o1[key], dict):
                more_diffs = diff_objects(o1[key], o2[key],
                                          "{} {}".format(parent, key))
                diffs.update(more_diffs)