def generate_config():
    """
    Uses a current configuration if possible otherwise creates a new
    configuration for the specified job type.

    :Returns:
        - An instance of the :class:`batchapps.Configuration`.
    """

    try:
        cfg = Configuration(log_level="info", job_type="ImageMagick")
        print("Existing config found.")
        return cfg

    except InvalidConfigException as exp:
        print("Invalid Configuration: {0}\n" "Attempting to create new config.".format(exp))

    try:
        cfg = Configuration(log_level="info")

        cfg.aad_config(account=ACCOUNT_ID, key=ACCOUNT_KEY, ENDPOINT=endpoint, unattended=True)

        cfg.add_jobtype("ImageMagick")
        cfg.current_jobtype("ImageMagick")
        cfg.set("width", "500")
        cfg.set("height", "500")
        cfg.set_default_jobtype()

    except InvalidConfigException as exp:
        raise RuntimeError("Invalid Configuration: {0}".format(exp))

    finally:
        cfg.save_config()
        return cfg
def create_config():
    """
    Looks for configuration settings for specified application, otherwise
    creates new configuration, sets chosen log_level.
    
    :Returns:
        - a :class:`.Configuration` instance object
    """

    global LOG_LEVEL

    if input("Run in debug mode? (yes/no)")[0].lower() == 'n':
        LOG_LEVEL = "info"

    try:
        # Look for application in existing config file
        config = Configuration(log_level=LOG_LEVEL, jobtype="MyApp")
        print("Config found.")
        return config

    except InvalidConfigException:
        print("Valid config not found. Attempting to create new config.")

    try:  
        config = Configuration(log_level=LOG_LEVEL)
        config.aad_config(endpoint=ENDPOINT,
                          account=ACCOUNT_ID,
                          key=ACCOUNT_KEY,
                          unattended=True)

        config.add_jobtype("MyApp")
        config.current_jobtype("MyApp")
        
        # Examples of default config settings for your job
        config.set("width", "500")
        config.set("height", "500")

        # Set MyApp to be the default job type
        config.set_default_jobtype()

    except InvalidConfigException as e:
         raise RuntimeError("Invalid Configuration: {0}".format(e))

    finally:
        config.save_config()
        return config
def create_config():
    """
    Looks for configuration settings for specified application, otherwise
    creates new configuration, sets chosen log_level.
    
    :Returns:
        - a :class:`.Configuration` instance object
    """

    global LOG_LEVEL

    if input("Run in debug mode? (yes/no)")[0].lower() == 'n':
        LOG_LEVEL = "info"

    try:
        # Look for application in existing config file
        config = Configuration(log_level=LOG_LEVEL, jobtype="MyApp")
        print("Config found.")
        return config

    except InvalidConfigException:
        print("Valid config not found. Attempting to create new config.")

    try:
        config = Configuration(log_level=LOG_LEVEL)
        config.aad_config(endpoint=ENDPOINT,
                          account=ACCOUNT_ID,
                          key=ACCOUNT_KEY,
                          unattended=True)

        config.add_jobtype("MyApp")
        config.current_jobtype("MyApp")

        # Examples of default config settings for your job
        config.set("width", "500")
        config.set("height", "500")

        # Set MyApp to be the default job type
        config.set_default_jobtype()

    except InvalidConfigException as e:
        raise RuntimeError("Invalid Configuration: {0}".format(e))

    finally:
        config.save_config()
        return config
Exemplo n.º 4
0
    def test_config_set_default_jobtype(self, mock_save):
        """Test set_default_jobtype"""

        if not self.use_test_files:
            self.skipTest("No test files present")

        _cfg = configparser.RawConfigParser()
        _cfg.read(os.path.join(self.test_dir, "batch_apps.ini"))
        cfg = mock.create_autospec(Configuration)
        cfg._config = _cfg
        cfg.jobtype = "Test"
        cfg._write_file = True
        cfg._log = logging.getLogger("set_default_jobtype")

        Configuration.set_default_jobtype(cfg)
        self.assertFalse(cfg._config.has_option('Blender', 'default_jobtype'))
        self.assertTrue(cfg._config.has_option('Test', 'default_jobtype'))

        cfg.jobtype = "Test"
        Configuration.set_default_jobtype(cfg)
        self.assertFalse(cfg._config.has_option('Blender', 'default_jobtype'))
        self.assertTrue(cfg._config.has_option('Test', 'default_jobtype'))
    def test_config_set_default_jobtype(self, mock_save):
        """Test set_default_jobtype"""

        if not self.use_test_files:
            self.skipTest("No test files present")
      
        _cfg = configparser.RawConfigParser()
        _cfg.read(os.path.join(self.test_dir, "batch_apps.ini"))
        cfg = mock.create_autospec(Configuration)
        cfg._config = _cfg
        cfg.jobtype = "Test"
        cfg._write_file = True
        cfg._log = logging.getLogger("set_default_jobtype")

        Configuration.set_default_jobtype(cfg)
        self.assertFalse(cfg._config.has_option('Blender', 'default_jobtype'))
        self.assertTrue(cfg._config.has_option('Test', 'default_jobtype'))

        cfg.jobtype = "Test"
        Configuration.set_default_jobtype(cfg)
        self.assertFalse(cfg._config.has_option('Blender', 'default_jobtype'))
        self.assertTrue(cfg._config.has_option('Test', 'default_jobtype'))
def generate_config():
    """
    Uses a current configuration if possible otherwise creates a new
    configuration for the specified job type.

    :Returns:
        - An instance of the :class:`batchapps.Configuration`.
    """

    try:
        cfg = Configuration(log_level="info", job_type="ImageMagick")
        print("Existing config found.")
        return cfg

    except InvalidConfigException as exp:
        print("Invalid Configuration: {0}\n"
              "Attempting to create new config.".format(exp))

    try:
        cfg = Configuration(log_level="info")

        cfg.aad_config(account=ACCOUNT_ID,
                       key=ACCOUNT_KEY,
                       ENDPOINT=endpoint,
                       unattended=True)

        cfg.add_jobtype("ImageMagick")
        cfg.current_jobtype("ImageMagick")
        cfg.set("width", "500")
        cfg.set("height", "500")
        cfg.set_default_jobtype()

    except InvalidConfigException as exp:
        raise RuntimeError("Invalid Configuration: {0}".format(exp))

    finally:
        cfg.save_config()
        return cfg