Beispiel #1
0
    def test_encode_decode(self):
        simple_erl_term = erl_terms.encode(1)
        self.assertEqual(simple_erl_term, b'\x83a\x01')
        self.assertEqual(erl_terms.decode(simple_erl_term), 1)

        complex_data = {'error': None, 'payload': {'active_param': 1, 'pipe_before': False}, 'signatures': [{'docs': 'docs', 'name': 'name', 'params': ['list']}, {'docs': 'snd doc', 'params': ['list']}], 'request_id': 1 }

        self.assertEqual(erl_terms.decode(erl_terms.encode(complex_data)), complex_data)
    def get(self, id):
        final = {
            'json': {
                'data': u'File content is null, please select [Detail]'
            },
            'file_info': {}
        }
        sql = common_sql_content + ' where a.id = %s'

        file_info = util.db_fetchone(pool, sql, (id, ))
        if not file_info:
            return final

        # 文件内容还未加载
        if not file_info.get('conf_content'):
            return final

        conf_file_path = file_info.get('conf_file_path')
        # 是 erl文件才解析
        if conf_file_path:
            try:
                tuple_list = erl_terms.decode(file_info['conf_content'])
                convert_result = util.convert_tuple_to_map(tuple_list, 'data')

                final = {'json': convert_result, 'file_info': file_info}
            except Exception, e:
                final = {
                    'json': {
                        'data':
                        u'文件解析失败,请确定是标准的erl配置文件格式, err_info:%s' % str(e)
                    },
                    'file_info': file_info
                }
Beispiel #3
0
    def process_command(self, request, source, line, column):
        self._log('column: %s' % column)
        self._log('line: %s' % line)
        self._log('source: %s' % source)
        py_struct = {
            'request_id': 1,
            'auth_token': None,
            'request': request,
            'payload': {
                'buffer': source,
                'line': int(line),
                'column': int(column)
            }
        }

        req_erl_struct = erl_terms.encode(py_struct)
        server_log = self._get_running_server_log()
        if server_log == None:
            server_log = self._create_server_log()
            self._run_alchemist_server(server_log)

        connection = self._extract_connection_settings(server_log)
        if connection == None:
            self._run_alchemist_server(server_log)
            connection = self._extract_connection_settings(server_log)

        sock = self._connect(connection)
        if sock == None:
            self._run_alchemist_server(server_log)
            connection = self._extract_connection_settings(server_log)
            if connection == None:
                self._log(
                    "Couldn't find the connection settings from server_log: %s"
                    % (server_log))
                return None
            sock = self._connect(connection)

        resp_erl_struct = self._send_command(sock, req_erl_struct)
        rep_py_struct = erl_terms.decode(resp_erl_struct)
        if rep_py_struct['error']:
            return 'error:%s' % rep_py_struct['error']
        self._log('ElixirSense: %s' % rep_py_struct)
        if request == "suggestions":
            return self.to_vim_suggestions(rep_py_struct['payload'])
        elif request == "docs":
            if rep_py_struct['payload']['docs']:
                return rep_py_struct['payload']['docs']['docs']
            return rep_py_struct['payload']
        elif request == 'definition':
            return self.to_vim_definition(rep_py_struct['payload'])
Beispiel #4
0
def parse_deps(config):
    """Parse rebar.config and rip out the deps section"""
    buffer = ""
    with open(config) as file:
        for line_with_newline in file:
            line = line_with_newline.rstrip()
            # Skip commented lines
            if re.match("\s*%", line):
                continue
            if len(buffer) > 0:
                buffer += line
            if "{deps," in line:
                buffer = line
            if len(buffer) > 0 and "]}." in line:
                break
    if buffer == "":
        return []
    else:
        decoded = erl_terms.decode(buffer)
    if len(decoded[0]) < 2:
        return []
    else:
        return decoded[0][1]
Beispiel #5
0
    def process_command(self, request, source, line, column):
        self._log('column: %s' % column)
        self._log('line: %s' % line)
        self._log('source: %s' % source)
        py_struct = {
            'request_id': 1,
            'auth_token': None,
            'request': request,
            'payload': {
                'buffer': source,
                'line': int(line),
                'column': int(column)
            }
        }

        req_erl_struct = erl_terms.encode(py_struct)

        sock = self.__get_socket()

        try:
            resp_erl_struct = self._send_command(sock, req_erl_struct)
        except Exception as e:
            return 'error:%s' % e

        rep_py_struct = erl_terms.decode(resp_erl_struct)
        if rep_py_struct['error']:
            return 'error:%s' % rep_py_struct['error']
        self._log('ElixirSense: %s' % rep_py_struct)
        if request == "suggestions":
            return self.to_vim_suggestions(rep_py_struct['payload'])
        elif request == "docs":
            if rep_py_struct['payload']['docs']:
                return rep_py_struct['payload']['docs']['docs']
            return rep_py_struct['payload']
        elif request == 'definition':
            return self.to_vim_definition(rep_py_struct['payload'])
Beispiel #6
0
    def process_command(self, request, source, line, column):
        self._log('column: %s' % column)
        self._log('line: %s' % line)
        self._log('source: %s' % source)
        py_struct = {
                'request_id': 1,
                'auth_token': None,
                'request': request,
                'payload': {
                    'buffer': source,
                    'line': int(line),
                    'column': int(column)
                    }
                }

        req_erl_struct = erl_terms.encode(py_struct)

        sock = self.__get_socket()

        try:
            resp_erl_struct = self._send_command(sock, req_erl_struct)
        except Exception as e:
            return 'error:%s' % e

        rep_py_struct = erl_terms.decode(resp_erl_struct)
        if rep_py_struct['error']:
            return 'error:%s' % rep_py_struct['error']
        self._log('ElixirSense: %s' % rep_py_struct)
        if request == "suggestions":
            return self.to_vim_suggestions(rep_py_struct['payload'])
        elif request == "docs":
            if rep_py_struct['payload']['docs']:
                return rep_py_struct['payload']['docs']['docs']
            return rep_py_struct['payload']
        elif request == 'definition':
            return self.to_vim_definition(rep_py_struct['payload'])
Beispiel #7
0
def convert(script_content, env):
    return substitute_vars(erl_terms.decode(script_content), env)
Beispiel #8
0
zabbix 增加sudo权限
例如:
zabbix ALL=(root) NOPASSWD:/usr/sbin/rabbitmqctl
Defaults:zabbix   !requiretty
'''

check_command = ['/usr/sbin/rabbitmqctl', '-q', 'status']

if getuid() != 0:
    check_command.insert(0, '/usr/bin/sudo')
status = check_output(check_command)

status = ''.join(status.splitlines()) + '.'
status = sub('(?:\\\\n)+', '', status)

status = decode(status)

#print status

status_dict = dict()
for item in status[0]:
    key = item[0]
    val = item[1]

    if key == 'running_applications':
        continue

    #print key, val
    if type(val) == type(list()):
        d_tmp = dict()
        for v in val:
Beispiel #9
0
import tempfile
from erl_terms import decode
import os.path
import tarfile
import pprint
import shutil

TARBALL_DIR = 'tarballs'


def make_tarball_path(fname, loc=TARBALL_DIR):
    return os.path.join(loc, fname)


tmpdir = tempfile.mkdtemp()

with tarfile.open(make_tarball_path("gisla-1.0.0.tar")) as tf:
    tf.extractall(path=tmpdir)

metadata = None
with open(make_tarball_path("metadata.config", tmpdir), "rb") as f:
    metadata = decode(f.read())

pprint.pprint(metadata)

shutil.rmtree(tmpdir)
Beispiel #10
0
def convert(script_content, env):
    return substitute_vars(erl_terms.decode(script_content), env)