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_current_jobtype(self):
        """Test current_jobtype"""

        _cfg = configparser.RawConfigParser()
        cfg = mock.create_autospec(Configuration)
        cfg._log = logging.getLogger("jobtype")
        cfg._config = _cfg
        cfg.jobtype = "TestApp"

        app = Configuration.current_jobtype(cfg)
        self.assertEqual(app, cfg.jobtype)

        _cfg.add_section('TestApp2')
        with self.assertRaises(InvalidConfigException):
            Configuration.current_jobtype(cfg, 'DifferentApp')

        app = Configuration.current_jobtype(cfg, "TestApp2")
        self.assertEqual(app, 'TestApp2')
        self.assertEqual(cfg.jobtype, 'TestApp2')
        self.assertEqual(cfg.job_type, 'TestApp2')
    def test_config_current_jobtype(self):
        """Test current_jobtype"""

        _cfg = configparser.RawConfigParser()
        cfg = mock.create_autospec(Configuration)
        cfg._log = logging.getLogger("jobtype")
        cfg._config = _cfg
        cfg.jobtype = "TestApp"

        app = Configuration.current_jobtype(cfg)
        self.assertEqual(app, cfg.jobtype)

        _cfg.add_section('TestApp2')
        with self.assertRaises(InvalidConfigException):
            Configuration.current_jobtype(cfg, 'DifferentApp')

        app = Configuration.current_jobtype(cfg, "TestApp2")
        self.assertEqual(app, 'TestApp2')
        self.assertEqual(cfg.jobtype, 'TestApp2')
        self.assertEqual(cfg.job_type, 'TestApp2')
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