clusterjob/__init__.py
def read_defaults(cls, filename=None):
        """Set class attributes from the INI file with the given file name

        The file must be in the format specified in
        https://docs.python.org/3.5/library/configparser.html#supported-ini-file-structure
        with the default ConfigParser settings, except that all keys are case
        sensitive. It must contain exactly one or both of the sections
        "Attributes" and "Resources". The key-value pairs in the Attributes
        sections are set as class attributes, whereas the key-value pairs in
        the "Resources" section are set as keys and values in the `resources`
        class attribute.

        All keys in the "Attributes" section must be start with a letter, and
        must consist only of letters, numbers, and underscores. Keys in the
        "Resources" section can be arbitrary string. The key names 'resources'
        and 'backends' may not be used. An example for a valid config file is::

            [Attributes]
            remote = login.cluster.edu
            prologue =
                ssh {remote} 'mkdir -p {rootdir}/{workdir}'
                rsync -av {workdir}/ {remote}:{rootdir}/{workdir}
            epilogue = rsync -av {remote}:{rootdir}/{workdir}/ {workdir}
            rootdir = ~/jobs/
            # the following is a new attribute
            text = Hello World

            [Resources]
            queue = exec
            nodes = 1
            threads = 1
            mem = 10

        If no filename is given, reset all class attributes to their initial
        value, and delete any attributes that do not exist by default. This
        restores the JobScript class to a pristine state.
        """
        logger = logging.getLogger(__name__)
        def attr_setter(key, val):
            if not re.match(r'^[a-zA-Z]\w*$', key):
                raise ConfigParserError(("Key '%s' is invalid. Keys "
                "must be valid attribute names, i.e., they must match "
                "the regular expression '^[a-zA-Z]\w*$'") % key)
            val = cls._sanitize_attr(key, val)
            logger.debug("Set class attribute %s = %s",  key, val)
            setattr(cls, key, val)
        def rsrc_setter(key, val):
            logger.debug("Set class resources key %s = %s", key, val)
            cls.resources[key] = val
        if filename is None:
            # restore the original class attributes
            known_attrs = set.union(set(cls._attributes.keys()),
                                    set(cls._protected_attributes.keys()),
                                    set(['backends', ]) )
            for attr in list(cls.__dict__.keys()):
                if ((not attr.startswith('_'))
                and (attr not in known_attrs)
                and (not callable(getattr(cls, attr)))):
                    logger.debug("Removing class attribute '%s'", attr)
                    delattr(cls, attr)
            for attr in cls._attributes:
                logger.debug("Set class attribute '%s' to original value '%s'",
                             attr, cls._attributes[attr])
                setattr(cls, attr, cls._attributes[attr])
            for attr in cls._protected_attributes:
                # For the '_backends' attribute, the setattr below sets
                # cls._backends to a *reference* to
                # cls._protected_attributes['_backends'], not a copy. As a
                # consequence, any call to register_backend will modify both
                # locations, and we don't lose registered backends when
                # resetting.
                if attr == '_backends':
                    logger.debug("Keeping known backends: %s", list(
                            cls._protected_attributes['_backends'].keys()))
                else:
                    logger.debug("Set class attribute '%s' to original value "
                                 "'%s'", attr, cls._protected_attributes[attr])
                setattr(cls, attr, cls._protected_attributes[attr])
            cls.resources = OrderedDict()
            logger.debug("Set class attribute 'resources' to original value "
                         "OrderedDict()")
        else:
            cls._read_inifile(filename, attr_setter, rsrc_setter)
Set class attributes from the INI file with the given file name

        The file must be in the format specified in
        https://docs.python.org/3.5/library/configparser.html#supported-ini-file-structure
        with the default ConfigParser settings, except that all keys are case
        sensitive. It must contain exactly one or both of the sections
        "Attributes" and "Resources". The key-value pairs in the Attributes
        sections are set as class attributes, whereas the key-value pairs in
        the "Resources" section are set as keys and values in the `resources`
        class attribute.

        All keys in the "Attributes" section must be start with a letter, and
        must consist only of letters, numbers, and underscores. Keys in the
        "Resources" section can be arbitrary string. The key names 'resources'
        and 'backends' may not be used. An example for a valid config file is::

            [Attributes]
            remote = login.cluster.edu
            prologue =
                ssh {remote} 'mkdir -p {rootdir}/{workdir}'
                rsync -av {workdir}/ {remote}:{rootdir}/{workdir}
            epilogue = rsync -av {remote}:{rootdir}/{workdir}/ {workdir}
            rootdir = ~/jobs/
            # the following is a new attribute
            text = Hello World

            [Resources]
            queue = exec
            nodes = 1
            threads = 1
            mem = 10

        If no filename is given, reset all class attributes to their initial
        value, and delete any attributes that do not exist by default. This
        restores the JobScript class to a pristine state.
        


All keys in the "Attributes" section must be start with a letter, and
must consist only of letters, numbers, and underscores. Keys in the
"Resources" section can be arbitrary string. The key names 'resources'
and 'backends' may not be used. An example for a valid config file is:.



[Resources]
queue = exec
nodes = 1
threads = 1
mem = 10

If no filename is given, reset all class attributes to their initial
value, and delete any attributes that do not exist by default. This
restores the JobScript class to a pristine state.
All keys in the " Attributes " section must be start with a letter and must consist only of letters numbers and underscores . Keys in the " Resources " section can be arbitrary string . The key names ' resources ' and ' backends ' may not be used . An example for a valid config file is : . [ Resources ] queue = exec nodes = 1 threads = 1 mem = 10 If no filename is given reset all class attributes to their initial value and delete any attributes that do not exist by default . This restores the JobScript class to a pristine state .
def read_defaults(cls, filename=None):
        logger = logging.getLogger(__name__)
        def attr_setter(key, val):
            if not re.match(r'^[a-zA-Z]\w*$', key):
                raise ConfigParserError(("Key '%s' is invalid. Keys "
                "must be valid attribute names, i.e., they must match "
                "the regular expression '^[a-zA-Z]\w*$'") % key)
            val = cls._sanitize_attr(key, val)
            logger.debug("Set class attribute %s = %s",  key, val)
            setattr(cls, key, val)
        def rsrc_setter(key, val):
            logger.debug("Set class resources key %s = %s", key, val)
            cls.resources[key] = val
        if filename is None:
            known_attrs = set.union(set(cls._attributes.keys()),
                                    set(cls._protected_attributes.keys()),
                                    set(['backends', ]) )
            for attr in list(cls.__dict__.keys()):
                if ((not attr.startswith('_'))
                and (attr not in known_attrs)
                and (not callable(getattr(cls, attr)))):
                    logger.debug("Removing class attribute '%s'", attr)
                    delattr(cls, attr)
            for attr in cls._attributes:
                logger.debug("Set class attribute '%s' to original value '%s'",
                             attr, cls._attributes[attr])
                setattr(cls, attr, cls._attributes[attr])
            for attr in cls._protected_attributes:
                if attr == '_backends':
                    logger.debug("Keeping known backends: %s", list(
                            cls._protected_attributes['_backends'].keys()))
                else:
                    logger.debug("Set class attribute '%s' to original value "
                                 "'%s'", attr, cls._protected_attributes[attr])
                setattr(cls, attr, cls._protected_attributes[attr])
            cls.resources = OrderedDict()
            logger.debug("Set class attribute 'resources' to original value "
                         "OrderedDict()")
        else:
            cls._read_inifile(filename, attr_setter, rsrc_setter)
def read_defaults ( cls , filename = None ) : logger = logging . getLogger ( __name__ ) def attr_setter ( key , val ) : if not re . match ( r'^[a-zA-Z]\w*$' , key ) : raise ConfigParserError ( ( "Key '%s' is invalid. Keys " "must be valid attribute names, i.e., they must match " "the regular expression '^[a-zA-Z]\w*$'" ) % key ) val = cls . _sanitize_attr ( key , val ) logger . debug ( "Set class attribute %s = %s" , key , val ) setattr ( cls , key , val ) def rsrc_setter ( key , val ) : logger . debug ( "Set class resources key %s = %s" , key , val ) cls . resources [ key ] = val if filename is None : known_attrs = set . union ( set ( cls . _attributes . keys ( ) ) , set ( cls . _protected_attributes . keys ( ) ) , set ( [ 'backends' , ] ) ) for attr in list ( cls . __dict__ . keys ( ) ) : if ( ( not attr . startswith ( '_' ) ) and ( attr not in known_attrs ) and ( not callable ( getattr ( cls , attr ) ) ) ) : logger . debug ( "Removing class attribute '%s'" , attr ) delattr ( cls , attr ) for attr in cls . _attributes : logger . debug ( "Set class attribute '%s' to original value '%s'" , attr , cls . _attributes [ attr ] ) setattr ( cls , attr , cls . _attributes [ attr ] ) for attr in cls . _protected_attributes : if attr == '_backends' : logger . debug ( "Keeping known backends: %s" , list ( cls . _protected_attributes [ '_backends' ] . keys ( ) ) ) else : logger . debug ( "Set class attribute '%s' to original value " "'%s'" , attr , cls . _protected_attributes [ attr ] ) setattr ( cls , attr , cls . _protected_attributes [ attr ] ) cls . resources = OrderedDict ( ) logger . debug ( "Set class attribute 'resources' to original value " "OrderedDict()" ) else : cls . _read_inifile ( filename , attr_setter , rsrc_setter )
Set class attributes from the INI file with the given file name
The file must be in the format specified in
https://docs.python.org/3.5/library/configparser.html#supported-ini-file-structure
with the default ConfigParser settings, except that all keys are case
sensitive.
Set class attributes from the INI file with the given file name The file must be in the format specified in https : // docs . python . org / 3 . 5 / library / configparser . html#supported - ini - file - structure with the default ConfigParser settings except that all keys are case sensitive .
"""Set class attributes from the INI file with the given file name

        The file must be in the format specified in
        https://docs.python.org/3.5/library/configparser.html#supported-ini-file-structure
        with the default ConfigParser settings, except that all keys are case
        sensitive. It must contain exactly one or both of the sections
        "Attributes" and "Resources". The key-value pairs in the Attributes
        sections are set as class attributes, whereas the key-value pairs in
        the "Resources" section are set as keys and values in the `resources`
        class attribute.

        All keys in the "Attributes" section must be start with a letter, and
        must consist only of letters, numbers, and underscores. Keys in the
        "Resources" section can be arbitrary string. The key names 'resources'
        and 'backends' may not be used. An example for a valid config file is::

            [Attributes]
            remote = login.cluster.edu
            prologue =
                ssh {remote} 'mkdir -p {rootdir}/{workdir}'
                rsync -av {workdir}/ {remote}:{rootdir}/{workdir}
            epilogue = rsync -av {remote}:{rootdir}/{workdir}/ {workdir}
            rootdir = ~/jobs/
            # the following is a new attribute
            text = Hello World

            [Resources]
            queue = exec
            nodes = 1
            threads = 1
            mem = 10

        If no filename is given, reset all class attributes to their initial
        value, and delete any attributes that do not exist by default. This
        restores the JobScript class to a pristine state.
        """ # restore the original class attributes # For the '_backends' attribute, the setattr below sets # cls._backends to a *reference* to # cls._protected_attributes['_backends'], not a copy. As a # consequence, any call to register_backend will modify both # locations, and we don't lose registered backends when # resetting.
cls
filename