def build(self, operating_system, arch):
        runtime_path = PackageStore.get_runtimes_path()
        pathlib.Path(runtime_path).mkdir(parents=True, exist_ok=True)

        # FIXME: Put more abstraction here:
        if operating_system == "darwin":
            environment = "wine_osxcross"
            env_arch = "amd64"
        else:
            environment = "wine"
            env_arch = arch

        environment = Environment(environment, "linux", env_arch)
        environment.build()

        container = Container(environment).with_output_callback(self._output_callback)

        try:
            container.start()
            builder = RuntimeBuilder(container)
            builder.build(operating_system, arch)
            builder.archive(runtime_path + ("/runtime-%s-%s-%s.tar.gz" % (operating_system, arch, datetime.datetime.now().strftime("%Y%m%d%H%M"))))
            builder.checksum()
        finally:
            print("Cleaning container")
            container.clean()
Beispiel #2
0
    def build(self, distribution, version, operating_system, arch):
        distribution_parameters = self.fetch_distribution(distribution)

        pathlib.Path(PackageStore.get_binaries_path()).mkdir(parents=True,
                                                             exist_ok=True)
        pathlib.Path(PackageStore.get_logs_path()).mkdir(parents=True,
                                                         exist_ok=True)

        # FIXME: Put more abstraction here:
        print(distribution_parameters)
        environmentSuffix = ""
        if "environmentSuffix" in distribution_parameters:
            environmentSuffix = "_" + distribution_parameters[
                "environmentSuffix"]

        if operating_system == "darwin":
            environment = "wine_osxcross" + environmentSuffix
            env_arch = "amd64"
        else:
            environment = "wine" + environmentSuffix
            env_arch = arch

        directory = "-".join([distribution, operating_system, arch])
        filename = "-".join(
            ["PlayOnLinux", version, distribution, operating_system, arch])

        pathlib.Path(PackageStore.get_logs_path() + "/" + directory).mkdir(
            parents=True, exist_ok=True)
        pathlib.Path(PackageStore.get_binaries_path() + "/" + directory).mkdir(
            parents=True, exist_ok=True)

        environment = Environment(environment, "linux", env_arch)
        environment.build()

        container = Container(environment).with_log_file(
            PackageStore.get_logs_path() + "/" + directory + "/" + filename +
            ".log").with_output_callback(self._output_callback)

        scriptSuffix = None
        if "scriptSuffix" in distribution_parameters:
            scriptSuffix = distribution_parameters["scriptSuffix"]

        try:
            container.start()
            builder = WineBuilder(
                container, distribution_parameters["patches"],
                self.create_hooks(distribution_parameters["hooks"]),
                scriptSuffix)
            builder.build(operating_system, arch, version, distribution,
                          distribution_parameters["source"])
            builder.archive(PackageStore.get_binaries_path() + "/" +
                            directory + "/" + filename + ".tar.gz")
            builder.checksum()
        except:
            traceback.print_exc()
            raise
        finally:
            print("Cleaning container")
            container.clean()
    def load(self):
        environments = self._config()
        loaded_environments = []
        for environment in environments:
            instance = Environment(environment["name"], environment["os"],
                                   environment["arch"])
            environment["docker_name"] = instance.full_name()
            environment["state"] = instance.state()

            loaded_environments += [{
                "instance": instance,
                "environment": environment
            }]

        self.environments = loaded_environments
 def __init__(self, password, channel_enc_mode, default_shell, url,
              user_agent, cookies, custom_headers, insecure_ssl, proxy):
     reload(sys)
     sys.setdefaultencoding('utf8')
     signal.signal(signal.SIGTSTP, lambda s, f: self.do_quit())
     Cmd.__init__(self)
     if channel_enc_mode == 'aes128':
         self.password = hashlib.md5(password).hexdigest()
     else:
         self.password = hashlib.sha256(password).hexdigest()
     self.channel_enc_mode = channel_enc_mode
     self.default_shell = default_shell
     request_object = Request(url, user_agent, cookies, custom_headers,
                              insecure_ssl, proxy)
     self.env_obj = Environment(self.password, self.channel_enc_mode,
                                request_object)
     env_dict = self.env_obj.make_env(random_generator())
     if '{{{Offline}}}' in env_dict:
         self.do_quit([env_dict])
     self.online = True
     self.modules_settings = env_dict
     self.load_modules(request_object)
Beispiel #5
0
    def __init__(self):
        # Saves an instance of the Environment class.
        self.__environment = Environment()

        # Saves an instance of the FunctionMapper class.
        self.__function_mapper = FunctionMapper()

        # Loads the module containing the special functions available to the user.
        self.__function_mapper.load_class(SpecialFunctions)

        # Loads the module containing the functions available to the user.
        self.__function_mapper.load_class(Functions)

        # Loads the module containing the predicates available to the user.
        self.__function_mapper.load_class(Predicates)

        # Saves an instance of the Evaluator class, which requires as parameters
        # the references to the instances of the Environment containing the global variables
        # and of the FunctionMapper containing the mappings between the names of the functions
        # and the predicates available to the users and the corresponding implementations.
        self.__evaluator = Evaluator(self.__environment,
                                     self.__function_mapper)
Beispiel #6
0
    def __init__(self):
        # Saves an instance of the Environment class.
        self.__environment = Environment()

        # Saves an instance of the FunctionMapper class.
        self.__function_mapper = FunctionMapper()

        # Loads the module containing the special functions available to the user.
        self.__function_mapper.load_class(SpecialFunctions)

        # Loads the module containing the functions available to the user.
        self.__function_mapper.load_class(Functions)

        # Loads the module containing the predicates available to the user.
        self.__function_mapper.load_class(Predicates)

        # Saves an instance of the Evaluator class, which requires as parameters
        # the references to the instances of the Environment containing the global variables
        # and of the FunctionMapper containing the mappings between the names of the functions
        # and the predicates available to the users and the corresponding implementations.
        self.__evaluator = Evaluator(self.__environment, self.__function_mapper)
#!/usr/bin/env python

from core.Container import Container
from core.Environment import Environment
from builders.WineBuilder import WineBuilder

environment = Environment("wine_osxcross", "linux", "amd64")
environment.build()

container = Container(environment)
container.start()

builder = WineBuilder(container, [{
    "name": "appwiz-disable_mono_and_gecko_cx21",
    "operatingSystems": "darwin",
    "architectures": ["amd64"]
}, {
    "name": "winemac-allow_customization_bundle_name_cx",
    "operatingSystems": "darwin",
    "architectures": ["amd64"]
}, {
    "name": "winemac-allow_customization_hide_icon_cx",
    "operatingSystems": "darwin",
    "architectures": ["amd64"]
}, {
    "name": "winemac-exit_app_with_cmd_q_cx21",
    "operatingSystems": "darwin",
    "architectures": ["amd64"]
}, {
    "name": "loader-shape3D-name_cx21",
    "operatingSystems": "darwin",
Beispiel #8
0
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "system",
        nargs='?',
        choices=["particles", "wator"],
        help="The simulation to start. Can be particles or wator")

    args = parser.parse_args()

    config = ConfigParser()
    config.read("config.ini")

    gridSizeX = config.getint("environment", "gridSizeX")
    gridSizeY = config.getint("environment", "gridSizeY")

    environment = Environment(gridSizeX, gridSizeY,
                              config.getboolean("environment", "torus"))

    if args.system == "wator":
        environment.color = (0, 0, 255)

    grid = config.getboolean("view", "grid")
    boxSize = config.getint("view", "boxsize")

    view = View(environment, boxSize, grid)

    seed = config.getint("simulation", "seed")
    if seed != 0:
        random.seed(seed)

    scheduling = config.get("simulation", "scheduling")
    trace = config.getboolean("simulation", "trace")
from orchestrator.Orchestrator import Orchestrator
from orchestrator.EnvironmentCreationTask import EnvironmentCreationTask
from core.Environment import Environment

environment = Environment("wine_osxcross", "linux", "x86")

orchestrator = Orchestrator()
orchestrator.run_task(EnvironmentCreationTask(environment))

import time
while (len(orchestrator.tasks()) > 0):
    print(orchestrator.tasks())
    time.sleep(1)

print("Done")
class SharPyShellPrompt(Cmd):
    # overriden properties
    doc_header = "SharPyShell Commands (type help <topic>):"
    prompt = "SharPyShellPrompt> "
    identchars = Cmd.identchars + '#'

    # new properties: modules
    online = False
    modules_loaded = {}
    modules_loaded_tree = []

    helper_commands = ['cd', 'help', 'quit', 'exit']

    def __init__(self, password, channel_enc_mode, default_shell, url,
                 user_agent, cookies, custom_headers, insecure_ssl, proxy):
        reload(sys)
        sys.setdefaultencoding('utf8')
        signal.signal(signal.SIGTSTP, lambda s, f: self.do_quit())
        Cmd.__init__(self)
        if channel_enc_mode == 'aes128':
            self.password = hashlib.md5(password).hexdigest()
        else:
            self.password = hashlib.sha256(password).hexdigest()
        self.channel_enc_mode = channel_enc_mode
        self.default_shell = default_shell
        request_object = Request(url, user_agent, cookies, custom_headers,
                                 insecure_ssl, proxy)
        self.env_obj = Environment(self.password, self.channel_enc_mode,
                                   request_object)
        env_dict = self.env_obj.make_env(random_generator())
        if '{{{Offline}}}' in env_dict:
            self.do_quit([env_dict])
        self.online = True
        self.modules_settings = env_dict
        self.load_modules(request_object)

    def load_modules(self, request_object):
        modules_paths = glob.glob(config.modules_paths + '[a-z]*py')
        for module_path in modules_paths:
            module_filename = module_path.split(os.sep)[-1:]
            module_name = os.path.splitext(''.join(module_filename))[0]
            classname = module_name.capitalize()
            module = __import__('modules.%s' % module_name, fromlist=["*"])
            # load all run classes and pass arguments to init method
            module_class = getattr(module, classname)(self.password,
                                                      self.channel_enc_mode,
                                                      self.modules_settings,
                                                      request_object)
            self.modules_loaded[module_name] = module_class
            self.modules_loaded_tree.append(module_name)
            setattr(SharPyShellPrompt, 'do_%s' % module_name, module_class.run)

    def precmd(self, line):
        if '"' in line:
            line = line.replace('"', '""')
        return line

    def onecmd(self, line):
        cmd, args, line = self.parseline(line)
        if not line:
            return self.emptyline()
        if cmd is None:
            return self.emptyline()
        if line == 'EOF':
            raise EOFError()
        if cmd == '':
            return self.emptyline()
        if cmd.startswith('#'):
            response = self.onecmd_custom(cmd.lstrip('#'), args)
            print response
            return response
        if cmd in self.helper_commands:
            func = getattr(self, 'do_' + cmd.lstrip('#'))
            return func(args)
        return self.default(line)

    def onecmd_custom(self, cmd, args):
        if cmd in self.modules_loaded_tree:
            shlex_obj = shlex.shlex(args, posix=False)
            shlex_obj.quotes = '\''
            shlex_obj.whitespace_split = True
            shlex_obj.commenters = ''
            args = list(shlex_obj)
            args = normalize_args(args)
            parsed_response = self.modules_loaded[cmd].run(args)
        else:
            parsed_response = '"#' + cmd + '" Module not found.'
        return parsed_response

    def postcmd(self, stop, line):
        working_directory = self.modules_settings['working_directory']
        if working_directory.endswith(
                '\\') and not working_directory.endswith(':\\'):
            self.modules_settings[
                'working_directory'] = working_directory.rstrip('\\')
        if self.default_shell == 'exec_cmd':
            self.prompt = self.modules_settings['working_directory'] + '> '
        else:
            self.prompt = 'PS ' + self.modules_settings[
                'working_directory'] + '> '

    def do_cd(self, arg):
        """Change the current working directory."""
        working_directory = self.modules_settings['working_directory']
        if arg == "" or arg == " " or arg == '.':
            print working_directory
            return
        if arg == '..':
            arg = working_directory.split('\\')
            for i in range(0, len(arg)):
                if arg[i] == '':
                    del arg[i]
            del arg[len(arg) - 1]
            if len(arg) == 1:
                arg[0] = arg[0].replace(':', ':\\')
                arg = ''.join(arg)
            elif len(arg) > 0:
                arg = '\\'.join(arg)
            else:
                print "Empty Path."
                return
        else:
            if '/' in arg:
                arg = arg.replace('/', '\\')
            if arg.endswith(':'):
                arg = arg + '\\'
            elif ':' not in arg:
                if working_directory.endswith('\\'):
                    arg = working_directory + arg
                else:
                    arg = working_directory + '\\' + arg
        response = self.modules_loaded['exec_cmd'].run(['dir ""' + arg + '""'])
        if '{{{SharPyShellError}}}' not in response:
            self.modules_settings['working_directory'] = arg
        else:
            print response
        return response

    def do_help(self, arg):
        """List available commands."""
        if arg and arg.lstrip('#') in self.modules_loaded_tree:
            print self.modules_loaded[arg.lstrip('#')].complete_help
        else:
            print "\n\n" + self.doc_header + "\n"
            data = [['\nCommands\n', '\nDesc\n']]
            for module_name in sorted(self.modules_loaded_tree):
                data.append([
                    '#%s' % module_name,
                    self.modules_loaded[module_name].short_help
                ])
            print prettify.tablify(data, table_border=False)
            print
            print "\n" + "SharPyShell Helper Commands:" + "\n"
            data = [['\nCommands\n', '\nDesc\n']]
            for module_name in sorted(self.helper_commands):
                data.append([
                    '%s' % module_name,
                    getattr(self, 'do_' + module_name).__doc__
                ])
            print prettify.tablify(data, table_border=False)
            print

    def complete_help(self, text, line, start_index, end_index):
        out = [
            '#' + module for module in self.modules_loaded_tree
            if module not in self.helper_commands
        ]
        if text:
            return [module for module in out if module.startswith(text)]
        else:
            return out

    def completenames(self, text, *ignored):
        out = [
            '#' + module for module in self.modules_loaded_tree
            if module not in self.helper_commands and ('#' +
                                                       module).startswith(text)
        ]
        return out

    def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            old_delims = readline.get_completer_delims()
            readline.set_completer_delims(old_delims.replace('#', ''))
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx > 0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None

    def default(self, line):
        """Default command line send."""
        if not line:
            return
        result = self.modules_loaded[self.default_shell].run([line])
        if not result:
            return
        # Clean trailing newline if existent to prettify output
        result = result[:-1] if (isinstance(result, basestring)
                                 and result.endswith('\n')) else result
        print result

    def cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.

        """
        # Custom change: added hadling for ctrl+c
        self.preloop()
        if self.use_rawinput and self.completekey:
            try:
                import readline
                self.old_completer = readline.get_completer()
                readline.set_completer(self.complete)
                readline.parse_and_bind(self.completekey + ": complete")
            except ImportError:
                pass
        try:
            if intro is not None:
                self.intro = intro
            if self.intro:
                self.stdout.write(str(self.intro) + "\n")
            stop = None
            while not stop:
                try:
                    if self.cmdqueue:
                        line = self.cmdqueue.pop(0)
                    else:
                        if self.use_rawinput:
                            try:
                                line = raw_input(self.prompt)
                            except EOFError:
                                line = 'EOF'
                        else:
                            self.stdout.write(self.prompt)
                            self.stdout.flush()
                            line = self.stdin.readline()
                            if not len(line):
                                line = 'EOF'
                            else:
                                line = line.rstrip('\r\n')
                    line = self.precmd(line)
                    stop = self.onecmd(line)
                    stop = self.postcmd(stop, line)
                except KeyboardInterrupt:
                    print("^C")
            self.postloop()
        finally:
            if self.use_rawinput and self.completekey:
                try:
                    import readline
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass

    def do_quit(self, args=[]):
        """Quit the program."""
        if self.online:
            print "\n\nQuitting...\n"
            print self.env_obj.clear_env(self.modules_settings)
        else:
            print args[0] + "\n\n\nTarget Offline...\n"
        raise SystemExit

    def do_exit(self, args=[]):
        """Exit the program."""
        self.do_quit()
Beispiel #11
0
class Builder(object):
    """
    Class for the building of the working memory and
    the production memory after the parsing and
    the preliminary evaluation of a sequence
    of facts and rules.
    """
    def __init__(self):
        # Saves an instance of the Environment class.
        self.__environment = Environment()

        # Saves an instance of the FunctionMapper class.
        self.__function_mapper = FunctionMapper()

        # Loads the module containing the special functions available to the user.
        self.__function_mapper.load_class(SpecialFunctions)

        # Loads the module containing the functions available to the user.
        self.__function_mapper.load_class(Functions)

        # Loads the module containing the predicates available to the user.
        self.__function_mapper.load_class(Predicates)

        # Saves an instance of the Evaluator class, which requires as parameters
        # the references to the instances of the Environment containing the global variables
        # and of the FunctionMapper containing the mappings between the names of the functions
        # and the predicates available to the users and the corresponding implementations.
        self.__evaluator = Evaluator(self.__environment,
                                     self.__function_mapper)

    @property
    def evaluator(self):
        return self.__evaluator

    @evaluator.setter
    def evaluator(self, value):
        self.__evaluator = value

    def build(self, AST):
        # Saves a list to contain the facts.
        facts = []

        # Memorizza a list to contain the rules.
        rules = []

        for (item_type, item_content) in AST:
            # If the construct corresponds to the definition of a global variable, then
            # it is evaluated and the result is added in the set of global variables.
            if item_type == 'DEFGLOBAL_CONSTRUCT':
                for assignment in item_content:
                    print 'Defining defglobal:', assignment.name
                    assignment.content = self.__evaluator.evaluate(
                        assignment.content)
                    self.__environment.set_global_variable(assignment)

            # If the construct corresponds to the definition of a list of facts, then
            # the attributes of each fact are evaluated and the fact is added to the list of facts.
            elif item_type == 'DEFFACTS_CONSTRUCT':
                print 'Defining deffacts:', item_content[0]
                for fact in item_content[1:]:
                    for i in xrange(len(fact[1])):
                        # Evaluates each attribute of the considered fact.
                        fact[1][i] = self.__evaluator.evaluate(fact[1][i])

                    # Saves an instance of the considered fact
                    # specifying its name and its attributes.
                    f = OrderedFact(fact[0], fact[1])

                    # Adds the current fact to the list of facts.
                    facts.append(f)

            # If the construct corresponds to the definition of a rule, then
            # its left and right parts are preliminarly evaluated and the rule
            # is added to the list of rules. Possible non global variables
            # will be evaluated after the matching phase between facts and rules.
            elif item_type == 'DEFRULE_CONSTRUCT':
                name = item_content[0][0]
                print 'Defining defrule:', name

                # Saves an instance of the considered rule.
                r = Rule(name)

                # If the rule contains a value of the salience,
                # then it is saved in the instance of the rule.
                if len(item_content[0]) > 1:
                    if item_content[0][1][0] is 'salience':
                        r.salience = item_content[0][1][1].content

                # Saves the left part in the instance of the rule.
                lhs = item_content[1]

                # Evaluates each element of the left part of the rule.
                for i in xrange(len(lhs)):

                    # Checks if the element of the left part of the rule represents a test.
                    if isinstance(lhs[i][0], SpecialTestCallType):

                        # Builds the set of the variables contained in the test.
                        lhs[i][0].build()

                        # Builds, in the rule containing the test, a dictionary in the form:
                        # variable_involved_in_the_test : list_of_references_to_tests_which_contains_it.
                        for v in lhs[i][0].test_variables:
                            if not v in r.variable_tests:
                                r.variable_tests[v] = set([lhs[i][0]])
                            else:
                                r.variable_tests[v].add(lhs[i][0])

                        # Adds the test to instance of the rule.
                        r.tests.add(lhs[i][0])

                    else:
                        # If the current element of the left part
                        # of the rule is not a test, then it is evaluated.
                        lhs[i] = self.__evaluator.evaluate(lhs[i])

                        # Adds the current element to the left part of the instance of the rule.
                        r.lhs.append(lhs[i])

                # Evaluates the complexity of the rule.
                r.evaluate_complexity()

                # Saves the right part in the instance of the rule.
                r.rhs = item_content[2]

                # Adds the rule to the list of rules.
                rules.append(r)

        # Returns the lists of identified facts and rules.
        return (facts, rules)

    def build_assert(self, ast):
        facts = []

        for fact in ast[1:]:
            print 'Defining fact:', fact[0]

            for i in xrange(len(fact[1])):
                # Evaluates each attribute of the considered fact.
                fact[1][i] = self.__evaluator.evaluate(fact[1][i])

            # Saves an instance of the considered fact
            # specifying its name and its attributes.
            f = OrderedFact(fact[0], fact[1])

            # Adds the considered fact to the Working Memory.
            facts.append(f)

        return facts

    def reset(self):
        self.__environment.clear_local_variables()
        self.__environment.clear_test_variables()
        self.__evaluator = Evaluator(self.__environment,
                                     self.__function_mapper)
Beispiel #12
0
if args.environment is None:
    fatal(
        "You need to provide a valid environment (ex: --environment=wine_osxcross/linux/amd64)"
    )

wine_source = args.wine_src if args.wine_src is not None else os.getcwd()
patches = [{
    "name": patch,
    "operatingSystems": args.os,
    "architecture": args.architecture
} for patch in args.apply_patches] if args.apply_patches is not None else None

try:
    environment = args.environment.split("/")
    build_environment = Environment(environment[0], environment[1],
                                    environment[2])
    info("Building environment...")
    build_environment.build()
    container = Container(build_environment)
    container.with_mount({
        "src": wine_source,
        "dest": "/root/wine-git",
        "mode": "rw"
    })
    container.start()

    builder = WineBuilder(container, patches)

    if patches is not None:
        builder.prepare(args.os,
                        args.architecture,
#!/usr/bin/env python
from builders.RuntimeBuilder import RuntimeBuilder
from core.Container import Container
from core.Environment import Environment

environment = Environment("wine", "linux", "x86")
environment.build()

container = Container(environment)
container.start()

builder = RuntimeBuilder(container)
builder.build("linux", "x86")
builder.archive("runtime.tar.gz")

container.clean()
Beispiel #14
0
class Builder(object):
    """
    Class for the building of the working memory and
    the production memory after the parsing and
    the preliminary evaluation of a sequence
    of facts and rules.
    """
    def __init__(self):
        # Saves an instance of the Environment class.
        self.__environment = Environment()

        # Saves an instance of the FunctionMapper class.
        self.__function_mapper = FunctionMapper()

        # Loads the module containing the special functions available to the user.
        self.__function_mapper.load_class(SpecialFunctions)

        # Loads the module containing the functions available to the user.
        self.__function_mapper.load_class(Functions)

        # Loads the module containing the predicates available to the user.
        self.__function_mapper.load_class(Predicates)

        # Saves an instance of the Evaluator class, which requires as parameters
        # the references to the instances of the Environment containing the global variables
        # and of the FunctionMapper containing the mappings between the names of the functions
        # and the predicates available to the users and the corresponding implementations.
        self.__evaluator = Evaluator(self.__environment, self.__function_mapper)

    @property
    def evaluator(self):
        return self.__evaluator

    @evaluator.setter
    def evaluator(self, value):
        self.__evaluator = value

    def build(self, AST):
        # Saves a list to contain the facts.
        facts = []

        # Memorizza a list to contain the rules.
        rules = []

        for (item_type, item_content) in AST:
            # If the construct corresponds to the definition of a global variable, then
            # it is evaluated and the result is added in the set of global variables.
            if item_type == 'DEFGLOBAL_CONSTRUCT':
                for assignment in item_content:
                    print 'Defining defglobal:', assignment.name
                    assignment.content = self.__evaluator.evaluate(assignment.content)
                    self.__environment.set_global_variable(assignment)

            # If the construct corresponds to the definition of a list of facts, then
            # the attributes of each fact are evaluated and the fact is added to the list of facts.
            elif item_type == 'DEFFACTS_CONSTRUCT':
                print 'Defining deffacts:', item_content[0]
                for fact in item_content[1:]:
                    for i in xrange(len(fact[1])):
                        # Evaluates each attribute of the considered fact.
                        fact[1][i] = self.__evaluator.evaluate(fact[1][i])

                    # Saves an instance of the considered fact
                    # specifying its name and its attributes.
                    f = OrderedFact(fact[0], fact[1])

                    # Adds the current fact to the list of facts.
                    facts.append(f)

            # If the construct corresponds to the definition of a rule, then
            # its left and right parts are preliminarly evaluated and the rule
            # is added to the list of rules. Possible non global variables
            # will be evaluated after the matching phase between facts and rules.
            elif item_type == 'DEFRULE_CONSTRUCT':
                name = item_content[0][0]
                print 'Defining defrule:', name

                # Saves an instance of the considered rule.
                r = Rule(name)

                # If the rule contains a value of the salience,
                # then it is saved in the instance of the rule.
                if len(item_content[0]) > 1:
                    if item_content[0][1][0] is 'salience':
                        r.salience = item_content[0][1][1].content

                # Saves the left part in the instance of the rule.
                lhs = item_content[1]

                # Evaluates each element of the left part of the rule.
                for i in xrange(len(lhs)):

                    # Checks if the element of the left part of the rule represents a test.
                    if isinstance(lhs[i][0], SpecialTestCallType):

                        # Builds the set of the variables contained in the test.
                        lhs[i][0].build()

                        # Builds, in the rule containing the test, a dictionary in the form:
                        # variable_involved_in_the_test : list_of_references_to_tests_which_contains_it.
                        for v in lhs[i][0].test_variables:
                            if not v in r.variable_tests:
                                r.variable_tests[v] = set([lhs[i][0]])
                            else:
                                r.variable_tests[v].add(lhs[i][0])

                        # Adds the test to instance of the rule.
                        r.tests.add(lhs[i][0])

                    else:
                        # If the current element of the left part
                        # of the rule is not a test, then it is evaluated.
                        lhs[i] = self.__evaluator.evaluate(lhs[i])

                        # Adds the current element to the left part of the instance of the rule.
                        r.lhs.append(lhs[i])

                # Evaluates the complexity of the rule.
                r.evaluate_complexity()

                # Saves the right part in the instance of the rule.
                r.rhs = item_content[2]

                # Adds the rule to the list of rules.
                rules.append(r)

        # Returns the lists of identified facts and rules.
        return (facts, rules)

    def build_assert(self, ast):
        facts = []

        for fact in ast[1:]:
            print 'Defining fact:', fact[0]

            for i in xrange(len(fact[1])):
                # Evaluates each attribute of the considered fact.
                fact[1][i] = self.__evaluator.evaluate(fact[1][i])

            # Saves an instance of the considered fact
            # specifying its name and its attributes.
            f = OrderedFact(fact[0], fact[1])

            # Adds the considered fact to the Working Memory.
            facts.append(f)

        return facts

    def reset(self):
        self.__environment.clear_local_variables()
        self.__environment.clear_test_variables()
        self.__evaluator = Evaluator(self.__environment, self.__function_mapper)