#!/usr/bin/env python
# encoding: utf-8
'''
ProgramConfiguration -- Configuration of a target program

Container class that stores various configuration parameters, like platform,
product, OS, version and other parameters relevant for reproducing the issue.

@author:     Christian Holler (:decoder)

@license:

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

@contact:    choller@mozilla.com
'''

# Ensure print() compatibility with Python 3
from __future__ import print_function

class ProgramConfiguration():
    def __init__(self, product, platform, os, version=None, env=None, args=None):
        '''
        @type product: string
        @param product: The name of the product/program/branch tested
        @type platform: string
        @param platform: Platform on which is tested (e.g. x86, x86-64 or arm)
        @type os: string
        @param os: Operating system on which is tested (e.g. linux, windows, macosx)
        '''
        self.product = product.lower()
        self.platform = platform.lower()
        self.os = os.lower()
        self.version = version
        
        if env is None:
            env = {}
        
        if args is None:
            args = []
        
        assert isinstance(env, dict)
        assert isinstance(args, list)
        
        self.env = env
        self.args = args
@@ -619,16 +619,91 @@
 function
+%0Aimport sys%0Aimport os%0Afrom FTB.ConfigurationFiles import ConfigurationFiles
 %0A%0Aclass 
@@ -805,16 +805,31 @@
 rgs=None
+, metadata=None
 ):%0A     
@@ -1417,16 +1417,84 @@
 gs = %5B%5D%0A
+            %0A        if metadata is None:%0A            metadata = %7B%7D%0A
         
@@ -1569,16 +1569,58 @@
 , list)%0A
+        assert isinstance(metadata, dict)%0A
         
@@ -1663,12 +1663,2019 @@
 .args = args
+%0A        self.metadata = metadata%0A    %0A    @staticmethod%0A    def fromBinary(binaryPath):%0A        binaryConfig = %22%25s.fuzzmanagerconf%22 %25 binaryPath%0A        if not os.path.exists(binaryConfig):%0A            print(%22Warning: No binary configuration found at %25s%22 %25 binaryConfig, file=sys.stderr)%0A            return None%0A%0A        config = ConfigurationFiles(%5B binaryConfig %5D)%0A        mainConfig = config.mainConfig%0A        %0A        for field in %5B%22product%22, %22platform%22, %22os%22%5D:%0A            if not field in mainConfig:%0A                raise RuntimeError('Missing %22%25s%22 in binary configuration file %25s' %25 (field, binaryConfig))%0A            %0A        # Version field is optional%0A        version = None%0A        if %22product_version%22 in mainConfig:%0A            version = mainConfig%5B%22product_version%22%5D%0A        %0A        return ProgramConfiguration(mainConfig%5B%22product%22%5D, mainConfig%5B%22platform%22%5D, mainConfig%5B%22os%22%5D, version=version, metadata=config.metadataConfig)%0A    %0A    def addEnvironmentVariables(self, env):%0A        '''%0A        Add (additional) environment variable definitions. Existing definitions%0A        will be overwritten if they are redefined in the given environment.%0A        %0A        @type env: dict%0A        @param env: Dictionary containing the environment variables%0A        '''%0A        assert isinstance(env, dict)%0A        self.env.update(env)%0A        %0A    def addProgramArguments(self, args):%0A        '''%0A        Add (additional) program arguments.%0A        %0A        @type args: list%0A        @param args: List containing the program arguments%0A        '''%0A        assert isinstance(args, list)%0A        self.args.extend(args)%0A        %0A    def addMetadata(self, metadata):%0A        '''%0A        Add (additional) metadata definitions. Existing definitions%0A        will be overwritten if they are redefined in the given metadata.%0A        %0A        @type metadata: dict%0A        @param metadata: Dictionary containing the metadata%0A        '''%0A        assert isinstance(metadata, dict)%0A        self.metadata.update(metadata)

Add a method to handle binary configuration files (#62)