Exemplo n.º 1
0
    def __init__(self, language_file):
        self.symbol_table_list = []

        self.symbol = [
            "~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "+",
            "-", "=", "[", "{", "}", "]", "|", "\\", ":", ";", "'", "<", ",",
            ">", ".", "/", "?", '"', "_"
        ]

        self.config = Config(language_file)
        self.keyword = self.config.get_argvs("keyword").keys()
        '''Init value.'''
        self.index = 0
        self.start_index = 0
        self.end_index = 0
        self.next = 0
        self.pre = 0
        self.row = None

        self.text = ""
        self.token = ""

        self.type = SYMBOL_TABLE_VARIABLE_TYPE
        self.function_type = ["def"]
        self.class_type = ["class"]
        self.variable_type = ["self"]
Exemplo n.º 2
0
 def __init__(self, language_file, code_edit_file):
     self.symbol_table_list = []
     
     self.symbol = ["~", "`", "!", "@", "#", 
                    "$", "%", "^", "&", "*",                        
                    "(", ")", "+", "-", 
                    "=", "[", "{", "}", "]", 
                    "|", "\\", ":", ";", "'", 
                    "<", ",", ">", ".", "/", "?", '"', "_"]
     
     self.config = Config(language_file)
     self.code_edit_config = Config(code_edit_file)
     
     self.keyword = self.config.get_argvs("keyword").keys()
     '''Init value.'''
     self.index = 0
     self.start_index = 0
     self.end_index = 0
     self.next = 0
     self.pre  = 0
     self.row  = None
     
     self.text  = ""
     self.token = ""
     
     self.type           = SYMBOL_TABLE_VARIABLE_TYPE
     
     self.init_type_symbol()
Exemplo n.º 3
0
class Lang(object):
    def __init__(self):
        self.config = Config("cn.ini")
        
    def get_value(self, id):
        if self.config:
            return self.config.get("DEEPIN", str(id))
        else:    
            return "None"
        
    def set_lang(self, lang_path):
        if os.path.exists(lang_path):
            lang_path = lang_path
            self.config = Config(lang_path)
Exemplo n.º 4
0
class Lang(object):
    def __init__(self):
        self.config = Config("cn.ini")

    def get_value(self, id):
        if self.config:
            return self.config.get("DEEPIN", str(id))
        else:
            return "None"

    def set_lang(self, lang_path):
        if os.path.exists(lang_path):
            lang_path = lang_path
            self.config = Config(lang_path)
Exemplo n.º 5
0
 def set_lang(self, lang_path):
     if os.path.exists(lang_path):
         lang_path = lang_path
         self.config = Config(lang_path)
Exemplo n.º 6
0
 def __init__(self):
     self.config = Config("cn.ini")
Exemplo n.º 7
0
class Scan(object):
    def __init__(self, language_file):
        self.symbol_table_list = []

        self.symbol = [
            "~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "+",
            "-", "=", "[", "{", "}", "]", "|", "\\", ":", ";", "'", "<", ",",
            ">", ".", "/", "?", '"', "_"
        ]

        self.config = Config(language_file)
        self.keyword = self.config.get_argvs("keyword").keys()
        '''Init value.'''
        self.index = 0
        self.start_index = 0
        self.end_index = 0
        self.next = 0
        self.pre = 0
        self.row = None

        self.text = ""
        self.token = ""

        self.type = SYMBOL_TABLE_VARIABLE_TYPE
        self.function_type = ["def"]
        self.class_type = ["class"]
        self.variable_type = ["self"]

    def scan(self, text, row):
        # Save text and row.
        self.text = text
        self.row = row
        # Read token.
        if self.text:
            while True:
                ch = self.text[self.index]
                if ch not in [" "]:
                    if self.letter_bool(ch):
                        # print "======字母处理===="
                        self.letter_function()
                    elif self.number_bool(ch):
                        # print "======数字处理===="
                        self.number_function()
                    elif self.symbol_bool(ch):
                        # print "======符号处理===="
                        self.symbol_function()
                    else:
                        # print "======中文处理===="
                        self.index += 1
                else:
                    self.index += 1

                if self.len_text() <= self.index:
                    break

        ########################################
        ## return symbol table list.
        return self.symbol_table_list

    def china_function(self):
        pass

    def china_save(self):
        pass

    def letter_function(self):
        if self.keyword_bool(self.text[self.index]):
            self.keyword_function()
        else:
            self.variable_function()

        self.index += 1

    def keyword_function(self):
        # print "关键字处理模块:"
        self.token = ""
        # save pre and next point.
        self.pre = self.index
        self.next = self.index
        # save start index.
        self.start_index = self.pre
        # get keyword list.
        # key_list = self.keyword_bool(self.text[self.index])
        ######################################
        while True:
            try:
                keyword_ch = self.text[self.next]
            except:
                self.keyword_save()
                break

            if self.next > self.len_text() - 1:
                self.keyword_save()
                self.next += 1
                break

            if (not self.symbol_bool(keyword_ch)) and not keyword_ch in [" "]:
                self.token += keyword_ch
                self.next += 1
            else:
                self.keyword_save()
                break

        ######################################
        # print "======================"
        # print "token:", self.token
        # print "last next:", self.next
        # set index.
        self.index = self.next
        # save end index.
        self.end_index = self.next

    def keyword_save(self):
        self.end_index = self.next
        symbol_table = SymbolTable()
        symbol_table.type = SYMBOL_TABLE_NUMBER_TYPE
        symbol_table.token = self.token
        symbol_table.row = self.row
        symbol_table.start_index = self.start_index
        symbol_table.end_index = self.end_index - 1
        config_rgb = self.config.get("keyword", self.token)

        if self.token in self.function_type:
            self.type = SYMBOL_TABLE_FUNCTION_TYPE
        elif self.token in self.class_type:
            self.type = SYMBOL_TABLE_CLASS_TYPE
        elif self.token in self.variable_type:
            self.type = SYMBOL_TABLE_VARIABLE_TYPE

        if not config_rgb:
            self.variable_save()
        else:
            symbol_table.rgb = config_rgb
            # print "================="
            # print "type:", symbol_table.type
            # print "token:", symbol_table.token
            # print "row:", symbol_table.row
            # print "start_index:", symbol_table.start_index
            # print "end_index:", symbol_table.end_index - 1
            # print "rgb:", symbol_table.rgb
            # print "==========="
            self.symbol_table_list.append(symbol_table)

    def variable_function(self):
        # print "变量处理模块:"
        # clear token.
        self.token = ""
        # save pre and next point.
        self.pre = self.index
        self.next = self.index
        # save start index.
        self.start_index = self.pre

        #####################################################
        while True:
            try:
                variable_ch = self.text[self.next]
            except:
                self.variable_save()
                break

            if self.next > self.len_text() - 1:
                self.variable_save()
                self.next += 1
                break

            if (not self.symbol_bool(variable_ch)
                ) and not variable_ch in [" "]:
                self.token += variable_ch
                self.next += 1
            else:
                self.variable_save()
                break
        ##################################################
        # print "======================"
        # print "token:", self.token
        # print "last next:", self.next
        # set index.
        self.index = self.next
        # save end index.
        self.end_index = self.next

    def variable_save(self):
        self.end_index = self.next
        symbol_table = SymbolTable()
        symbol_table.token = self.token
        symbol_table.row = self.row
        symbol_table.start_index = self.start_index
        symbol_table.end_index = self.end_index - 1

        # save color->rgb.
        if self.type == SYMBOL_TABLE_VARIABLE_TYPE:
            config_rgb = self.config.get("keyword", "VARIABLE")
        elif self.type == SYMBOL_TABLE_FUNCTION_TYPE:
            config_rgb = self.config.get("keyword", "FUNCTION")
        elif self.type == SYMBOL_TABLE_CLASS_TYPE:
            config_rgb = self.config.get("keyword", "CLASS")

        self.type = SYMBOL_TABLE_VARIABLE_TYPE

        # save type.
        symbol_table.type = self.type

        if not config_rgb:
            self.config_rgb = "#000000"

        symbol_table.rgb = config_rgb

        # print "================="
        # print "type:", symbol_table.type
        # print "token:", symbol_table.token
        # print "row:", symbol_table.row
        # print "start_index:", symbol_table.start_index
        # print "end_index:", symbol_table.end_index - 1
        # print "rgb:", symbol_table.rgb
        # print "==========="
        self.symbol_table_list.append(symbol_table)

    def number_function(self):
        # print "数字处理模块:"
        # clear token.
        self.token = ""
        # save pre point.
        self.pre = self.index
        # save start index.
        self.start_index = self.pre
        # save next point.
        self.next = self.index

        # print "pre:", self.pre
        # print "next:", (self.next + self.index)
        # print "len:", self.len_text() - 1
        ###################################
        while True:
            try:
                number_ch = self.text[self.next]
            except:
                break

            if self.next >= self.len_text() - 1:
                self.end_index = self.next
                if self.symbol_bool(number_ch):
                    self.end_index -= 1

                self.next += 1
                break

            if (not self.symbol_bool(number_ch)) and not number_ch in [" "]:
                self.token += number_ch
                self.next += 1
            else:
                self.end_index = self.next - 1
                break

        ###################################
        # print "======================"
        # print "token:", self.token
        # print "last next:", self.next
        # set index.
        self.index = self.next
        self.number_save()

    def number_save(self):
        symbol_table = SymbolTable()
        symbol_table.type = SYMBOL_TABLE_NUMBER_TYPE
        symbol_table.token = self.token
        symbol_table.row = self.row
        symbol_table.start_index = self.start_index
        symbol_table.end_index = self.end_index
        config_rgb = self.config.get("keyword", "NUMBER")
        if not config_rgb:
            config_rgb = "#000000"
        symbol_table.rgb = config_rgb
        # print "================="
        # print "type:", symbol_table.type
        # print "token:", symbol_table.token
        # print "row:", symbol_table.row
        # print "start_index:", symbol_table.start_index
        # print "end_index:", symbol_table.end_index
        # print "rgb:", symbol_table.rgb
        # print "==========="
        self.symbol_table_list.append(symbol_table)

    def symbol_function(self):
        # print "符号处理模块:"
        temp_list = list(self.config.get("keyword", "notes_symbol"))
        if self.text[self.index] == '"':
            # print "字符串类型"
            self.string_function()
        elif self.text[self.index] == temp_list[0]:
            # print "===注释处理..."
            type_bool = False
            if len(self.text) >= len(temp_list):
                try:
                    for i in range(0, len(temp_list)):
                        type_bool = False
                        if self.text[self.index + i] == temp_list[i]:
                            type_bool = True
                except Exception, e:
                    print "symbol_function:-->", e
                    type_bool = False

            if type_bool:
                self.notes_function()
            else:
                self.index += 1

        self.index += 1
Exemplo n.º 8
0
 def set_lang(self, lang_path):
     if os.path.exists(lang_path):
         lang_path = lang_path
         self.config = Config(lang_path)
Exemplo n.º 9
0
 def __init__(self):
     self.config = Config("cn.ini")
Exemplo n.º 10
0
class Scan(object):        
    def __init__(self, language_file, code_edit_file):
        self.symbol_table_list = []
        
        self.symbol = ["~", "`", "!", "@", "#", 
                       "$", "%", "^", "&", "*",                        
                       "(", ")", "+", "-", 
                       "=", "[", "{", "}", "]", 
                       "|", "\\", ":", ";", "'", 
                       "<", ",", ">", ".", "/", "?", '"', "_"]
        
        self.config = Config(language_file)
        self.code_edit_config = Config(code_edit_file)
        
        self.keyword = self.config.get_argvs("keyword").keys()
        '''Init value.'''
        self.index = 0
        self.start_index = 0
        self.end_index = 0
        self.next = 0
        self.pre  = 0
        self.row  = None
        
        self.text  = ""
        self.token = ""
        
        self.type           = SYMBOL_TABLE_VARIABLE_TYPE
        
        self.init_type_symbol()
        
    def init_type_symbol(self):        
        function_type_list = [""]
        class_type_list = [""]
        variable_type_list = [""]
        #################################
        config_function_type = self.code_edit_config.get("TEXT_BUFFER_VALUE", "function_type")
        if config_function_type:
            function_type_list = (config_function_type).split(",")
        config_class_type = self.code_edit_config.get("TEXT_BUFFER_VALUE", "class_type")    
        if config_class_type:
            class_type_list = config_class_type.split(",")
        config_variable_type = self.code_edit_config.get("TEXT_BUFFER_VALUE", "variable_type")
        if config_variable_type:
            variable_type_list = config_variable_type.split(",")
        #################################    
        self.function_type  = function_type_list
        self.class_type     = class_type_list
        self.variable_type  = variable_type_list
        
    def scan(self, text, row):    
        # Save text and row.
        self.text = text
        self.row  = row
        # Read token.
        self.temp_cn_next = 0
        if self.text:
            while True:
                ch = self.text[self.index]
                if ch not in [" "]:
                    if self.letter_bool(ch):
                        # print "======字母处理===="
                        self.letter_function()
                    elif self.number_bool(ch):
                        # print "======数字处理===="
                        self.number_function()
                    elif self.symbol_bool(ch):    
                        # print "======符号处理===="
                        self.symbol_function()  
                    else:    
                        # print "======中文处理===="
                        self.index += 1
                        self.temp_cn_next += 2
                else:    
                    self.index += 1
                
                if self.len_text() <= self.index:
                    break                
                
        ########################################
        ## return symbol table list.    
        return self.symbol_table_list
    
    def china_function(self):
        pass
    
    def china_save(self):    
        pass
    
    def letter_function(self):
        if self.keyword_bool(self.text[self.index]):
            self.keyword_function()
        else:    
            self.variable_function()
        
        self.index += 1
        
    def keyword_function(self):
        # print "关键字处理模块:"
        self.token = ""
        # save pre and next point.
        self.pre = self.index
        self.next = self.index
        # save start index.
        self.start_index = self.pre
        # get keyword list.
        # key_list = self.keyword_bool(self.text[self.index])
        ######################################        
        while True:
            try:
                keyword_ch = self.text[self.next]
            except:
                self.keyword_save()
                break                        
            
            if self.next > self.len_text() - 1:
                self.keyword_save()
                self.next += 1
                break
            
            if (not self.symbol_bool(keyword_ch)) and not keyword_ch in [" "]:
                self.token += keyword_ch
                self.next += 1
            else:
                self.keyword_save()
                break
            
        ######################################
        # print "======================"
        # print "token:", self.token
        # print "last next:", self.next
        # set index.            
        self.index     = self.next
        # save end index.
        self.end_index = self.next
            
    def keyword_save(self):    
        self.end_index = self.next
        symbol_table = SymbolTable()
        symbol_table.type  = SYMBOL_TABLE_NUMBER_TYPE
        symbol_table.token = self.token
        symbol_table.row   = self.row
        symbol_table.start_index = self.start_index + self.temp_cn_next
        symbol_table.end_index   = self.end_index - 1 + self.temp_cn_next
        config_rgb = self.config.get("keyword", self.token)
        
        if self.token in self.function_type:
            self.type = SYMBOL_TABLE_FUNCTION_TYPE
        elif self.token in self.class_type:    
            self.type = SYMBOL_TABLE_CLASS_TYPE
        elif self.token in self.variable_type:    
            self.type = SYMBOL_TABLE_VARIABLE_TYPE
            
            
        if not config_rgb:
            self.variable_save()
            # pass
        else:    
            symbol_table.rgb = config_rgb
            # print "================="
            # print "type:", symbol_table.type
            # print "token:", symbol_table.token
            # print "row:", symbol_table.row
            # print "start_index:", symbol_table.start_index
            # print "end_index:", symbol_table.end_index - 1
            # print "rgb:", symbol_table.rgb
            # print "==========="
            self.symbol_table_list.append(symbol_table)
        
    def variable_function(self):    
        # print "变量处理模块:"
        # clear token.
        self.token = ""
        # save pre and next point.
        self.pre = self.index
        self.next = self.index
        # save start index.
        self.start_index = self.pre
        
        #####################################################
        while True:
            try:
                variable_ch = self.text[self.next]
                if self.cn_bool(variable_ch):
                    self.temp_cn_next += 2
            except:    
                self.variable_save()
                break
            
            if self.next > self.len_text() - 1:
                self.variable_save()
                self.next += 1
                break
            
            if (not self.symbol_bool(variable_ch)) and not variable_ch in [" "]:
                self.token += variable_ch
                self.next += 1
            else:
                self.variable_save()
                break                       
        ##################################################    
        # print "======================"
        # print "token:", self.token
        # print "last next:", self.next
        # set index.            
        self.index     = self.next
        # save end index.
        self.end_index = self.next
                    
    def variable_save(self):
        self.end_index = self.next
        symbol_table = SymbolTable()        
        symbol_table.token = self.token
        symbol_table.row   = self.row
        symbol_table.start_index = self.start_index + self.temp_cn_next
        symbol_table.end_index   = self.end_index - 1 + self.temp_cn_next
                    
        # save color->rgb.
        if self.type ==   SYMBOL_TABLE_VARIABLE_TYPE:
            config_rgb = self.code_edit_config.get("TEXT_BUFFER_VALUE", "VARIABLE")
        elif self.type == SYMBOL_TABLE_FUNCTION_TYPE:    
            config_rgb = self.code_edit_config.get("TEXT_BUFFER_VALUE", "FUNCTION")
        elif self.type == SYMBOL_TABLE_CLASS_TYPE:
            config_rgb = self.code_edit_config.get("TEXT_BUFFER_VALUE", "CLASS")            
            
        self.type = SYMBOL_TABLE_VARIABLE_TYPE
        
        # save type.    
        symbol_table.type  = self.type
        
        if not config_rgb:
            config_rgb = "#000000"
            
        symbol_table.rgb = config_rgb
        
        # print "================="
        # print "type:", symbol_table.type
        # print "token:", symbol_table.token
        # print "row:", symbol_table.row
        # print "start_index:", symbol_table.start_index
        # print "end_index:", symbol_table.end_index - 1
        # print "rgb:", symbol_table.rgb
        # print "==========="
        self.symbol_table_list.append(symbol_table)
        
    def number_function(self):
        # print "数字处理模块:"
        # clear token.
        self.token = ""
        # save pre point.
        self.pre = self.index
        # save start index.
        self.start_index = self.pre
        # save next point.
        self.next = self.index
        
        # print "pre:", self.pre
        # print "next:", (self.next + self.index)
        # print "len:", self.len_text() - 1                
        ###################################            
        while True:
            try:
                number_ch = self.text[self.next]
            except:    
                break
            
            if self.next >= self.len_text()-1:                
                self.end_index = self.next
                if self.symbol_bool(number_ch):
                    self.end_index -= 1 
                    
                self.next += 1
                break
            
            if (not self.symbol_bool(number_ch)) and not number_ch in [" "]:
                self.token += number_ch
                self.next += 1
            else:
                self.end_index = self.next - 1                
                break
            
        ###################################
        # print "======================"   
        # print "token:", self.token
        # print "last next:", self.next            
        # set index.                        
        self.index     = self.next
        self.number_save()
        
    def number_save(self):            
        symbol_table = SymbolTable()
        symbol_table.type  = SYMBOL_TABLE_NUMBER_TYPE
        symbol_table.token = self.token
        symbol_table.row   = self.row
        symbol_table.start_index = self.start_index + self.temp_cn_next
        symbol_table.end_index   = self.end_index + self.temp_cn_next
        config_rgb = self.code_edit_config.get("TEXT_BUFFER_VALUE", "NUMBER")
        if not config_rgb:
            config_rgb = "#000000"
        symbol_table.rgb = config_rgb
        # print "================="
        # print "type:", symbol_table.type
        # print "token:", symbol_table.token
        # print "row:", symbol_table.row
        # print "start_index:", symbol_table.start_index
        # print "end_index:", symbol_table.end_index
        # print "rgb:", symbol_table.rgb
        # print "==========="
        self.symbol_table_list.append(symbol_table)

    def symbol_function(self):
        # print "符号处理模块:"
        # temp_list = list(self.config.get("keyword", "notes_symbol"))
        temp_list = list(self.code_edit_config.get("TEXT_BUFFER_VALUE", "notes_symbol"))
        
        if self.text[self.index] == '"':
            # print "字符串类型"
            self.string_function()            
        elif self.text[self.index] == temp_list[0]:
            # print "===注释处理..."      
            type_bool = False
            if len(self.text) >= len(temp_list):
                try:
                    for i in range(0, len(temp_list)):
                        type_bool = False                    
                        if self.text[self.index + i] == temp_list[i]:
                            type_bool = True                        
                except Exception, e:
                    print "symbol_function:-->", e
                    type_bool = False
                
            if type_bool:
                self.notes_function()
            else:
                self.index += 1
                
        self.index += 1        
Exemplo n.º 11
0
#!/usr/bin/python3

import os
import subprocess
import json
import argparse
import getpass

# .ini -> RECIPIENT, STORE
import sys
sys.path.append('../lib')
from ini import Config
cfg = Config("/etc/integration/certs.ini")
RECIPIENT = cfg.config.get('inicerts', 'RECIPIENT')
STORE_PATH = cfg.config.get('inicerts', 'STORE_PATH')

PASSPHRASE = None
GPG_BIN = 'gpg2'  # w pgp nie ma opcji --output - dlatego pgp2

# This command adds key info to ssh-agent
# see: https://github.com/ulmenhaus/env/blob/33f07be079bc7c1caa8108ffafd726ed06a0bd45/bin/ssh-add-with-password

EXPECT_CMDS = """
spawn ssh-add %(key_path)s;
expect "Enter passphrase for %(key_path)s:";
send "%(key_pass)s\r";
expect eof
"""


def agent_store(key_file_name, password):