Пример #1
0
    def process_init(self):
        self.event_queue = Queue(1000)
        self.event_queue_name = str(id(self))
        PmakeManager.queues[self.event_queue_name] = self.event_queue

        # info('Starting %d processes' % self.num_processes)

        self.subs = {}  # name -> sub
        # available + processing + aborted = subs.keys
        self.sub_available = set()
        self.sub_processing = set()
        self.sub_aborted = set()

        db = self.context.get_compmake_db()
        storage = db.basepath  # XXX:
        logs = os.path.join(storage, 'logs')

        #self.signal_queue = Queue()

        for i in range(self.num_processes):
            name = 'parmake_sub_%02d' % i
            write_log = os.path.join(logs, '%s.log' % name)
            make_sure_dir_exists(write_log)
            signal_token = name

            self.subs[name] = PmakeSub(name=name,
                                       signal_queue=None,
                                       signal_token=signal_token,
                                       write_log=write_log)
        self.job2subname = {}
        # all are available
        self.sub_available.update(self.subs)

        self.max_num_processing = self.num_processes
Пример #2
0
    def process_init(self):
        self.event_queue = Queue(1000)
        self.event_queue_name = str(id(self))
        PmakeManager.queues[self.event_queue_name] = self.event_queue

        # info('Starting %d processes' % self.num_processes)

        self.subs = {}  # name -> sub
        # available + processing + aborted = subs.keys
        self.sub_available = set()
        self.sub_processing = set()
        self.sub_aborted = set()

        db = self.context.get_compmake_db()
        storage = db.basepath  # XXX:
        logs = os.path.join(storage, 'logs')
        
        #self.signal_queue = Queue()
        
        for i in range(self.num_processes):
            name = 'parmake_sub_%02d' % i
            write_log = os.path.join(logs, '%s.log' % name)
            make_sure_dir_exists(write_log)
            signal_token = name
            
            self.subs[name] = PmakeSub(name=name, 
                                       signal_queue=None, 
                                       signal_token=signal_token, 
                                       write_log=write_log)
        self.job2subname = {}
        # all are available
        self.sub_available.update(self.subs)

        self.max_num_processing = self.num_processes
Пример #3
0
def open_for_write(fout):
    if fout == '/dev/stdout':
        return open('/dev/stdout', 'wb', buffering=0)
    else:
        wants_fifo = fout.startswith('fifo:')
        fout = fout.replace('fifo:', '')

        logger_interaction.info(
            f'Opening output file {fout} (wants fifo: {wants_fifo})')

        if not os.path.exists(fout):

            if wants_fifo:
                make_sure_dir_exists(fout)
                os.mkfifo(fout)
                logger_interaction.info('Fifo created.')
        else:
            is_fifo = stat.S_ISFIFO(os.stat(fout).st_mode)
            if wants_fifo and not is_fifo:
                logger_interaction.info(f'Recreating {fout} as a fifo.')
                os.unlink(fout)
                os.mkfifo(fout)

        if wants_fifo:
            logger_interaction.info(
                'Fifo detected. Opening will block until a reader appears.')

        make_sure_dir_exists(fout)
        fo = open(fout, 'wb', buffering=0)

        if wants_fifo:
            logger_interaction.info('Reader has connected to my fifo')

        return fo
Пример #4
0
def write_data_to_file(data, filename, quiet=False):
    """
        Writes the data to the given filename.
        If the data did not change, the file is not touched.

    """
    from mcdp import logger

    if not isinstance(data, str):
        msg = 'Expected "data" to be a string, not %s.' % type(data).__name__
        raise ValueError(msg)

    if len(filename) > 256:
        msg = 'Invalid argument filename: too long. Did you confuse it with data?'
        raise ValueError(msg)

    filename = expand_all(filename)
    make_sure_dir_exists(filename)

    if os.path.exists(filename):
        current = open(filename).read()
        if current == data:
            if not 'assets' in filename:
                if not quiet:
                    logger.debug('already up to date %s' %
                                 friendly_path(filename))
            return

    with open(filename, 'w') as f:
        f.write(data)

    if not quiet:
        size = '%.1fMB' % (len(data) / (1024 * 1024))
        logger.debug('Written %s to: %s' % (size, friendly_path(filename)))
Пример #5
0
def assert_seq(s: Union[str, Language], seq: List[Event], expect: Sequence[type], final: type):
    if isinstance(s, str):
        s = s.replace('\n', ' ').strip()
        while '  ' in s:
            s = s.replace('  ', ' ')
        l = parse_language(s)
    else:
        l = s

    s2 = language_to_str(l)
    print(s)
    print(s2)
    l2 = parse_language(s2)
    assert l == l2, (s, s2)

    pc = LanguageChecker(l)
    logger.info(f'Active start: {pc.get_active_states_names()}')

    dn = get_comptests_output_dir()
    fn = os.path.join(dn, 'language.dot')
    make_sure_dir_exists(fn)
    write_dot(pc.g, fn)
    logger.info(f'Written to {fn}')

    # all except last
    for i, (e, r) in enumerate(zip(seq, expect)):
        logger.info(f'Active before: {pc.get_active_states_names()}')
        logger.info(f'Event {e}')
        res = pc.push(e)
        logger.info(f'Active after: {pc.get_active_states_names()}')
        if not isinstance(res, r):
            msg = f'Input {i} ({e}) response was {type(res).__name__} instead of {r.__name__}'
            msg += f'\n entire sequence: {seq}'
            msg += f'\n language: {l}'
            msg += f'\n language string: {s2}'
            raise Exception(msg)

    res = pc.finish()
    if not isinstance(res, final):
        msg = f'finish response was {type(res).__name__} instead of {final.__name__}'
        msg += f'\n entire sequence: {seq}'
        msg += f'\n language: {l}'
        msg += f'\n language string: {s2}'
        raise Exception(msg)