Beispiel #1
0
import bin.forms as Forms
from bin.cache import Cache

# monkey patch all the things
from gevent import monkey
monkey.patch_all()
from psycogreen.gevent import patch_psycopg
patch_psycopg()

# hook like a true pirate
@hook('after_request')
def enable_cors():
    response.headers['X-Pirate'] = 'Yarrr'

Debug('Loading config', info=True)
cfg = Config()
cfg.reload()

logging.basicConfig(format='localhost - - [%(asctime)s] %(message)s', level=logging.DEBUG)
log_handler = logging.handlers.RotatingFileHandler('debug.out', maxBytes=2048576)

log = logging.getLogger('file_logger')
if cfg.get('General', 'debug'):
    log.addHandler(log_handler)
    debug(True)

# Authentication, Authorization and Accounting. Use users.json and roles.json in users/
Debug('Loading AAA', info=True)
aaa = Cork('users')

Debug('Loading bottle app', info=True)
Beispiel #2
0
import wtforms as wtf
from wtforms import Form
from bin.config import Config

CONFIG = Config()
CONFIG.reload()

class RegistrationForm(Form):
    username = wtf.StringField('Username', [wtf.validators.Length(min=4, max=25)])
    email = wtf.StringField('Email Address', [wtf.validators.Length(min=6, max=35)])
    password = wtf.PasswordField('New Password', [
        wtf.validators.DataRequired(),
        wtf.validators.EqualTo('confirm', message='Passwords must match')
    ])
    confirm = wtf.PasswordField('Repeat Password')
    accept_tos = wtf.BooleanField('I accept the TOS', [wtf.validators.DataRequired()])

def validate_protocol(form, field):
    protocols = ['HTTP(s)', 'FTP', 'SMB', 'LOCAL']
    if not field.data in protocols:
        raise wtf.ValidationError('Protocol \'%s\' is not known.' % field.data)

def validate_crawlinterval(form, field):
    pass

def validate_authtype(form, field):
    pass

def validate_crawlua(form, field):
    pass
Beispiel #3
0
class RunCheck(QObject):
    progress_message = pyqtSignal(int, str)
    stop_signal = pyqtSignal()

    def __init__(self, log, base_path, parent=None):
        super(RunCheck, self).__init__(parent)
        self.log = log
        self.base_path = base_path
        self.link_path = os.path.join(self.base_path, 'config', 'linkcheck',
                                      'link.xls')
        self.config_path = os.path.join(self.base_path, 'config', 'linkcheck',
                                        'config.ini')
        self.data = {}

    def run(self):
        new_link_excel = ''
        try:
            self.progress_message.emit(5, '正在初始化...')
            self.data = Config(self.log, self.config_path).read()
            self.progress_message.emit(10, '开始下载和解压...')
            uncompressed_path = self.download_and_uncompress()
            self.progress_message.emit(45, '下载解压完成,获取excel链接')

            link = GetLink(self.log, self.base_path, self.link_path)
            max_row = link.get_link(self.data['checkversion'],
                                    self.data['checklanguage'])
            new_link_excel = link.new_excel_path
            self.progress_message.emit(60, '开始检查excel链接')
            _progress = float(max_row) / 40

            if 'click_tb' in self.data.keys() and self.data['click_tb'] == '1':
                self.progress_message.emit(60, '通过点击TB界面获取链接')
            for row in range(1, max_row):
                strings = link.read_data_by_row(row)
                # 增加点击TB界面获取链接的方式,2019.03.26 ygx
                if 'click_tb' in self.data.keys(
                ) and self.data['click_tb'] == '1':
                    result = 'success'
                else:
                    check = CheckLink(self.log, strings, uncompressed_path,
                                      self.base_path)
                    result = check.check()
                self.write_result(row, result, new_link_excel)
                progress = 60 + row / _progress
                if result == 'Failed':
                    self.progress_message.emit(
                        progress, '第%d行检测到链接不相等\n文档链接:%s\n程序链接:%s' %
                        (row + 1, check.failed_excel_link,
                         check.failed_program_link))
                elif row % _progress == 0 and row / _progress != 0:
                    self.progress_message.emit(progress, '')
            self.progress_message.emit(100, '检查完成')
            # 设置列宽
            self.set_col_width(new_link_excel)
        except Exception as e:
            self.progress_message.emit(100, '检查失败:\n%s' % e.args[0])
            raise Exception('检查失败\n%s' % e.args[0])
        finally:
            self.progress_message.emit(100, new_link_excel)

    def download_and_uncompress(self):
        download_flag = '0' if 'download' not in self.data.keys(
        ) else self.data['download']
        download = Download(self.log)
        if download_flag != '0':
            package_path = download.download(self.data['downloadpath'],
                                             r'C:\setup\package',
                                             _filter=self.data['version'])
        else:
            package_path = [self.data['specifypath']]

        uncompressed_path = []
        for package in package_path:
            if os.path.isdir(package):
                uncompressed_path.append(package)
            else:
                tool_path = os.path.join(self.base_path, 'tools',
                                         'innounp.exe')
                uncompressed_path.append(
                    download.uncompress(package, package[:-4], tool_path))
        return uncompressed_path

    def get_result_path(self):
        now_time = time.strftime('%Y%m%d%H%M%S', time.localtime())
        return os.path.join(self.base_path, 'result', 'linkcheck',
                            'result_' + now_time + '.xls')

    @staticmethod
    def write_result(row, result, excel_path):
        excel = WriteExcel(excel_path)
        excel.write_row_by_title(row, result=result)

    @staticmethod
    def set_col_width(excel_path):
        excel = WriteExcel(excel_path)
        excel.set_col_width(ID=8888, link=18000, language=5000)
Beispiel #4
0
class SettingUI(QWidget):
    def __init__(self, log, run_path, parent=None):
        super(SettingUI, self).__init__(parent)
        self.log = log
        self.run_path = run_path
        self.config_path = os.path.join(run_path, 'config', 'linkcheck',
                                        'config.ini')
        self.data = Config(log, self.config_path).read() if os.path.exists(
            self.config_path) else None

        # qt widget
        self.add_version_edit = QLineEdit()
        self.add_version_btn = QPushButton('添加')

        self.radio_specify = QRadioButton("指定安装包或解压包")
        self.edit_specify = QLineEdit()
        self.specify_btn_file = QPushButton('文 件')
        # self.specify_btn_file.setStyleSheet(STYLE)
        self.specify_btn_dir = QPushButton('文件夹')
        # self.specify_btn_dir.setStyleSheet(STYLE)

        self.radio_download = QRadioButton('下载安装包')
        self.edit_download = QLineEdit()
        self.download_btn_dir = QPushButton('浏览')
        # self.download_btn_dir.setStyleSheet(STYLE)

        self.click_TB_ui_checkbox = QCheckBox('通过点击TB界面获取链接')

        self.group_box = QButtonGroup()
        self.group_box.addButton(self.radio_specify)
        self.group_box.addButton(self.radio_download)

        # self.mail_label = M

        # default data
        self.checked_style = 'background-color:#4BAEB3;color:#FFFFFF;'
        self.display_versions = ['trial', 'ad', 'efrontier', 'xagon']
        self.display_languages = [
            'All', '德语', '英语', '波兰语', '葡萄牙语', '西班牙语', '日语', '韩语', '法语', '意大利语',
            '繁体中文', '简体中文'
        ]
        self.display_language_buttons = []
        self.checked_versions = []
        self.checked_languages = []

        self.download = 0
        self.initial_data()
        self.ui()

    def initial_data(self):
        if self.data and 'versions' in self.data.keys():
            versions = self.data['versions']
            self.display_versions = [
                versions
            ] if ',' not in versions else versions.split(',')
        if self.data and 'languages' in self.data.keys():
            languages = self.data['languages']
            self.display_languages = [
                languages
            ] if ',' not in languages else languages.split(',')
        if self.data and 'checkversion' in self.data.keys():
            checked_versions = self.data['checkversion']
            self.checked_versions = [
                checked_versions
            ] if ',' not in checked_versions else checked_versions.split(',')
        if self.data and 'checklanguage' in self.data.keys():
            checked_languages = self.data['checklanguage']
            if checked_languages == 'All':
                self.checked_languages = [i for i in self.display_languages]
            else:
                self.checked_languages = [
                    checked_languages
                ] if ',' not in checked_languages else checked_languages.split(
                    ',')

        if self.data and 'download' in self.data.keys():
            download = self.data['download']
            self.download = 0 if download == '0' else 1
        if self.data and 'downloadpath' in self.data.keys():
            self.edit_download.setText(self.data['downloadpath'])

        if self.data and 'click_tb' in self.data.keys():
            self.click_TB_ui_checkbox.setChecked(
                True) if self.data['click_tb'] == '1' else None

        self.radio_download.setChecked(
            True) if self.download else self.radio_specify.setChecked(True)
        self.radio_logic()

        if self.data and 'specifypath' in self.data.keys():
            self.edit_specify.setText(self.data['specifypath'])

    def ui(self):
        layout = QVBoxLayout(self)
        layout.addSpacing(10)
        layout.addWidget(QLabel('检查版本:'))
        layout.addSpacing(10)
        layout.addLayout(self.display_versions_layout())
        layout.addSpacing(20)
        layout.addWidget(QLabel('检查语言:'))
        layout.addLayout(self.display_languages_layout())
        layout.addSpacing(20)

        layout.addWidget(self.radio_specify)
        layout.addLayout(self.specify_layout())
        layout.addWidget(self.radio_download)
        layout.addLayout(self.download_layout())
        layout.addWidget(self.click_TB_ui_checkbox)
        layout.addSpacing(20)
        layout.addStretch()

        # ui settings
        self.setStyleSheet(STYLE)
        self.setBackgroundColor(QColor('#FFFFFF'))
        # signals
        self.signals()

    def setBackgroundColor(self, color):
        pal = QPalette()
        pal.setColor(QPalette.Background, color)
        self.setPalette(pal)
        self.setAutoFillBackground(True)

    def display_versions_layout(self):
        layout = QHBoxLayout()
        layout.addSpacing(40)
        for i in range(len(self.display_versions)):
            button = QPushButton(self.display_versions[i])
            button.setStyleSheet(CHOICE_BUTTON)
            # 按钮加宽
            if len(self.display_versions[i]) > 5:
                button.setFixedWidth(10 * (len(self.display_versions[i]) - 5) +
                                     60)
            # 判断按钮初始状态
            if self.display_versions[i] in self.checked_versions:
                button.setStyleSheet(self.checked_style)
            button.clicked.connect(partial(self.display_btn_click, button))
            layout.addWidget(button)
        layout.addStretch()
        return layout

    def display_languages_layout(self):
        layout = QGridLayout()
        _all = False  # 全选标志
        for i in range(len(self.display_languages)):
            button = QPushButton(self.display_languages[i])
            button.setStyleSheet(CHOICE_BUTTON)
            self.display_language_buttons.append(button)
            # 检查是否是全选标志
            if _all:
                button.setStyleSheet(self.checked_style)
            elif button.text() in self.checked_languages:
                button.setStyleSheet(self.checked_style)

            # 处理全选标志
            if self.display_languages[i] == 'All' and self.display_languages[
                    i] in self.checked_languages:
                button.setStyleSheet(self.checked_style)
                _all = True

            # 按钮布局
            half_count = len(self.display_languages) / 2 + len(
                self.display_languages) % 2
            if i < half_count:
                layout.addWidget(button, 0, i)
                layout.setColumnStretch(i, 0)  # 设置按钮不拉伸
            else:
                layout.addWidget(button, 1, i - half_count)
            button.clicked.connect(partial(self.display_btn_click, button))
        layout.setColumnStretch(half_count, 10)  # 设置按钮不拉伸
        layout.setContentsMargins(40, 10, 10, 10)  # 设置按钮边间距
        return layout

    def specify_layout(self):
        layout = QHBoxLayout()
        layout.addWidget(self.edit_specify)
        layout.addWidget(self.specify_btn_file)
        layout.addWidget(self.specify_btn_dir)
        return layout

    def download_layout(self):
        layout = QHBoxLayout()
        layout.addWidget(self.edit_download)
        layout.addWidget(self.download_btn_dir)
        return layout

    def radio_logic(self):
        if self.radio_specify.isChecked():
            self.download = 0
            self.edit_download.setEnabled(False)
            self.download_btn_dir.setEnabled(False)
            self.edit_specify.setEnabled(True)
            self.specify_btn_file.setEnabled(True)
            self.specify_btn_dir.setEnabled(True)

            self.download_btn_dir.setStyleSheet(DISABLE_BUTTON)
            self.specify_btn_file.setStyleSheet(STYLE)
            self.specify_btn_dir.setStyleSheet(STYLE)
        else:
            self.download = 1
            self.edit_download.setEnabled(True)
            self.download_btn_dir.setEnabled(True)
            self.edit_specify.setEnabled(False)
            self.specify_btn_file.setEnabled(False)
            self.specify_btn_dir.setEnabled(False)

            self.download_btn_dir.setStyleSheet(STYLE)
            self.specify_btn_file.setStyleSheet(DISABLE_BUTTON)
            self.specify_btn_dir.setStyleSheet(DISABLE_BUTTON)

    def signals(self):
        self.radio_specify.clicked.connect(self.radio_logic)
        self.radio_download.clicked.connect(self.radio_logic)
        self.specify_btn_file.clicked.connect(self.specify_btn_file_click)
        self.specify_btn_dir.clicked.connect(self.specify_btn_dir_click)
        self.download_btn_dir.clicked.connect(self.download_btn_dir_click)

    def save(self):
        # check data
        if not self.checked_versions:
            raise IOError('请选择要检查的版本')
        if not self.checked_languages:
            raise IOError('请选择要检查的语言')
        if self.download:
            if not self.edit_download.text():
                raise IOError('请指定安装包下载目录')
        else:

            if not self.edit_specify.text():
                raise IOError('请指定安装包/解压文件的目录')
        if self.click_TB_ui_checkbox.isChecked():
            click_tb = '1'
        else:
            click_tb = '0'

        data = {
            'CheckVersion': self.checked_versions,
            'CheckLanguage': self.checked_languages,
            'SpecifyPath': self.edit_specify.text(),
            'download': '1' if self.download else '0',
            'DownloadPath': self.edit_download.text(),
            'click_tb': click_tb
        }
        download_versions = []
        for version in self.checked_versions:
            if version == 'trial':
                download_versions.append('Trial.exe')
            else:
                download_versions.append('Trial_' + version + '.exe')
        data['version'] = download_versions
        config = Config(self.log, self.config_path)
        config.write(data, 'LinkConfig')

    def display_btn_click(self, btn):
        if isinstance(btn, QPushButton):
            name = btn.text()
        else:
            raise IOError('display_btn_click需要传递一个按钮对象')

        # 处理全选/全不选
        if name == 'All' and name in self.checked_languages:
            for button in self.display_language_buttons:
                button.setStyleSheet(CHOICE_BUTTON)
                self.checked_languages = []
            return
        elif name == 'All' and name not in self.checked_languages:
            for button in self.display_language_buttons:
                button.setStyleSheet(self.checked_style)
                self.checked_languages = [i for i in self.display_languages]
            return

        # 处理其它语言/版本
        if name in self.display_versions:
            if name in self.checked_versions:
                self.checked_versions.remove(name)
                btn.setStyleSheet(CHOICE_BUTTON)
            else:
                self.checked_versions.append(name)
                btn.setStyleSheet(self.checked_style)
        else:
            if name in self.checked_languages:
                self.checked_languages.remove(name)
                btn.setStyleSheet(CHOICE_BUTTON)
                if 'All' in self.checked_languages:
                    self.checked_languages.remove('All')
                    self.display_language_buttons[0].setStyleSheet(
                        CHOICE_BUTTON)
            else:
                self.checked_languages.append(name)
                btn.setStyleSheet(self.checked_style)
                if len(self.checked_languages) == len(
                        self.display_languages) - 1:
                    self.checked_languages.append('All')
                    self.display_language_buttons[0].setStyleSheet(
                        self.checked_style)

    def specify_btn_file_click(self):
        file_name, file_type = QFileDialog.getOpenFileName(
            self, '选择安装包', './', '*.exe')
        self.edit_specify.setText(file_name)

    def specify_btn_dir_click(self):
        file_name = QFileDialog.getExistingDirectory(self, '选择解压包路径', '.')
        self.edit_specify.setText(file_name)

    def download_btn_dir_click(self):
        file_name = QFileDialog.getExistingDirectory(self, '选择安装包路径', '.')
        self.edit_download.setText(file_name)
Beispiel #5
0
import logging
import os

from bin.config import Config

config = Config(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/conf/config.ini')

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(levelname)s %(filename)s[line:%(lineno)d] %(message)s',
                    datefmt='%d %b %Y %H:%M:%S')
Beispiel #6
0
class CheckLink:
    def __init__(self, log, strings, package_path, base_path):
        self.log = log
        self.strings = strings
        self.package_path = package_path
        self.language_config_path = os.path.join(base_path, 'config',
                                                 'linkcheck', 'language.ini')
        self.config = Config(self.log, self.language_config_path)

        self.language, self.version = self.get_language_version()
        self.package_path = self.get_package_path()
        self.id = strings['ID'] if 'ID' in strings.keys() else None
        self.link = strings['link'] if 'link' in strings.keys() else None
        # self.language_chinese = strings['language'] if 'language' in strings.keys() else None
        self.outer_link_id = [
            'CTPANL', 'STARTP', 'UNINST', 'INSTALL', 'UNINSTALL',
            'HELP_ONLINE', 'ID_LINK_BUY_', 'ID_LINK_HOME_BUY'
        ]
        self.share_net = ['email', 'google+', 'twitter', 'facebook']

        self.failed_excel_link = ''
        self.failed_program_link = ''

    def get_package_path(self):
        version = self.version if self.version == 'trial' else 'trial_' + self.version
        if isinstance(self.package_path, list):
            for package in self.package_path:
                if package.lower().endswith(version):
                    break
            else:
                raise IOError('No found version package path:%s' %
                              self.version)
            return package
        else:
            return self.package_path

    def get_language_version(self):
        if self.strings['language']:
            language = self.strings['language']
            if language == 'xagon':
                version = 'xagon'
                language = '日语'
            elif '_' in language:
                version = language.split('_')[0]
                language = language.split('_')[1].encode('utf8')
            else:
                version = 'trial'
                language = language.encode('utf8')
        else:
            self.log.logger.error('No found "language" row in test.xls')
            return False
        if '链接' in language:
            language = language.replace('链接', '')
        return language, version

    def get_excel_link(self):
        return self.strings['link'].lower().strip()

    def get_program_link(self):
        for outer_id in self.outer_link_id:
            if (outer_id != 'ID_LINK_HOME_BUY'
                    and outer_id in self.id) or self.id == 'ID_LINK_HOME_BUY':
                program_link = self.get_program_link_from_install_file()
                break
        else:
            program_link = self.get_program_link_from_ini()
        return program_link

    def get_program_link_from_ini(self):
        # 根据version language 获取common_url.ini文件位置
        ini_path = self.get_common_url_path()
        if not ini_path:
            return False
        config = Config(self.log, ini_path)
        url = config.read('text') if self.id.lower(
        ) not in self.share_net else config.read('ContactProductManegerUrl')
        # google转换
        self.id = 'google%2b' if self.id == 'google+' else self.id
        if self.id.lower() not in url.keys():
            self.log.logger.error('No found key:%s in %s' %
                                  (self.id, ini_path))
            return False
        link = url[self.id.lower()].lower()
        return link if 'mailto' not in link else link.split(':')[1]

    def get_program_link_from_install_file(self):
        return GetLinkFromInstallFile(
            self.config.read('translate')[self.language], self.version,
            self.id, self.package_path).get_link()

    def get_common_url_path(self):
        if self.package_path.lower().endswith(self.version):
            if self.version == 'xagon':
                url_path = os.path.join(self.package_path, r'{app}\bin',
                                        'common_url,2.ini')
            else:
                url_name = self.config.read('url')
                url_path = os.path.join(self.package_path, r'{app}\bin',
                                        url_name[self.language.encode('utf8')])
            # TB特殊处理efrontier日语版(链接文件为common_url,12.ini)
            if self.version == 'efrontier' and self.language == '日语':
                url_path = os.path.join(self.package_path, r'{app}\bin',
                                        'common_url,12.ini')
            # 特殊处理ad版本(链接文件编号+11)
            if self.version == 'ad':
                url_path_list = url_path.split(',')
                url_path_index = int(url_path_list[1].split('.')[0])
                # 日语本来的index是11,但是这里插队了,插在波兰语(index=6)前面,后续语言一次+1
                if url_path_index == 11:
                    url_path = url_path_list[0] + ',17.ini'
                elif url_path_index >= 6:  # 波兰语后面的语言+12
                    url_path = url_path_list[0] + ',' + str(url_path_index +
                                                            12) + '.ini'
                else:  # 波兰语前面的语言+11
                    url_path = url_path_list[0] + ',' + str(url_path_index +
                                                            11) + '.ini'
        else:
            raise IOError('package path and version is not matching')
        return url_path

    def check(self):
        excel_link = self.get_excel_link()
        program_link = self.get_program_link()
        if excel_link == program_link:
            result = 'success'
        elif excel_link.endswith(
                "/") and excel_link[:-1] == program_link:  # 排除最后斜杠
            result = 'success'
        elif 'www.' in excel_link and excel_link.replace('www.',
                                                         '') == program_link:
            result = 'success'
        else:
            self.log.logger.info('The program link is:%s' % program_link)
            self.log.logger.info('The excel   link is:%s' % excel_link)
            result = 'Failed'
            self.failed_excel_link = excel_link
            self.failed_program_link = program_link
        return result
Beispiel #7
0
app.config['SECRET_KEY'] = settings.app_secret
app.config['dir_base'] = os.path.dirname(os.path.abspath(__file__))
app.config['dir_root'] = '/'.join(app.config['dir_base'].split('/')[:-1])
app.config['APPLICATION_ROOT'] = settings.BIND_ROUTE

SECRET_KEY = settings.app_secret

babel = Babel(app)

locales = {
    'en': 'English',
}

import paste.controllers.routes.static
import paste.controllers.routes.errors
import paste.controllers.routes.before_request

from bin.config import Config
settings = Config()

if not settings.local:
    raise Exception('Local settings (%s/settings.py) not found' %
                    app.config['dir_root'])

# init routes
import main
import paste.controllers.pastes.routes

from paste.controllers.pastes.controller import PasteLoop
loop = PasteLoop()