Exemplo n.º 1
0
    def __init__(self, replace_db=True):
        ## List of data sets
        self.catalog = []

        # Connect/create to DB
        db_path = os.path.join(os.path.expanduser("~"), ".mantid_data_sets")
        self.db_exists = False
        self.db = None

        try:
            self._create_db(db_path, replace_db)
        except Exception as msg:
            logger.error("DataCatalog: Could not access local data catalog\n%s" % sys.exc_info()[1])
            logger.exception(msg)
Exemplo n.º 2
0
    def __init__(self, replace_db=True):
        ## List of data sets
        self.catalog = []

        # Connect/create to DB
        db_path = os.path.join(os.path.expanduser("~"), ".mantid_data_sets")
        self.db_exists = False
        self.db = None

        try:
            self._create_db(db_path, replace_db)
        except Exception as msg:
            logger.error("DataCatalog: Could not access local data catalog\n%s" % sys.exc_info()[1])
            logger.exception(msg)
Exemplo n.º 3
0
    def list_data_sets(self,
                       data_dir=None,
                       call_back=None,
                       process_files=True):
        """
            Process a data directory
        """
        self.catalog = []

        if self.db is None:
            print "DataCatalog: Could not access local data catalog"
            return

        c = self.db.cursor()

        if not os.path.isdir(data_dir):
            return

        try:
            for f in os.listdir(data_dir):
                if f.endswith(self.extension):
                    file_path = os.path.join(data_dir, f)

                    if hasattr(self.data_set_cls, "find_with_api"):
                        d = self.data_set_cls.find_with_api(
                            file_path, c, process_files=process_files)
                    else:
                        d = self.data_set_cls.find(file_path,
                                                   c,
                                                   process_files=process_files)
                    if d is not None:
                        if call_back is not None:
                            attr_list = d.as_string_list()
                            type_id = self.data_set_cls.data_type_cls.get_likely_type(
                                d.id, c)
                            attr_list += (type_id, )
                            call_back(attr_list)
                        self.catalog.append(d)

            self.db.commit()
            c.close()
        except Exception, msg:
            logger.error(
                "DataCatalog: Error working with the local data catalog\n%s" %
                str(traceback.format_exc()))
            logger.exception(msg)
Exemplo n.º 4
0
    def list_data_sets(self, data_dir=None, call_back=None, process_files=True):
        """
            Process a data directory
        """
        self.catalog = []

        if self.db is None:
            print ("DataCatalog: Could not access local data catalog")
            return

        c = self.db.cursor()

        if not os.path.isdir(data_dir):
            return

        try:
            for f in os.listdir(data_dir):
                for extension in self.extension:
                    if f.endswith(extension):
                        file_path = os.path.join(data_dir, f)
                        if hasattr(self.data_set_cls, "find_with_api"):
                            d = self.data_set_cls.find_with_api(file_path, c,
                                                                process_files=process_files)
                        else:
                            d = self.data_set_cls.find(file_path, c,
                                                       process_files=process_files)
                        if d is not None:
                            if call_back is not None:
                                attr_list = d.as_string_list()
                                type_id = self.data_set_cls.data_type_cls.get_likely_type(d.id, c)
                                attr_list += (type_id,)
                                call_back(attr_list)
                            self.catalog.append(d)

            self.db.commit()
            c.close()
        except Exception as msg:
            logger.error("DataCatalog: Error working with the local data catalog\n%s" % str(traceback.format_exc()))
            logger.exception(msg)