def __init__(self, root, shape):
        """
        Initialize root tkinter window and master GUI window
        """
        Toplevel.__init__(self, root, width=200, height=200)

        self.__shape = shape
        if shape is False:
            self.close()
            return
        self.title('Edit Attributes')

        # copies TAGS to avoid aliasing
        self.__available_attributes = TAGS[:]
        self.container = Frame(self)
        self.container.pack(side=TOP, fill=BOTH, expand=True)
        self.top_frame = None
        self.bottom_frame = None
        self.note_text = None
        self.attributes_list = None
        self.selected_list = None

        self.transient(root)
        logger.info('Creating top frame')
        self.create_top_frame()
        logger.info('Creating bottom frame')
        self.create_bottom_frame()
Example #2
0
 def get_session(self):
     """
     Returns an instance of a session, USERS job to ensure session
     is committed/closed
     """
     logger.info('Getting session')
     return self.__Session()
Example #3
0
 def new_room_btn(self):
     new_room_Btn = self.wait_find_element(*self.room_text_element)
     try:
         new_room_Btn.click()
         logger.info("new_oder_Btn is click")
     except:
         logger.info("进入新添房源界面失败")
 def clear(self):
     """
     Deletes the note
     """
     logger.info('Deleting note')
     self.note_text.delete(1.0, END)
     self.__shape.set_notes('')
Example #5
0
def check_default_value():
    logger.info("start to check_default_value...")
    moc_ins = MocSingleton.get_instance()
    for moc_name in moc_ins.moc_object_list:
        ret, db_para_lst = get_para_lst_db(moc_name)
        if not ret or len(db_para_lst) == 0:
            continue
        logger.info("moc_name:%s, db_para_lst is %s." %
                    (moc_name, db_para_lst))
        ret, configure_para_lst = get_para_lst_configure(moc_name)
        if not ret:
            continue
        logger.info("moc_name:%s, configure_para_lst is %s." %
                    (moc_name, configure_para_lst))

        db_para_set = set(db_para_lst)
        configure_para_set = set(configure_para_lst)
        db_not_in_configure_para = db_para_set - configure_para_set
        configure_not_in_db_para = configure_para_set - db_para_set
        logger.info(
            "moc_name:%s, configure_not_in_db_para is %s, db_not_in_configure_para is %s."
            % (moc_name, configure_not_in_db_para, db_not_in_configure_para))
        persist_compare_result(moc_name, db_not_in_configure_para,
                               configure_not_in_db_para)
    logger.info("check_default_value end...")
Example #6
0
    def _make_dataset(root, quality, mode):
        assert (quality == 'fine' and mode in ['train', 'val', 'test']) or \
               (quality == 'coarse' and mode in ['train', 'train_extra', 'val'])

        if quality == 'coarse':
            img_dir_name = 'leftImg8bit_trainextra' if mode == 'train_extra' else 'leftImg8bit_trainvaltest'
            mask_path = os.path.join(root, 'gtCoarse', 'gtCoarse', mode)
            mask_postfix = '_gtCoarse_labelIds.png'
        else:
            mask_path = os.path.join(root, 'gtFine', mode)
            mask_postfix = '_gtFine_labelIds.png'

        img_path = os.path.join(root, 'leftImg8bit', mode)
        print(img_path)
        logger.info(img_path)
        assert os.listdir(img_path) == os.listdir(mask_path)
        items = []
        categories = os.listdir(img_path)
        for c in categories:
            c_items = [
                name.split('_leftImg8bit.png')[0]
                for name in os.listdir(os.path.join(img_path, c))
            ]
            for it in c_items:
                item = (os.path.join(img_path, c, it + '_leftImg8bit.png'),
                        os.path.join(mask_path, c, it + mask_postfix))
                items.append(item)

        return items
Example #7
0
    def run(self, custom_classfy):
        """
        遍历config文件和音频路径,将其新平台文本格式信息写到output/result.txt文件中
        :param custom_classfy: 自定义分包条数,默认按spk音频数分包
        """
        logger.debug('遍历wav_name,text信息')
        wav_suf = 'wav'
        counter = 0
        wavs_info_map = {}

        for SPK, wav_name, content in self.get_info():  # 遍历说话人id,音频名,音频内容 信息
            logger.debug('[wav_info] %s - %s - %s ' % (SPK, wav_name, content))

            if wav_name not in self.wav_time_map:
                logger.warning('[%s] 未找到音频' % wav_name)
                continue

            wav_time = self.wav_time_map.get(wav_name)
            if not wav_time:
                continue

            wav_info = [  # 填充新平台文本格式
                {
                    "Wav_name": wav_name,
                    "Length_time": wav_time,
                    "Data": [
                        {
                            "text": content,
                            "start_time": 0,
                            "end_time": wav_time
                        }
                    ],
                    "Wav_suf": wav_suf
                }
            ]

            if custom_classfy:  # 指定分包数的模式
                id = f'line_{counter}'
                if id not in wavs_info_map:
                    wavs_info_map[id] = [wav_info]

                else:
                    if len(wavs_info_map[id]) == custom_classfy - 1:
                        counter += 1

                    wavs_info_map[id].append(wav_info)

            else:  # 默认分包模式
                if SPK not in wavs_info_map:
                    wavs_info_map[SPK] = [wav_info]
                else:
                    wavs_info_map[SPK].append(wav_info)

        logger.info(
            '处理完毕! 共 %s 批次 [%s]' % (len(wavs_info_map.keys()), wavs_info_map.keys()) if not custom_classfy else (
                counter, len(reduce(lambda x, y: x + y, wavs_info_map.values()))))

        with open(self._save_path, 'w', encoding='utf-8') as f:
            for key, value in wavs_info_map.items():
                f.write(json.dumps(value, ensure_ascii=False) + '\n')
 def test01(self, Case_Info):
     '''
     登录
     :return:
     '''
     print(Case_Info)
     TestCaseAPi.index += 1
     casename, method, apiname, data, extract, duanyan, headers ,host= Case_Info['接口用例名称'], Case_Info['请求方式'], \
                                                                  Case_Info['接口url'], Case_Info['请求入参'], \
                                                                  Case_Info['提取变量'], Case_Info['检查点'], \
                                                                  Case_Info['请求头信息'],Case_Info['域名'],
     #excel里面字典类型数据转化
     data = json_loads(data)
     headers = json_loads(headers)
     duanyan = json_loads(duanyan)
     extract = json_loads(extract)
     url = host + apiname
     res = self.request.sendRequest(method=method,
                                    url=url,
                                    data=data,
                                    tiqu=extract,
                                    headers=headers,
                                    index=TestCaseAPi.index)  # 3.发请求过程
     result = self.request.validate(yuqi=duanyan,
                                    shiji=res)  # 返回元组(1布尔值,2验证信息)
     logger.info(result[1])
     self.assertTrue(result[0])  # 4.结果验证
     '''拿到响应值,写入到excel,输入到报告'''
Example #9
0
    def save_as_json(self, save_all=False):
        """
        Save all selected objects on the plot, asking for a filename first

        if ``save_all`` is specified and set to ``True``, the function will save **all**
        shapes across **all** plots in the program.
        """
        logger.info('Notifying JSON to save as')
        # Save to a file entered by user, saveAll saves ALL objects across canvas
        # and cannot be called as a normal save(must always be save as)
        if self.__shapemanager.get_selected_count() > 0:
            options = dict()
            options['defaultextension'] = '.json'
            options['filetypes'] = [('CALIPSO Data files', '*.json'),
                                    ('All files', '*')]
            f = tkFileDialog.asksaveasfilename(**options)
            if f == '':
                logger.info("cancelling save as json")
                return False
            if save_all:
                self.__shapemanager.save_all_json(f)
            else:
                self.__shapemanager.save_json(f)
        else:
            logger.error('No selected objects found, canceling save')
            tkMessageBox.showerror('save as JSON', 'No objects to be saved')
Example #10
0
 def reset(self):
     """
     Reset all objects on the screen, move pan to original
     """
     logger.info("Resetting plot")
     self.__shapemanager.reset()  # reset all shapes
     self.__toolbar.home()  # proc toolbar function to reset plot to home
Example #11
0
    def import_json_db():
        """
        Import the contents of a JSON file to the database, works hand in hand
        with the ``export_json_db`` class method. This will allows users to share
        their database without needing to manually move their db file.
        :return:
        """

        options = dict()
        options['defaultextension'] = '.zip'
        options['filetypes'] = [('CALIPSO Data Archive', '*.zip'),
                                ('All files', '*')]
        options['initialdir'] = CONF.session_db.dir()
        fl = tkFileDialog.askopenfilename(**options)
        if fl != '':
            log_fname = fl.rpartition('/')[2]
            logger.info('Importing database from \'%s\'' % log_fname)
            success = db.import_from_json(fl)
            if success:
                logger.info('Success, JSON file imported')
                tkMessageBox.showinfo(
                    'database', 'shapes from %s imported ' % log_fname +
                    '(note: new tags have been assigned to these shapes!)')
            else:
                logger.error('Invalid JSON file')
                tkMessageBox.showerror('database',
                                       'Invalid JSON file %s' % log_fname)
Example #12
0
 def free(self):
     """
     Notify base class window has been destroyed.
     """
     logger.info('Closing AdvancedSearchDialog')
     AdvancedSearchDialog.singleton = False
     self.destroy()
Example #13
0
def handle_douban_id(redis_con, douban_id):
    try:
        logger.info('id %s' % douban_id)
        url = detail_url % douban_id
        # url = '/data/project/self/bookMenu/detail.html'
        response_text = get_page_content(url)
        # response_text = open('/data/project/self/bookMenu/detail.html', 'r').read()
        soup = get_soup(response_text)
        info = BookDetailInfo()
        info.name = soup.find(attrs={
            'property': 'v:itemreviewed'
        }).text.strip()
        info.author_name = fetch_author_name(soup)
        info.press_name = (lambda x: x.next_sibling.strip()
                           if x is not None else None)(soup.find(
                               'span', string='出版社:'))
        info.origin_book_name = (lambda x: x.next_sibling.strip()
                                 if x is not None else None)(soup.find(
                                     'span', string='原作名:'))
        info.translator_name = (
            lambda x: x.next_sibling.next_sibling.text.strip()
            if x is not None else None)(soup.find('span', string=' 译者'))
        info.page_count = (lambda x: x.next_sibling.strip()
                           if x is not None else None)(soup.find('span',
                                                                 string='页数:'))
        info.price = (lambda x: x.next_sibling.strip()
                      if x is not None else None)(soup.find('span',
                                                            string='定价:'))
        tag_a_2 = soup.find(
            'a', attrs={'href': re.compile("https://book.douban.com/series/")})
        info.series_id = (lambda x: x['href'].split('/')[-1]
                          if x is not None else None)(tag_a_2)
        info.series_name = (lambda x: x.text.strip()
                            if x is not None else None)(tag_a_2)
        info.isbn = (lambda x: x.next_sibling.strip()
                     if x is not None else None)(soup.find('span',
                                                           string='ISBN:'))
        info.publish_year = (lambda x: x.next_sibling.strip()
                             if x is not None else None)(soup.find(
                                 'span', string='出版年:'))
        info.score = (lambda x: Decimal(x.text.strip())
                      if x is not None else None)(
                          soup.find(attrs={'property': 'v:average'}))
        info.menu = (lambda x: x.text.strip() if x is not None else None)(
            soup.find(attrs={'id': 'dir_' + douban_id + '_full'}))
        info.tags = '|'.join(
            map(lambda x: x.text.strip(),
                soup.find_all('a', attrs={'href': re.compile("/tag/")})))
        info.douban_id = douban_id
        logger.info(
            json.dumps(info,
                       sort_keys=True,
                       indent=2,
                       cls=AlchemyEncoder,
                       encoding='utf-8',
                       ensure_ascii=False))
        BookDetailInfo.add(info)
    except Exception as e:
        logger.error('--->%s', e)
        redis_con.lpush(QUEUE_DOUBAN_ID_EXCEPTION, douban_id)
Example #14
0
 def reset(self):
     """
     Reset the view of the tree within the import window, clears the stack as well
     """
     logger.info('Resetting tree view & stack')
     self.__display_all()
     self.__stack.clear()
Example #15
0
 def room_type(self, room_type_Value):
     room_type_text = self.wait_find_element(*self.room_type_description_element)  # 户型描述输入
     room_type_text.click()
     AdbShell.input_text(room_type_Value)
     # room_type_text.send_keys(room_type_Value)
     logger.info("RoomTypeText is setValues!")
     self.get_screeShot()
Example #16
0
 def __repr__(self):
     """
     Represent the database class as a JSON object. Useful as our program
     already supports JSON reading, so simply parse out the database as
     separate JSON 'files'
     """
     data = {}
     for key in constants.plot_type_enum:
         data[key] = {}
     data[self.plot] = {
         self.tag: {
             'color': self.color,
             'attributes': self.attributes,
             'id': self.id,
             'coordinates': self.coordinates,
             'btime': self.begin_time.strftime(DATEFORMAT),
             'etime': self.end_time.strftime(DATEFORMAT),
             'blat': self.begin_lat,
             'elat': self.end_lat,
             'balt': self.begin_alt,
             'ealt': self.end_alt,
             'notes': self.notes
         }
     }
     data['time'] = self.time_.strftime(DATEFORMAT)
     data['hdffile'] = self.hdf
     logger.info('Converting unicode to ASCII')
     return byteify(json.dumps(data))
Example #17
0
    def dump_to_json(self, zip_fname):
        """
        Dump the contents of the database into a JSON file with the specific format
        of DatabasePolygon. Creates a directory '{PROJECT}/tmp' and exports all db
        objects to it, then zips the directory and deletes tmp. Returns ``True`` on
        success, ``False`` otherwise

        :param str zip_fname: name of the zip file
        :rtype: bool
        """
        session = self.__Session()
        # tmp should not previously exist because we don't want files we didn't
        # add ourselves
        print(PATH)
        if os.path.exists(PATH + '/../tmp'):
            logger.error('Tmp directory should not exist, will not zip')
            return False
        logger.info('Creating /tmp and exporting shapes')
        os.makedirs(PATH + '/../tmp')
        for shape in session.query(DatabasePolygon).order_by(
                DatabasePolygon.tag):
            self.encode(PATH + '/../tmp/' + shape.tag + '.json', str(shape))
        logger.info('Packing /tmp into %s' % zip_fname)
        zipf = zipfile.ZipFile(zip_fname, 'w')
        zipdir(PATH + '/../tmp', zipf)
        zipf.close()
        shutil.rmtree(PATH + '/../tmp')
        session.close()
        return True
Example #18
0
 def free(self):
     """
     Free the window and notify ``ImportDialog`` that a new window can be created now
     """
     logger.info('Closing ExtractColumnsDialog')
     self.shared_data.data = {'free': True}
     self.destroy()
Example #19
0
 def advanced_prompt(self):
     logger.info('Opening advanced search window')
     if (not AdvancedSearchDialog.singleton):
         AdvancedSearchDialog(self, self.__root). \
             wm_iconbitmap(ICO)
     else:
         logger.warning('Found existing advanced search window, canceling')
Example #20
0
    def plot_point(self, event):
        """
        Plot a single point to the screen for the current shape object,
        if other points exist, a line is drawn between then until a
        polygon is formed

        :param event: A ``matplotlib.backend_bases.MouseEvent`` passed object
        """
        if self.__current_plot == Plot.baseplot:
            logger.warning('Cannot draw to the base plot')
            return
        if event.xdata and event.ydata:
            logger.info('Plotting point at %.5f, %.5f' %
                        (event.xdata, event.ydata))
            check = self.__current_list[-1].plot_point(
                event, self.__current_plot, self.__hdf, self.__figure,
                ShapeManager.outline_toggle)
            self.__drawing = True

            if check:
                self.__current_list[-1].set_tag(self.generate_tag())
                self.__current_list.append(Shape(self.__canvas))
                self.__drawing = False
                self.__canvas.show()

        else:
            logger.error("Point to plot is out or range, skipping")
Example #21
0
    def select_from_tag(self, tag):
        """
        Highlight the shape specified by ``tag``. Ensures to reset
        any other objects that may be highlighted. Not to be confused
        with ``select(self, event)``, which is for multiple selections
        via event objects

        :param str tag: The tag of the object
        """
        if tag == "" and self.__selected_shapes:
            logger.info('Disabling selection for all shapes')
            for x in self.__selected_shapes:
                # The shape may have been removed, so we should ensure it exists
                if x: x.set_highlight(False)
            self.__selected_shapes = []
            self.__canvas.show()
            return
        for shape in self.__current_list[:-1]:
            if shape.get_tag() == tag:
                logger.info('Selecting %s' % tag)
                for x in self.__selected_shapes:
                    if x: x.set_highlight(False)
                self.__selected_shapes.append(shape)
                shape.set_highlight(True)
                break
        self.__canvas.show()
Example #22
0
    def render(self):
        """
        Errors checks all user entered parameters and calls ``set_plot`` from *Calipso*
        """
        '''
        if self.plot_type.get() == 0:
            logger.error('No plot type set')
            tkMessageBox.showerror('toolswindow', 'No plot type specified')
            return
        '''

        if not self.__parent.get_file():
            logger.error('No file entered')
            tkMessageBox.showerror('toolswindow', 'No file loaded')
            return

        time_range = ToolsWindow.__check_range(0, 1000, 5,
                                               self.begin_range_entry,
                                               self.end_range_entry)
        alt_range = ToolsWindow.__check_range(0, 20, 5,
                                              self.begin_alt_range_entry,
                                              self.end_alt_range_entry)

        logger.info('Grabbing range and safe checking')
        if time_range is None or alt_range is None:
            return

        logger.info('Calling plot')
        self.__parent.set_plot(self.__parent.plot_type.get(),
                               xrange_=time_range,
                               yrange=alt_range)
Example #23
0
    def fill_rectangle(self, event):
        """
        Informs the correct shape list's blank object to draw a rectangle to the screen
        using the provided coordinates

        :param event: A backend passed ``matplotlib.backend_bases.MouseEvent`` object
        """
        if self.__current_plot == Plot.baseplot:
            logger.warning("Cannot draw to BASE_PLOT")
            return
        if event.xdata and event.ydata:
            if len(self.__current_list[-1].get_coordinates()) is 0:
                return
            logger.debug('Filling: %d, %d' % (event.xdata, event.ydata))
            logger.info('Creating rectangle')
            self.__current_list[-1].fill_rectangle(event, self.__current_plot,
                                                   self.__hdf, self.__figure,
                                                   ShapeManager.outline_toggle)
            self.__current_list[-1].set_tag(self.generate_tag())
            self.__current_list.append(Shape(self.__canvas))
            self.__canvas.show()
        else:
            logger.error('Bounds out of plot range, skipping')
            self.__current_list[-1].set_coordinates([])
            self.__canvas._tkcanvas.delete(self.__current_list[-1].lastrect)
Example #24
0
 def tenant_name(self, tenant_name_value):
     tenant_name_text = self.wait_find_element(*self.tenant_name_element)  # 户型描述输入
     tenant_name_text.click()
     AdbShell.input_text(tenant_name_value)
     # print("入住人姓名:",tenant_name_value)
     # tenant_name_text.send_keys(tenant_name_value)
     logger.info("TenantNameText is setValues!")
Example #25
0
def train(train_loader, net, optimizer, epoch, all_iter, accumulation_steps):
    net.train()
    train_loss = 0.0
    for i, (inputs, targets) in enumerate(train_loader):
        assert inputs.size()[2:] == targets[0].size()[1:]
        inputs = Variable(inputs).cuda()
        targets0 = Variable(targets[0]).cuda()
        targets1 = Variable(targets[1]).cuda()
        targets2 = Variable(targets[2]).cuda()
        targets3 = Variable(targets[3]).cuda()
        targets4 = Variable(targets[4]).cuda()

        loss = net(inputs, [targets0, targets1, targets2, targets3, targets4])

        train_loss += loss.item()
        loss.backward()
        optimizer.step()
        optimizer.zero_grad()

        if (i + 1) % 20 == 0:
            localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            logger.info(
                '[%s], [epoch %d], [iter %d / %d], [train loss %.5f]' %
                (localtime, epoch, i + 1, len(train_loader), train_loss /
                 (i + 1)))
Example #26
0
    def send(self):
        self.msg['Subject'] = self.title
        self.msg['From'] = self.sender
        self.msg['To'] = self.receiver

        # 邮件正文
        if self.message:
            self.msg.attach(MIMEText(self.message))

        # 添加附件,支持多个附件(传入list),或者单个附件(传入str)
        if self.files:
            if isinstance(self.files, list):
                for f in self.files:
                    self._attach_file(f)
            elif isinstance(self.files, str):
                self._attach_file(self.files)

        # 连接服务器并发送
        try:
            smtp_server = smtplib.SMTP(self.server)  # 连接sever
        except (gaierror and error) as e:
            logger.exception('发送邮件失败,无法连接到SMTP服务器,检查网络以及SMTP服务器. %s', e)
        else:
            try:
                smtp_server.login(self.sender, self.password)  # 登录
            except smtplib.SMTPAuthenticationError as e:
                logger.exception('用户名密码验证失败!%s', e)
            else:
                smtp_server.sendmail(self.sender, self.receiver.split(';'),
                                     self.msg.as_string())  # 发送邮件
            finally:
                smtp_server.quit()  # 断开连接
                logger.info('发送邮件"{0}"成功! 收件人:{1}。如果没有收到邮件,请检查垃圾箱,'
                            '同时检查收件人地址是否正确'.format(self.title, self.receiver))
Example #27
0
 def choose_room(self):
     choose_room = self.wait_find_element(*self.choose_room_element)
     # print(choose_room)
     choose_room.click()
     room_name = self.wait_find_element(*self.test_room_element)
     # print(room_name)
     room_name.click()
     logger.info("ChooseRoom is click")
Example #28
0
def rm_backup_db_7_day_ago(dst):
    time_7_day_ago = (datetime.datetime.now() -
                      datetime.timedelta(days=7)).strftime('%Y_%m_%d_%H_%M_%S')
    for dir_time in os.listdir(dst):
        if dir_time <= time_7_day_ago:
            logger.info("rm backup db file 7 day ago: %s" %
                        os.path.join(dst, dir_time))
            shutil.rmtree(os.path.join(dst, dir_time))
Example #29
0
 def _attach_file(self, att_file):
     """将单个文件添加到附件列表中"""
     att = MIMEText(open('%s' % att_file, 'rb').read(), 'plain', 'utf-8')
     att["Content-Type"] = 'application/octet-stream'
     file_name = re.split(r'[\\|/]', att_file)
     att["Content-Disposition"] = 'attachment; filename="%s"' % file_name[-1]
     self.msg.attach(att)
     logger.info('attach file {}'.format(att_file))
 def authorized_identity_btn(self):
     # 被授权人身份按钮
     authorized_identity_btn = self.wait_find_element(*self.authorized_identity_btn_element)
     authorized_identity_btn.click()
     # 被授权人身份(列表第二个元素,保洁)
     authorized_identity = self.wait_find_element(*self.authorized_identity_element)
     authorized_identity.click()
     logger.info("authorized_identity is click")