Exemplo n.º 1
0
def doc_search():
    content = request.json

    arg_specs = client.run('sys.argspec', client='local',
        tgt=content['tgt'].strip(), expr_form=content['expr_form'],
        args=Call(content['fun'].strip()))

    if not arg_specs:
        return jsonify({'error': 'No matching minions found'}), 400

    # Take only first result
    arg_specs = arg_specs.values()[0]

    module_function_names = arg_specs.keys()

    docs = client.run('sys.doc', client='local', tgt=content['tgt'].strip(),
        expr_form=content['expr_form'], args=Call(*module_function_names))

    # Take only first result
    docs = docs.values()[0]

    result = {}

    for module_function_name in module_function_names:
        result[module_function_name] = {
            'spec': parse_argspec(arg_specs[module_function_name]),
            'doc': docs[module_function_name]}

    return jsonify(result)
Exemplo n.º 2
0
def _Clean(config, stream):
    if config.tool == 'cmake':
        command = 'cmake --build . --target ALL_BUILD '
        command += _cmake_config_options(config) + ' /t:clean'
        Call(command, config.directory, stream)
    if config.tool == 'node-gyp':
        command = 'node-gyp clean'
        #command += ' --directory=%s'%config.location
        if config.__global__.debug:
            command += ' options=--debug'
        Call(command, config.location, stream)
    else:
        raise Exception('unspport test for tool :%s' % config.tool)
Exemplo n.º 3
0
def minions_do_check_sync(minion):
    jid = client.run('state.highstate',
                     client="local_async",
                     tgt=minion,
                     args=Call(test=True))['jid']
    return redirect(
        url_for('job_result', minion=minion, jid=jid, renderer='highstate'))
Exemplo n.º 4
0
def find_fixed_lines_calls(calls):
    total_fixed_line_calls = 0
    for call in calls:
        call = Call(call)
        if is_bangalore_num(call.incoming) and is_bangalore_num(
                call.answering):
            total_fixed_line_calls += 1
    return total_fixed_line_calls
Exemplo n.º 5
0
def _Install(config, stream):

    if config.tool == 'cmake':
        command = 'cmake --build . --target INSTALL '
        command += _cmake_config_options(config)
        Call(command, config.directory, stream)
    else:
        raise Exception('unspport install for tool :%s' % config.tool)
Exemplo n.º 6
0
def _Test(config, stream):

    if config.tool == 'cmake':
        command = 'cmake --build . --target RUN_TESTS '
        command += _cmake_config_options(config)
        Call(command, config.directory, stream)
    else:
        raise Exception('unspport test for tool :%s' % config.tool)
Exemplo n.º 7
0
    def test_find(self):
        args = ['arg1', 'arg2', 'arg3']
        kwargs = {'kwarg1': '', 'kwarg2': '', 'kwarg3': ''}
        with patch.object(UserDocument, 'col') as mock_col:
            mock_find = mock_col.find
            UserDocument.find(*args, **kwargs)

        self.assertEqual(mock_find.call_args_list, [Call(*args, **kwargs)])
Exemplo n.º 8
0
    def test_find_one(self):
        args = ['arg1', 'arg2', 'arg3']
        kwargs = {'kwarg1': '', 'kwarg2': '', 'kwarg3': ''}
        with patch.object(UserDocument, 'col') as mock_col:
            mock_find_one = mock_col.find_one
            mock_find_one.return_value = {}
            UserDocument.find_one(*args, **kwargs)

        self.assertEqual(mock_find_one.call_args_list, [Call(*args, **kwargs)])
Exemplo n.º 9
0
    def test_simple_index(self):
        index = {'fields': ('something',)}

        SimpleIndex.indexes = [index]

        with patch.object(SimpleIndex, 'col') as mock_col:
            mock_ensure_index = mock_col.ensure_index
            SimpleIndex.generate_index()

        self.assertEqual(mock_ensure_index.call_args_list, [Call('something', background=True)])
Exemplo n.º 10
0
    def test_simple_descending_index(self):
        index = {'fields': ('-something',)}

        SimpleIndex.indexes = [index]

        with patch.object(SimpleIndex, 'col') as mock_col:
            mock_ensure_index = mock_col.ensure_index
            SimpleIndex.generate_index()

        call_indexes = [('something', pymongo.DESCENDING)]
        self.assertEqual(mock_ensure_index.call_args_list, [Call(call_indexes, background=True)])
Exemplo n.º 11
0
    def test_save(self):
        user = UserDocument()

        kwargs = {'kwarg1': '', 'kwarg2': '', 'kwarg3': ''}

        with patch.object(UserDocument, 'col') as mock_col:
            mock_save = mock_col.save
            user.save(reload=False, **kwargs)

        args = [user]
        self.assertEqual(mock_save.call_args_list, [Call(*args, **kwargs)])
Exemplo n.º 12
0
def run_template(template):
    master_config = client.run('config.values', client="wheel")['data']['return']
    template_data = master_config['templates'].get(template)

    if not template_data:
        return "Unknown template", 404

    jid = client.run(template_data['fun'], client="local_async",
        tgt=template_data['tgt'], expr_form=template_data['expr_form'],
        args=Call(**template_data['args']))['jid']

    return redirect(url_for('job_result', jid=jid))
Exemplo n.º 13
0
def find_unique_tele_numbers(texts, calls):
    uniq_tele_nums = set({})  # using set instead of dict
    for call in calls:
        call = Call(call)
        uniq_tele_nums.add(call.incoming)
        uniq_tele_nums.add(call.answering)

    for text in texts:
        text = Text(text)
        uniq_tele_nums.add(text.incoming)
        uniq_tele_nums.add(text.answering)
    return len(uniq_tele_nums)
Exemplo n.º 14
0
def run():
    form = RunForm()
    if form.validate_on_submit():

        args = {k: v for (k, v) in request.form.iteritems() if not k in ('csrf_token', 'tgt', 'fun', 'expr_form') and v}

        jid = client.run(form.fun.data.strip(), client="local_async",
            tgt=form.tgt.data.strip(), expr_form=form.expr_form.data.strip(),
            args=Call(**args))['jid']

        return redirect(url_for('job_result', jid=jid))
    return render_template("run.html", form=form)
Exemplo n.º 15
0
    def test_delete(self):
        user = UserDocument()
        user.save()

        args = ['arg1', 'arg2', 'arg3']
        kwargs = {'kwarg1': '', 'kwarg2': '', 'kwarg3': ''}

        with patch.object(UserDocument, 'col') as mock_col:
            mock_remove = mock_col.remove
            user.delete(*args, **kwargs)

        args.insert(0, {'_id': user._id})
        self.assertEqual(mock_remove.call_args_list, [Call(*args, **kwargs)])
Exemplo n.º 16
0
    def test_override_background(self):
        index = {'fields': ('something',), 'unique': True, 'background': False}

        SimpleIndex.indexes = [index]

        with patch.object(SimpleIndex, 'col') as mock_col:
            mock_ensure_index = mock_col.ensure_index
            SimpleIndex.generate_index()

        index.pop('fields')
        self.assertEqual(
            mock_ensure_index.call_args_list,
            [Call('something', **index)])
Exemplo n.º 17
0
def find_telemarkers(calls, texts):
    outgoing = set({})
    non_tele = set({})
    for call in calls:
        call = Call(call)
        outgoing.add(call.incoming)
        non_tele.add(call.answering)
    for text in texts:
        text = Text(text)
        non_tele.add(text.incoming)
        non_tele.add(text.answering)
    possible_tele = list(outgoing - non_tele)
    possible_tele.sort()
    return possible_tele
Exemplo n.º 18
0
    def test_default_background(self):
        index = {'fields': ('something',), 'unique': True, 'ttl': 3600 * 24}

        SimpleIndex.indexes = [index]

        with patch.object(SimpleIndex, 'col') as mock_col:
            mock_ensure_index = mock_col.ensure_index
            SimpleIndex.generate_index()

        index.pop('fields')
        index['background'] = True
        self.assertEqual(
            mock_ensure_index.call_args_list,
            [Call('something', **index)])
Exemplo n.º 19
0
def find_area_codes(calls):
    total_calls_made = 0
    area_codes = set({})  # e.g. { area_code1, area_code2 }
    for call in calls:
        call = Call(call)
        if is_bangalore_num(call.incoming):
            total_calls_made += 1
            area_code = ''
            if '(0' in call.answering:
                idx = call.answering.index(")")
                area_code = call.answering[1:idx]
            else:
                area_code = call.answering[:4]
            area_codes.add(area_code)
    return sorted(area_codes), total_calls_made
Exemplo n.º 20
0
def _Exec(commands, config, stream, directory=None):

    if directory:
        directory = config.directory

    for command in commands:
        for name, script in command.viewitems():
            try:
                if script.startswith('$python'):
                    script = script[len('$python'):]
                    exec(script, {
                        'config': config,
                        '__file__': config.__file__
                    })
                else:
                    Call(script, directory, stream)
            except Exception:
                traceback.print_exc(stream)
                raise CommandError(name)
Exemplo n.º 21
0
def CPPLint(config, stream):
    cpplint = config.cpplint
    filters = cpplint.get('filter', [])
    linelength = cpplint.get('linelength', None)
    sources = cpplint.get('sources', [])
    directory = config.directory
    options = ''
    if len(filters):
        options += " --filter=" + ",".join(filters)
    if linelength != None:
        options += " --linelength=" + str(linelength)
    slist = []
    for src in sources:
        rex = os.path.join(config.location, src)
        slist += glob.glob(rex)
    for filename in slist:
        try:
            Call('cpplint %s %s' % (options, filename), directory, stream)
        except subprocess.CalledProcessError:
            raise Exception('cpplint failed at %s' % filename)
Exemplo n.º 22
0
def find_max_time_spent_phone_no(calls):
    phone_dict = {}
    for call in calls:
        call = Call(call)
        # Adding answering numbers to dictionary with call duration
        if call.answering not in phone_dict:
            phone_dict[call.answering] = int(call.during)
        else:
            phone_dict[call.answering] += int(call.during)

        # adding incoming numbers to dictionary with their call duration
        if call.incoming not in phone_dict:
            phone_dict[call.incoming] = int(call.during)
        else:
            phone_dict[call.incoming] += int(call.during)

    # finding out max time spent phone no in records
    phone_no = max(phone_dict, key=lambda k: phone_dict[k])

    # returning phone_no and time spent
    return phone_no, phone_dict[phone_no]
Exemplo n.º 23
0
def Make(config, stream):
    directory = config.directory
    location = config.location
    arch = config.arch
    platform = config.platform
    command = None

    if config.make is None:
        if config.tool == 'cmake':
            command = 'cmake --build . --target ALL_BUILD'
            command += _cmake_config_options(config)

        elif config.tool == 'node-gyp':
            command = 'node-gyp build'
            command += ' --directory=%s' % config.location
            if config.__global__.debug:
                command += ' options=--debug'
        else:
            raise Exception('make with %s not support' % (config.tool))
    else:
        command = config.make

    Call(command, directory, stream)
Exemplo n.º 24
0
def Configure(config, stream):
    directory = config.directory
    location = config.location
    arch = config.arch
    platform = config.platform
    command = None
    rpath = os.path.relpath(location, directory)

    if config.tool == 'cmake':
        command = 'cmake '
        if config.platform.lower() == 'windows':
            ver = _msvs_ver(config.msvs)
            if ver is None:
                raise BuildToolError('Unsupport msvs : %d' % config.msvs)

        if arch == Architecture.X86_64:
            arch = 'Win64'
        command += ' -G"Visual Studio %s %d %s" ' % (ver, config.msvs, arch)
        command += ' %s ' % rpath

    elif config.tool == 'node-gyp':
        command = 'node-gyp configure '
        if platform == Platform.WINDOWS:
            command += '--msvs_version=%d' % config.msvs

            if config.arch == Architecture.X86:
                arch = 'win32'
            elif arch == Architecture.X86_64:
                arch = 'x64'

            command += ' --arch=%s' % arch
            command += ' --directory=%s' % config.location
            directory = config.location

    if command is None:
        raise Exception('can not hanlde the comand')
    Call(command, directory, stream)