Example #1
0
    def xls2xml(self, xls_path, file_path, target_language, target_dir_path):
        """
        :param xls_path: 表格路径
        :param file_path: 目标文件路径
        :param target_language: 目标语言
        :param target_dir_path: 目标文件目录
        """
        Log.info("--- xls2xml ---")

        # 输入 excel
        if not xls_path or not os.path.exists(xls_path):
            Log.error(
                Constant.Error(Constant.ERROR_EXCEL_NOT_EXIST).get_desc_en())
            return Constant.Error(Constant.ERROR_EXCEL_NOT_EXIST)

        xlsPath = xls_path
        self.filePath = file_path
        self.targetLanguage = target_language
        self.dirPath = target_dir_path

        # 获取 xls 对象,以及目标 sheet(这里默认为第一张表,index 从0开始)
        xlsParse = XLSParse()
        xlsParse.open_excel(xlsPath)

        sheet = xlsParse.sheet_by_index(0)

        Log.info("name = %s, rows number = %s,clos number = %s" %
                 (sheet.name, sheet.nrows, sheet.ncols))
        return self.convert(sheet)
def switch_4g(main_obj):
    print("配置MAC:" + str(Constant.MAC))
    mac_cmd = "ifconfig eth0 hw ether " + Constant.MAC + " & ifconfig lo up"
    os.system(mac_cmd)
    time.sleep(2)
    cmd = "ifconfig eth0 " + str(Constant.IP) + " netmask " + str(
        Constant.IPMASK)
    print(cmd)
    os.system(cmd)
    if main_obj is not None:
        main_obj.start_server_thread()
    if "1" == Constant.G4EN:
        Constant.network = 2
        print("开启4G")
        Constant.wtire_gpio(1, 0)
        time.sleep(3)
        Constant.wtire_gpio(1, 1)
        time.sleep(30)
        os.system('echo "AT\$QCRMCALL=1,1" > /dev/ttyUSB2')
        time.sleep(10)
        os.system("ifconfig wwan0 up")
        time.sleep(2)
        os.system("udhcpc -i wwan0 &")
        print("启用4G完成")
    FileUtil.write_dns(Constant.NAMESERVER_PATH, Constant.DNS1, Constant.DNS2)
    # os.system(Constant.NAMESERVER_PATH)
    cmd = "route add default gw " + Constant.GATEWAY
    print(cmd)
    os.system("route add default gw " + Constant.GATEWAY)
    print("网络配置完成")
def switch_voice(open_flag):
    if open_flag:
        print("打开声音")
        Constant.wtire_gpio(23, 1)  # 取消静音
    else:
        print("关闭声音")
        Constant.wtire_gpio(23, 0)
def wait_sn_mac_info():
    gkl = CDLL("libgkl.so")
    Constant.wtire_gpio = gkl.gpio_write
    Constant.wtire_gpio(4, 1)
    Constant.wtire_gpio(2, 1)
    try:
        update_complete_play()  # U盘升级完成,播放提示音
    except Exception as e:
        print("播放升级完成提示音异常:" + str(e))
def check_thread(main_obj):
    for i in range(1500):
        Constant.wtire_gpio(2, 1)
        time.sleep(Constant.time_interval)
        Constant.wtire_gpio(2, 0)
        time.sleep(Constant.time_interval)
    if main_obj is not None:
        main_obj.stop_server()
    while True:
        check_network()
def init(main_obj):
    try:
        gkl = CDLL("libgkl.so")
        Constant.wtire_gpio = gkl.gpio_write
        Constant.wtire_gpio(4, 1)
        print("check_thread start")
        check = threading.Thread(target=check_thread, args=[main_obj], name="check_thread")
        check.start()
        read_serial_thread = threading.Thread(target=read_serial, name="read_serial_thead")
        read_serial_thread.start()
        switch_voice(False)
        switch_4g(main_obj)
    except Exception as e:
        print("硬件初始化失败:" + str(e))
Example #7
0
 def xml2xls_single(self, xls_dir, input_file_path):
     # type: (str, str) -> object
     if not xls_dir or not os.path.exists(xls_dir):
         return Constant.Error(Constant.ERROR_DIR_NOT_EXIST, "excel dir")
     if not input_file_path or not os.path.exists(input_file_path):
         return Constant.Error(Constant.ERROR_XML_FILE_NOT_EXIST)
     xlsPath = os.path.join(xls_dir, Constant.Config.export_excel_name)
     workbook = pyExcelerator.Workbook()
     ws = workbook.add_sheet('Sheet1')
     # row col content
     ws.write(0, 0, Constant.Config.keyTitle)
     dic = XMLParse.get_value_and_key(input_file_path)
     writeDict(ws, dic, 1, 0, None, True)
     workbook.save(xlsPath)
     return Constant.Error(Constant.SUCCESS)
Example #8
0
def file_handling(obj, projectPath, newFileFlag):
    if newFileFlag:
        # 执行文件处理
        # 执行旧文件处置
        uploadFilePathForDeploy = Constant.get_file_upload_path(obj)
        if not check_file_exist(uploadFilePathForDeploy):
            raise RuntimeError(
                'new file not exist. Please check file {} first'.format(
                    uploadFilePathForDeploy))
        # 如果有新文件,则先判断新文件是否存在,如果存在再停止进程,否则不停止
        oldFileBackupPath = None
        deployFilePath = None
        try:
            kill_process(obj)
            oldFileBackupPath = obj.backupOldFile()
            # 执行新文件处置
            deployFilePath = obj.handleNewFile(uploadFilePathForDeploy,
                                               oldFileBackupPath)
            # 执行文件处置结果check,返回异常表示失败,否则表示成功
            if not obj.checkNewFile(deployFilePath):
                raise RuntimeError("handle file fail")
            return uploadFilePathForDeploy, oldFileBackupPath, deployFilePath
        except IOError as e:
            logging.error("file_handling error: {0}".format(e))
            # 处置失败时,执行旧文件恢复操作,进程中止
            recover_app(obj, projectPath, oldFileBackupPath, deployFilePath,
                        True, False, -1, Constant.javaPath)
            # obj.recoverOldFile(newFilePath, oldFileBackupPath, deployFilePath)
            raise RuntimeError('new file handle fail')
    else:
        # TODO 增加默认路径返回
        return None, None, obj.get_default_deploy_path()
Example #9
0
def server():
    constant = Constant.Constant()
    PORT = constant.port  # arbitrary, just make it match in Android code
    IP = constant.ip  # represents any IP address

    sock = socket(AF_INET, SOCK_DGRAM)  # SOCK_DGRAM means UDP socket
    sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)  # make socket reuseable
    sock.bind((IP, PORT))
    print "Waiting..."
    while True:
        print "Waiting for data..."
        data, addr = sock.recvfrom(2048)  # 返回的接收的数据,和发送数据的地址以及端口
        print('Received:', data, 'from', addr)
        Str = data
        beginStr = constant.beginStr
        endStr = constant.endStr
        dataReturn = constant.returnResoutOk
        if Str.startswith(beginStr) and Str.endswith(endStr):
            print "get the right words!"
            getStr = Str[6:-4]  #获取真正传入的信息
            if len(getStr) == 0:
                dataReturn = constant.returnResoutNull
                print "the word is null!  Return the Null Mark!"
            else:
                print "go on!   Return the right Mark!" + ctime()
                #处理返回的数据
                dealDatas(getStr)
        else:
            dataReturn = constant.returnResoutError
            print "can not get the UDP Packages!   Return the Error Mark!"
        sock.sendto(('[%s] %s' % (ctime(), dataReturn)).encode('utf8'),
                    addr)  #传输处理后的数据,需要写addr,仍然因为是无连接
Example #10
0
    def __init__(self, node_set):

        self.rho = ct.Constant().rho
        self.node_set = node_set
        self.xupdate = Xupdate(self.node_set, self.rho)
        self.zupdate = Zupdate(self.node_set, self.rho)
        self.mupdate = Mupdate(self.node_set, self.rho)
Example #11
0
 def checkHealth(self, current_pid, new_file_locate_path):
     url = Constant.get_property("healthCheckUrl",
                                 self.env).replace("{}",
                                                   self.get_artifact_id())
     try:
         ret = http_request_ret_content(url)
         return "passing".__eq__(ret)
     except Exception as e:
         return False
Example #12
0
 def getResult(self):
     
     primalRes,dualRes,exeTime=self.solver.start(ct.Constant().numIter)
     var=self.node_set
     
     obj=0
     for n in var:
         obj+=sum(n.z_npower)[0,0].real
     return (primalRes,dualRes,exeTime,var,obj)
     
     
def check_network():
    while True:
        if Constant.MQTT_CLIENT is None or not Constant.MQTT_CLIENT.is_connected():  # 如果没网
            if Constant.G4EN:
                print("尝试拨号...")
                os.system('echo "AT\$QCRMCALL=1,1" > /dev/ttyUSB2')
            for i in range(600):  # 等待20分钟
                Constant.wtire_gpio(2, 1)
                time.sleep(Constant.time_interval)
                Constant.wtire_gpio(2, 0)
                time.sleep(Constant.time_interval)
            if Constant.MQTT_CLIENT is None or not Constant.MQTT_CLIENT.is_connected():  # 如果依然没网
                os.system("reboot")
        else:
            if Constant.G4EN:
                get_csq()
            for i in range(600):  # 等待20分钟后再次检测
                Constant.wtire_gpio(2, 1)
                time.sleep(Constant.time_interval)
                Constant.wtire_gpio(2, 0)
                time.sleep(Constant.time_interval)
Example #14
0
 def __init__(self, base_url):
     self.base_url=base_url
     self.cons=Constant()
def read_serial():
    try:
        while not Constant.input_flag:  # 不允许输入命令
            value = input("")
            print(value)
            if "betel_" in value:
                os.system(value.replace("betel_", ""))
            elif "serialwrite" in value:
                value = value.replace("serialwrite", "").replace(
                    " ", "").replace("\"", "").replace("'", "")
                if value is not None:
                    FileUtil.set_conf(Constant.SERIAL_MAC_PATH, "sn_mac", "SN",
                                      value)
                    print("\n===SN OK !\n")
            elif "writemac" in value:
                value = value.replace("writemac", "").replace(" ", "").replace(
                    "\"", "").replace("'", "")
                if value is not None:
                    FileUtil.set_conf(Constant.SERIAL_MAC_PATH, "sn_mac",
                                      "MAC", value)
                    print("\n===MAC OK\n")
            elif "reboot" in value:
                os.system("reboot")
            elif "get_sn" in value:
                try:
                    sn = FileUtil.get_conf(Constant.SERIAL_MAC_PATH, "sn_mac",
                                           "SN")
                    print("get_sn:" + str(sn))
                except Exception as e:
                    print("get_sn: error" + str(e))
            elif "get_mac" in value:
                try:
                    mac = FileUtil.get_conf(Constant.SERIAL_MAC_PATH, "sn_mac",
                                            "MAC")
                    print("get_mac:" + str(mac))
                except Exception as e:
                    print("get_mac: error" + str(e))
            elif "get_imei" in value:
                cmd = 'echo "AT+SIMEI?" > /dev/ttyUSB2 & timeout -t 1 cat /dev/ttyUSB2 | grep SIMEI '
                os.system(cmd)
            elif "get_csq" in value:
                cmd = 'echo "AT+CSQ" > /dev/ttyUSB2  & timeout -t 3 cat /dev/ttyUSB2 | grep CSQ:'
                os.system(cmd)
            elif "check_usb" in value:
                cmd = 'cat /mnt/sda1/usb_check.txt'
                os.system(cmd)
            elif "get_device_status" in value:
                if Constant.MQTT_CLIENT is not None and Constant.MQTT_CLIENT.is_connected(
                ):
                    print("status: online")
                else:
                    print("status: offline")
            elif "test_play" in value:
                Constant.wtire_gpio(4, 1)
                Constant.wtire_gpio(2, 1)
                try:
                    update_complete_play()  # U盘升级完成,播放提示音
                except Exception as e:
                    print("播放升级完成提示音异常:" + str(e))
                print("test_play: ing")
            elif "mute" in value:
                switch_voice(False)
                print("mute: ok")
            elif "unm_ute" in value:
                switch_voice(True)
                print("unmute: ok")
            elif "power_off" in value:
                Constant.wtire_gpio(4, 0)
                print("power_off:ok")
            elif "power_on" in value:
                Constant.wtire_gpio(4, 1)
                print("power_on:ok")
    except Exception as e:
        print("read_serial failed : " + str(e))
        time.sleep(10)
        read_serial()
def wait_conf_info():
    gkl = CDLL("libgkl.so")
    Constant.wtire_gpio = gkl.gpio_write
    Constant.wtire_gpio(2, 1)
    time.sleep(2)
    Constant.wtire_gpio(2, 0)
Example #17
0
    def xml2xls(self, xls_dir, input_dir):
        # type: (str, str) -> Constant.Error
        if not xls_dir or not os.path.exists(xls_dir):
            return Constant.Error(Constant.ERROR_DIR_NOT_EXIST, "excel dir")
        if not input_dir or not os.path.exists(input_dir):
            return Constant.Error(Constant.ERROR_DIR_NOT_EXIST, "xml dir")

        xlsPath = os.path.join(xls_dir, Constant.Config.export_excel_name)
        workbook = pyExcelerator.Workbook()
        ws = workbook.add_sheet('Sheet1')
        # row col content
        ws.write(0, 0, Constant.Config.moduleTitle)
        ws.write(0, 1, Constant.Config.keyTitle)
        ws.write(0, 2, Constant.Config.export_base_title)

        # 获取某个文件夹的所有文件,作为标准 这里是 value-zh
        base_dir = os.path.join(input_dir, Constant.Config.export_base_dir)
        #  os.walk(path)返回三个值:
        #  parent, 表示path的路径、
        #  dirnames, path路径下的文件夹的名字
        #  filenames path路径下文件夹以外的其他文件。
        print input_dir
        sub_dir_names = []
        for _, dir_names, _ in os.walk(input_dir):
            if dir_names:
                sub_dir_names = dir_names
                break
        print sub_dir_names

        row = 1
        # 文件夹下所有文件
        files = os.listdir(base_dir)
        for filename in files:
            module_name = getModuleName(filename)
            if not module_name:
                continue
            file_path = os.path.join(base_dir, filename)  # 文件路径
            base_dict = XMLParse.get_value_and_key(file_path)

            col = 3  # base_dic 占用 0 和 1 2
            for dir_name in sub_dir_names:
                cur_dir_path = os.path.join(input_dir, dir_name)
                if cur_dir_path == base_dir:
                    continue  # 标准文件夹不处理

                # 当前文件夹的语言
                lan = getDirLan(input_dir, cur_dir_path)
                print lan
                if not lan:  # 文件夹爱不符合规范不处理(values-lan 或 values)
                    continue

                # 获取其他按文件夹下的该文件路径
                cur_file = os.path.join(cur_dir_path, filename)
                if not os.path.exists(cur_file):
                    # 路径不存在,不处理,跳过
                    continue

                # 写标题
                ws.write(0, col, lan)
                cur_dict = XMLParse.get_value_and_key(cur_file)
                (base_dict, cur_dict) = sortDic(base_dict, cur_dict)
                writeDict(ws, cur_dict, row, col, None, False)  # 仅写 value
                col += 1  # 写完非标准文件的内容,坐标右移(列+1)

            # 最后写 标准文件的 key(0)-values(1)
            writeDict(ws, base_dict, row, 0, module_name, True)

            row = len(base_dict)
            print("row = %s" % row)

        workbook.save(xlsPath)
        return Constant.Error(Constant.SUCCESS)
Example #18
0
def randomSayiGetir():
    if Constant.RANDOMITERASYONU == 10:
        Constant.birle()
        return Constant.RANDOMLAR[Constant.RANDOMITERASYONU]
    Constant.artir()
    return Constant.RANDOMLAR[Constant.RANDOMITERASYONU]
Example #19
0
 def applicationStartUp(self, project_path, new_file_location, java_path):
     return java_application_start(
         Constant.javaPath, Constant.get_property("startCmd", self.env),
         new_file_location,
         get_connect_path(project_path) + Constant.logoutpath)
Example #20
0
 def get_constant(self):
     tok = self.lex.get_next_token()
     self.match(tok, TokenType.CONST_TOK)
     value = int(tok.get_lexeme())
     return Constant.Constant(value)
Example #21
0
    def convert(self, sheet):
        """
        真正转化部分
        :param sheet: excel 的 sheet 对象
        :return: ErrorConstant.Error
        """
        Log.info("--- convert ---")
        keyIndex = -1
        moduleIndex = -1
        tempLanguageIndex = None
        # 返回由该行中所有单元格的数据组成的列表
        try:
            firstRow = sheet.row_values(0)
        except Exception as e:
            Log.error(
                Constant.Error(Constant.EXCEPTION_EXL_FILE,
                               e.message).get_desc_en())
            return Constant.Error(Constant.EXCEPTION_EXL_FILE, e.message)

        if len(firstRow) == 0:
            Log.error(
                Constant.Error(Constant.ERROR_KEY_NOT_FOUND).get_desc_en())
            return Constant.Error(Constant.ERROR_KEY_NOT_FOUND)

        for index in range(len(firstRow)):
            if firstRow[index] == self.keyTitle:
                keyIndex = index
                pass
            elif firstRow[index] == self.moduleTitle:
                moduleIndex = index
                pass
            elif firstRow[index] == self.targetLanguage:
                tempLanguageIndex = index
                pass

        if keyIndex == -1:
            Log.error(
                Constant.Error(Constant.ERROR_KEY_NOT_FOUND).get_desc_en())
            return Constant.Error(Constant.ERROR_KEY_NOT_FOUND)

        # 获取 key 集合,并删除 title 项
        xlsKeys = sheet.col_values(keyIndex)
        del xlsKeys[0]

        if self.filePath and tempLanguageIndex:  # 输入是文件,指定目标语言
            Log.debug("keyIndex = %s moduleIndex = %s languageIndex = %s" %
                      (keyIndex, moduleIndex, tempLanguageIndex))
            # 获取 value 集合,并删除 title 项
            xlsValues = sheet.col_values(tempLanguageIndex)
            del xlsValues[0]

            XMLParse.update_xml_value(self.filePath, xlsKeys, xlsValues)
            Log.info(Constant.Error(Constant.SUCCESS).get_desc_en())
            return Constant.Error(Constant.SUCCESS)

        Log.debug("Not a file")

        if moduleIndex == -1:
            Log.error(
                Constant.Error(Constant.ERROR_MODULE_NOT_FOUND).get_desc_en())
            return Constant.Error(Constant.ERROR_MODULE_NOT_FOUND)

        if not self.dirPath:  # 目录为空,返回
            Log.error(
                Constant.Error(Constant.ERROR_IMPORT_INPUT).get_desc_en())
            return Constant.Error(Constant.ERROR_IMPORT_INPUT)

        if not os.path.exists(self.dirPath):
            Log.error(
                Constant.Error(Constant.ERROR_DIR_NOT_EXIST).get_desc_en())
            return Constant.Error(Constant.ERROR_DIR_NOT_EXIST)

        for index, title in enumerate(firstRow):
            if index < self.fromIndex:
                continue
            languageIndex = index
            targetLanguage = title
            # print languageIndex
            # print title
            xlsKeys = sheet.col_values(keyIndex)
            del xlsKeys[0]

            xlsModules = sheet.col_values(moduleIndex)
            del xlsModules[0]

            xlsValues = sheet.col_values(languageIndex)
            del xlsValues[0]
            # 文件路径(子目录) 比如; value-zh
            # ├── android
            # │   ├── values-zh
            # │   |	├── strings_device.xml
            # │   |	├── strings_me.xml
            # │   |	├── strings_moment.xml
            # │   ├── values-de
            # │   ├── values-ko
            sub_dir_path = covertTargetPath(self.dirPath, targetLanguage)
            # print sub_dir_path
            if os.path.exists(sub_dir_path):
                XMLParse.update_multi_xml_value(sub_dir_path, xlsKeys,
                                                xlsValues, xlsModules)
        Log.info(Constant.Error(Constant.SUCCESS).get_desc_en())
        return Constant.Error(Constant.SUCCESS)
Example #22
0
import Move
import time
import math
import random
import threading
from tkinter import *
from tkinter import ttk
from tkinter import messagebox

root = Tk()
root.title("A-Star 算法")

MOVE = Move.Move()
ARIT1 = Arithmetic.Arith1()
ARIT2 = Arithmetic.Arith2()
CONSTANT = Constant.Constant()

# 存放初始、目标布局矩阵
group_init = []
group_goal = []

# 存放初始布局到目标布局的移动过程
group_course = []

# 存放 OPEN、CLOSE表内容
group_open = []
group_close = []

# 使用过的所有节点数
COUNT1 = 0