當前位置: 首頁>>代碼示例>>Python>>正文


Python DRSTree.set_move_cmd方法代碼示例

本文整理匯總了Python中drslib.drs_tree.DRSTree.set_move_cmd方法的典型用法代碼示例。如果您正苦於以下問題:Python DRSTree.set_move_cmd方法的具體用法?Python DRSTree.set_move_cmd怎麽用?Python DRSTree.set_move_cmd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在drslib.drs_tree.DRSTree的用法示例。


在下文中一共展示了DRSTree.set_move_cmd方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Command

# 需要導入模塊: from drslib.drs_tree import DRSTree [as 別名]
# 或者: from drslib.drs_tree.DRSTree import set_move_cmd [as 別名]
class Command(object):
    def __init__(self, op, opts, args):
        self.op = op
        self.opts = opts
        self.args = args
        self.shelve_dir = None
        self.p_cmip5_config = None
        self.drs_root = None
        self.drs_tree = None

        self.make_drs_tree()

    def _config_p_cmip5(self):
        """
        Ensure self.shelve_dir is set.  This is required for InitCommand
        and any command that uses p_cmip5.

        """
        self.shelve_dir = self.opts.shelve_dir
        if self.shelve_dir is None:
            try:
                self.shelve_dir = config.config.get("p_cmip5", "shelve-dir")
            except NoSectionError:
                raise Exception(
                    "Shelve directory not specified.  Please use --shelve-dir or set shelve_dir via metaconfig"
                )

    def _setup_p_cmip5(self):
        """
        Instantiate the p_cmip5.cmip5_product object ready for deducing
        the product component.

        """

        shelves = p_cmip5.init._find_shelves(self.shelve_dir)

        self.p_cmip5_config = self.opts.p_cmip5_config
        if self.p_cmip5_config is None:
            try:
                self.p_cmip5_config = config.config.get("p_cmip5", "config")
            except (NoSectionError, NoOptionError):
                raise Exception(
                    "p_cmip5 configuration file not specified.  Please use --p-cmip5-config or set via metaconfig"
                )

        self.drs_tree.set_p_cmip5(
            p_cmip5.product.cmip5_product(
                mip_table_shelve=shelves["stdo_mip"],
                template=shelves["template"],
                stdo=shelves["stdo"],
                config=self.p_cmip5_config,
                not_ok_excpt=True,
            )
        )

    def make_drs_tree(self):
        if self.opts.root:
            self.drs_root = self.opts.root
        else:
            try:
                self.drs_root = config.drs_defaults["root"]
            except KeyError:
                raise Exception("drs-root not defined")

        if self.opts.incoming:
            incoming = self.opts.incoming
        else:
            try:
                incoming = config.drs_defaults["incoming"]
            except KeyError:
                incoming = os.path.join(self.drs_root, config.DEFAULT_INCOMING)

        if self.opts.json_drs:
            json_drs = self.opts.json_drs
        else:
            json_drs = None

        drs_root = os.path.normpath(os.path.abspath(self.drs_root))

        if self.opts.scheme:
            scheme = self.opts.scheme
        else:
            scheme = config.default_drs_scheme

        try:
            fs_cls = config.get_drs_scheme(scheme)
        except KeyError:
            raise ValueError("Unrecognised DRS scheme %s" % scheme)

        self.drs_fs = fs_cls(drs_root)
        self.drs_tree = DRSTree(self.drs_fs)

        if self.opts.move_cmd:
            self.drs_tree.set_move_cmd(self.opts.move_cmd)

        # This code is specifically for the deprecated DRS setting options
        # Generic DRS component setting is handled below
        kwargs = {}
        for attr in ["activity", "product", "institute", "model", "experiment", "frequency", "realm", "ensemble"]:
            try:
#.........這裏部分代碼省略.........
開發者ID:ESGF,項目名稱:esgf-drslib,代碼行數:103,代碼來源:drs_command.py

示例2: Command

# 需要導入模塊: from drslib.drs_tree import DRSTree [as 別名]
# 或者: from drslib.drs_tree.DRSTree import set_move_cmd [as 別名]
class Command(object):
    def __init__(self, opts, args):
        self.opts = opts
        self.args = args
        self.shelve_dir = None
        self.p_cmip5_config = None
        self.drs_root = None
        self.drs_tree = None

        self.make_drs_tree()

    def _config_p_cmip5(self):
        """
        Ensure self.shelve_dir is set.  This is required for InitCommand
        and any command that uses p_cmip5.

        """
        self.shelve_dir = self.opts.shelve_dir
        if self.shelve_dir is None:
            try:
                self.shelve_dir = config.config.get('p_cmip5', 'shelve-dir')
            except NoSectionError:
                raise Exception("Shelve directory not specified.  Please use --shelve-dir or set shelve_dir via metaconfig")

    def _setup_p_cmip5(self):
        """
        Instantiate the p_cmip5.cmip5_product object ready for deducing
        the product component.

        """
        
        shelves = p_cmip5.init._find_shelves(self.shelve_dir)
    
        self.p_cmip5_config = self.opts.p_cmip5_config
        if self.p_cmip5_config is None:
            try:
                self.p_cmip5_config = config.config.get('p_cmip5', 'config')
            except (NoSectionError, NoOptionError):
                raise Exception("p_cmip5 configuration file not specified.  Please use --p-cmip5-config or set via metaconfig")

        self.drs_tree.set_p_cmip5(p_cmip5.product.cmip5_product(
                mip_table_shelve=shelves['stdo_mip'],
                template=shelves['template'],
                stdo=shelves['stdo'],
                config=self.p_cmip5_config,
                not_ok_excpt=True))


    def make_drs_tree(self):
        if self.opts.root:
            self.drs_root = self.opts.root
        else:
            try:
                self.drs_root = config.drs_defaults['root']
            except KeyError:
                raise Exception('drs-root not defined')

        if self.opts.incoming:
            incoming = self.opts.incoming
        else:
            try:
                incoming = config.drs_defaults['incoming']
            except KeyError:
                incoming = os.path.join(self.drs_root, config.DEFAULT_INCOMING)

        self.drs_tree = DRSTree(self.drs_root)

        if self.opts.move_cmd:
            self.drs_tree.set_move_cmd(self.opts.move_cmd)


        kwargs = {}
        for attr in ['activity', 'product', 'institute', 'model', 'experiment', 
                     'frequency', 'realm', 'ensemble']:
            try:
                val = getattr(self.opts, attr)
                # val may be there but None
                if val is None:
                    raise AttributeError
            except AttributeError:
                val = config.drs_defaults.get(attr)

            kwargs[attr] = val

        # Get the template DRS from args
        if self.args:
            dataset_id = self.args[0]
            drs = DRS.from_dataset_id(dataset_id, **kwargs)
        else:
            drs = DRS(**kwargs)

        # Product detection
        if self.opts.detect_product:
            self._config_p_cmip5()
            self._setup_p_cmip5()

        self.drs_tree.discover(incoming, **drs)

    def do(self):
        raise NotImplementedError("Unimplemented command")
#.........這裏部分代碼省略.........
開發者ID:alaniwi,項目名稱:esgf-drslib,代碼行數:103,代碼來源:drs_command.py


注:本文中的drslib.drs_tree.DRSTree.set_move_cmd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。