Esempio n. 1
0
def go():
    dir, useSingleQuotes, config = readconfig.readconfig()
    confirmNoDuplicateFilenames(dir)
    layers, filesReferencedInLayers, filenamesReferencedInLayers, layersCfg = readLayersFile(dir)
    confirmLayersIncludesFiles(layersCfg, dir, filenamesReferencedInLayers)
    autoAddImports(config, dir, layers, useSingleQuotes)
    enforceLayering(config, dir)
Esempio n. 2
0
def applyEUDDraft(sfname):
    try:
        config = readconfig(sfname)
        mainSection = config["main"]
        ifname = mainSection["input"]
        ofname = mainSection["output"]
        if ifname == ofname:
            raise RuntimeError("input and output file should be different.")

        try:
            if mainSection["debug"]:
                ep.EPS_SetDebug(True)
        except KeyError:
            pass

        print("---------- Loading plugins... ----------")
        ep.LoadMap(ifname)
        pluginList, pluginFuncDict = loadPluginsFromConfig(ep, config)

        print("--------- Injecting plugins... ---------")

        payloadMain = createPayloadMain(pluginList, pluginFuncDict)
        ep.CompressPayload(True)
        ep.SaveMap(ofname, payloadMain)

        if isFreezeIssued():
            if isPromptIssued():
                print("Freeze - prompt enabled ")
                sys.stdout.flush()
                os.system("pause")
            print("[Stage 4/3] Applying freeze mpq modification...")
            ret = freezeMpq.applyFreezeMpqModification(ep.u2b(ofname),
                                                       ep.u2b(ofname),
                                                       isMpaqIssued())
            if ret != 0:
                raise RuntimeError("Error on mpq protection (%d)" % ret)

        MessageBeep(MB_OK)
        return True

    except Exception as e:
        print("==========================================")
        MessageBeep(MB_ICONHAND)
        exc_type, exc_value, exc_traceback = sys.exc_info()
        excs = traceback.format_exception(exc_type, exc_value, exc_traceback)
        formatted_excs = []

        for i, exc in enumerate(excs):
            if isEpExc(exc) and not all(isEpExc(e) for e in excs[i + 1:-1]):
                continue
            formatted_excs.append(exc)

        print("[Error] %s" % e, "".join(formatted_excs), file=sys.stderr)
        if msgbox.isWindows:
            msgbox.SetForegroundWindow(msgbox.GetConsoleWindow())
        return False
Esempio n. 3
0
def applyEUDDraft(sfname):
    try:
        config = readconfig(sfname)
        mainSection = config['main']
        ifname = mainSection['input']
        ofname = mainSection['output']
        if ifname == ofname:
            raise RuntimeError('input and output file should be different.')

        try:
            if mainSection['debug']:
                ep.EPS_SetDebug(True)
        except KeyError:
            pass

        print('---------- Loading plugins... ----------')
        ep.LoadMap(ifname)
        pluginList, pluginFuncDict = loadPluginsFromConfig(ep, config)

        print('--------- Injecting plugins... ---------')

        payloadMain = createPayloadMain(pluginList, pluginFuncDict)
        ep.CompressPayload(True)
        ep.SaveMap(ofname, payloadMain)

        if isFreezeIssued():
            print("[Stage 4/3] Applying freeze mpq modification...")
            if isMpaqIssued():
                ret = subprocess.call([mpqFreezePath, ofname, 'mpaq'])
            else:
                ret = subprocess.call([mpqFreezePath, ofname])
            if ret != 0:
                raise RuntimeError("Error on mpq protection (%d)" % ret)

        MessageBeep(MB_OK)

    except Exception as e:
        print("==========================================")
        MessageBeep(MB_ICONHAND)
        exc_type, exc_value, exc_traceback = sys.exc_info()
        excs = traceback.format_exception(exc_type, exc_value, exc_traceback)
        formatted_excs = []

        for i, exc in enumerate(excs):
            if isEpExc(exc) and not all(isEpExc(e) for e in excs[i + 1:-1]):
                continue
            formatted_excs.append(exc)

        print("[Error] %s" % e, ''.join(formatted_excs))
        if msgbox.isWindows:
            msgbox.SetForegroundWindow(msgbox.GetConsoleWindow())
Esempio n. 4
0
def download_picture():
    root = 'D:\\wallpaper\\'
    # 根据配置文件自定义配置
    address, options = readconfig()
    id, url = eval(address + '(' + options + ')')
    if not os.path.exists(root):
        os.mkdir(root)
    jpg_file = root + id + '.jpg'
    r = requests.get(url)
    r.raise_for_status()
    with open(jpg_file, 'wb') as file:
        file.write(r.content)

    return jpg_file
Esempio n. 5
0
import unittest
from testCase.loginPage import login
from selenium.webdriver import Remote
from selenium import webdriver
import readconfig
localReadConfig = readconfig.readconfig()
import time
from comm import common
import paramunittest
from comm.Log import MyLog

login_xls = common.get_xls("userCase.xlsx", "login")
log = MyLog.get_log()
logger = log.get_logger()


@paramunittest.parametrized(*login_xls)
class Login(unittest.TestCase):
    def setParameters(self, case, email, password):
        self.email = email
        self.password = password
        self.case = case

    def setUp(self):
        self.driver = webdriver.Ie()
        self.driver.get(localReadConfig.get_HTTP("baseurl"))
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

        logger.info("开始." + self.case + "测试.")
Esempio n. 6
0
        try:
            inputMap = None

            def isModifiedFiles():
                return (
                    hasModifiedFile(globalPluginDir, lasttime) or
                    hasModifiedFile('.', lasttime) or
                    isFileModified(sfname, lasttime) or
                    (inputMap and isFileModified(inputMap, lasttime))
                )

            while True:
                # input map may change with edd update. We re-read inputMap
                # every time here.
                config = readconfig(sfname)
                mainSection = config['main']
                inputMap = mainSection['input']

                # Wait for changes
                while lasttime and not isModifiedFiles():
                    if msgbox.isWindows:
                        if (
                            msgbox.IsThisForeground() and
                            msgbox.GetAsyncKeyState(ord('R'))
                        ):
                            print("[Forced recompile issued]")
                            break
                    time.sleep(1)

                # epscript can alter other files if some file changes.
    parser.add_argument("-r", "--nopoolhashrate", help="do not fetch "
                        "pool hashrate.", action="store_true")
    parser.add_argument("-m", "--email", help="send email.",
                        action="store_true")
    parser.add_argument("-w", "--webpage", help="render webpage.",
                        action="store_true")
    parser.add_argument("-p", "--hsplot", help="plot hash speed graph.",
                        action="store_true")
    parser.add_argument("-t", "--tmplot", help="plot temperature map.",
                        action="store_true")
    parser.add_argument("-c", "--config", type=str, help="use another config "
                        "file rather than ./statreport.conf.")
    args = parser.parse_args()

    if args.config:
        cfg = readconfig(args.config)
    else:
        cfg = readconfig("./statreport.conf")

    time_now = datetime.datetime.now()

    data0 = None
    time_old = None
    for logfile in sorted(os.listdir(cfg['General']['log_dir']), reverse=True):
        if re.match(r'log-(\d+_){4}\d+\.xml', logfile):
            (data0, time_old) = readlog(cfg['General']['log_dir'], logfile)
            break

    luckyID = []
    if not args.nolog:
        data = chkstat(cfg)
Esempio n. 8
0
        ('fn(', ['1', '2', '3'], ')', 9),
        parseArguments("'test\\'tes' otherotherotherotherotherother fn(1,2,3)",
                       43))

    gStart = GeneratedCodeDetector('').gStart
    gEnd = GeneratedCodeDetector('').gEnd
    exampleDoc = f'first\nlines\n\nthen\n{gStart}\ninside\nthe_generated\narea\n{gEnd}outside\nagain'
    detector = GeneratedCodeDetector(exampleDoc)
    assertTrue(not detector.isInsideGeneratedCode(0))
    assertTrue(not detector.isInsideGeneratedCode(1))
    assertTrue(not detector.isInsideGeneratedCode(exampleDoc.find('then')))
    assertTrue(detector.isInsideGeneratedCode(exampleDoc.find('inside')))
    assertTrue(detector.isInsideGeneratedCode(
        exampleDoc.find('the_generated')))
    assertTrue(detector.isInsideGeneratedCode(exampleDoc.find('area')))
    assertTrue(not detector.isInsideGeneratedCode(exampleDoc.find('outside')))
    assertTrue(not detector.isInsideGeneratedCode(exampleDoc.find('again')))


tests()

if __name__ == '__main__':
    dir, desiredArgIndex, skipThese, skipFiles = readconfig.readconfig()
    sAssertsToMarker = '|'.join('\\b' + k + '\\('
                                for k in desiredArgIndex.keys())
    reAssertsToMarker = re.compile(sAssertsToMarker)

    previewOnly = True
    #~ previewOnly = False
    go(dir, previewOnly)
Esempio n. 9
0
    if not tasksDisabled.autoHelpLongLines:
        help_fix_long_lines.autoHelpLongLines(f, lines, prettierCfg)
    
    if not tasksDisabled.autoHelpSetTestCollectionName:
        check_tests_referenced.autoHelpSetTestCollectionName(f, lines)
    
    if linesOrig != lines:
        files.writeall(f, '\n'.join(lines), encoding='utf-8')
    return lines

def doOperationsThatAskQuestions(srcdirectory, f, lines, prettierPath, prettierCfg):
    if not tasksDisabled.check_tests_referenced:
        check_tests_referenced.checkText(f, lines)
        
    if not tasksDisabled.check_for_null_coalesce:
        check_for_null_coalesce.checkText(f, lines)
    
    if not readconfig.shouldAllowLongerLinesOn(f, allowLongerLinesOn):
        check_for_long_lines.checkText(f, lines, prettierCfg)
        counting[0] += 1
    else:
        counting[1] += 1
   
    if not tasksDisabled.additional_checks:
        check_more.checkText(f, lines)

if __name__ == '__main__':
    srcdirectory, prettierCfg, prettierPath, allowLongerLinesOn, tasksDisabled = readconfig.readconfig()
    go(srcdirectory)

Esempio n. 10
0
                        "--hsplot",
                        help="plot hash speed graph.",
                        action="store_true")
    parser.add_argument("-t",
                        "--tmplot",
                        help="plot temperature map.",
                        action="store_true")
    parser.add_argument("-c",
                        "--config",
                        type=str,
                        help="use another config "
                        "file rather than ./statreport.conf.")
    args = parser.parse_args()

    if args.config:
        cfg = readconfig(args.config)
    else:
        cfg = readconfig("./statreport.conf")

    time_now = datetime.datetime.now()

    data0 = None
    time_old = None
    for logfile in sorted(os.listdir(cfg['General']['log_dir']), reverse=True):
        if re.match(r'log-(\d+_){4}\d+\.xml', logfile):
            (data0, time_old) = readlog(cfg['General']['log_dir'], logfile)
            break

    luckyID = []
    if not args.nolog:
        data = chkstat(cfg)
Esempio n. 11
0
def main():
    '''get parameters'''
    func_dict, dims_dict, scales_dict, params_dict = readconfig(INIPATH)
    '''setup data'''
    train_set = DPDataset(DPATH,
                          scales_dict,
                          seq_len=int(params_dict['seq_len']),
                          separation=int(params_dict['separation']))
    train_loader = DataLoader(train_set,
                              batch_size=int(params_dict['batch']),
                              shuffle=True,
                              drop_last=True)

    val_set = DPDataset(DPATH,
                        scales_dict=scales_dict,
                        seq_len=int(params_dict['seq_len']),
                        val=True)
    val_loader = DataLoader(val_set,
                            batch_size=int(params_dict['batch']),
                            shuffle=True,
                            drop_last=True)
    iter_val = val_loader.__iter__()
    '''setup model'''
    model = CDPNet(funcs_dict=func_dict, dims_dict=dims_dict)
    DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    if torch.cuda.device_count() > 1:
        print('Using {} GPUs'.format(torch.cuda.device_count()))
        model = nn.DataParallel(model)
        #print(isinstance(model, nn.DataParallel))
    model.to(DEVICE)
    opt = torch.optim.RMSprop(model.parameters(), lr=params_dict['lr_init'])
    lr_plateau = torch.optim.lr_scheduler.ReduceLROnPlateau(opt,
                                                            factor=0.5,
                                                            patience=10,
                                                            cooldown=5,
                                                            min_lr=1e-6)
    '''setup checkpoint directory'''
    weights_path = './weights'
    if not os.path.exists(weights_path):
        os.mkdir(weights_path)
    save_path = os.path.join(weights_path, date_string())
    os.mkdir(save_path)

    config_name = os.path.split(INIPATH)[-1]
    copyfile(INIPATH, os.path.join(save_path, config_name))
    print('saving weights to', save_path)
    '''training'''
    train_loss_history = []
    val_loss_history = []
    lr_history = []
    val_freq = 10
    save_freq = 100
    total_batches = len(train_loader)

    start = time.time()
    try:
        for e in range(params_dict['epoch']):
            for b, batch in enumerate(train_loader):
                X = batch[0]
                y = batch[1]
                X = [x.float().to(DEVICE) for x in X]
                y = [wy.float().to(DEVICE) for wy in y]

                pred, hidden_states = model(X)

                total_loss, s_loss, p_loss = combined_loss(
                    pred, y, X[2][:, -1, :])
                total_loss.backward()
                opt.step()
                opt.zero_grad()

                if (b % save_freq == 0):
                    if b != 0:
                        if isinstance(model, nn.DataParallel):
                            sd = model.module.state_dict()
                        else:
                            sd = model.state_dict()

                        checkpoint_dir = os.path.join(save_path,
                                                      'e{}b{}.pt'.format(e, b))
                        torch.save(sd, checkpoint_dir)

                if (b % val_freq == 0) and b != 0:
                    model.eval()
                    try:
                        X_val, y_val = next(iter_val)
                    except StopIteration:
                        #if we reach the end of validation data
                        iter_val = val_loader.__iter__()
                        X_val, y_val = next(iter_val)

                    X_val = [x.float().to(DEVICE) for x in X_val]
                    y_val = [wy.float().to(DEVICE) for wy in y_val]

                    with torch.no_grad():
                        pred_val, hidden_val = model(X_val)
                        loss_val, s_loss_val, p_loss_val = combined_loss(
                            pred_val, y_val, X_val[2][:, -1, :])

                    val_loss_history.append(loss_val.item())
                    train_loss_history.append(total_loss.item())

                    print(
                        'e {}, b {}/{}, loss: {:.3f}, s_loss: {:.3f}, p_loss: {:.3f}, val loss: {:.3f}'
                        .format(e, b, total_batches, total_loss, s_loss,
                                p_loss, loss_val))

                    model.train()

                #if b>=1:
                #break
    finally:
        print('Training took {:.3f} seconds'.format(time.time() - start))
        if isinstance(model, nn.DataParallel):
            sd = model.module.state_dict()
        else:
            sd = model.state_dict()
        checkpoint_dir = os.path.join(save_path, 'final.pt')
        torch.save(model.state_dict(), checkpoint_dir)

        fig_path = os.path.join(save_path, 'loss.png')
        save_train_history(train_loss_history, val_loss_history, fig_path,
                           val_freq)
        os.system('nvidia-smi')
Esempio n. 12
0
from django.shortcuts import render
from django.shortcuts import redirect
from django.http import HttpResponse
from django.http import HttpResponseRedirect
import mysql.connector
from mysql.connector import errorcode
import readconfig
# Create your views here.

conf = readconfig.readconfig("./config.ini")

def index(request):
#    return HttpResponse("Hello World")
    return render(request, 'base.html')


class server:
    def __init__(self):
        self.server_id = 0
        self.server_ip = "0.0.0.0"
        self.server_port = 3306

def servers(request):
    return display_servers(request, "")

def display_servers(request, err_msg):
    cnx = mysql.connector.connect(user=conf.getuser(), host=conf.gethost(), password=conf.getpwd(),
            database=conf.getdb(), port=conf.getport())
    cursor = cnx.cursor()
    query_state = ("select server_id, ip_addr, port from servers")
    cursor.execute(query_state)
Esempio n. 13
0
def run_tests(srcdir, test_function):

    parser = optparse.OptionParser(usage="lydia_tests.py [options] [test-title]")
    parser.add_option("-e", "--echo", action="store_true",
                      help="run test, don't compare, output to console")
    parser.add_option("-q", "--quiet", action="store_true",
                      help="minimum output -- just pass/fail")
    parser.add_option("-f", "--file", metavar="FILE", default="tests.xml",
                      help="use test configuration file FILE")
                                   
    opts, args = parser.parse_args(sys.argv[1:])

    # Turn the options into attributes of the Config class.
    for opt in vars(opts):
        setattr(Config, opt, getattr(opts, opt))

    if len(args) > 1:
        print "Too many arguments"
        print parser.get_usage()
        sys.exit(1)

    all_tests = readconfig.readconfig(Config.file, srcdir)
    if len(args) == 0:
        tests = all_tests

    if len(args) == 1:
        test_title = args[0]
        user_test = find_test(all_tests, test_title)        
        if user_test:
            tests = [user_test]        
        else:
            print "Unknown test title: '%s'" % test_title
            sys.exit(1)

    okay = True
    for test in tests:
        if isinstance(test, readconfig.Separator):
            print test.title
            continue
        result = run_test(test, test_function)
        if result != 0:
            okay = False
            break

    testname = test_function.__name__
    testname = testname.replace("run_", "")
    testname = testname.replace("_command", "")

    if okay:
        result_str = "%s: All tests in `%s' were passed successfully" % (testname, Config.file)
    else:
        result_str = "%s: Test suite `%s' failed to complete" % (testname, Config.file)

    if len(args) == 0:
        print len(result_str) * "="
        print result_str
        print len(result_str) * "="

    if okay:
        sys.exit(0)
    else:
        sys.exit(1)
Esempio n. 14
0
def applyEUDDraft(sfname):
    try:
        config = readconfig(sfname)
        mainSection = config["main"]
        ifname = mainSection["input"]
        ofname = mainSection["output"]
        if ifname == ofname:
            raise RuntimeError("input and output file should be different.")

        try:
            if mainSection["debug"]:
                ep.EPS_SetDebug(True)
        except KeyError:
            pass
        try:
            unitname_encoding = mainSection["decodeUnitName"]
            from eudplib.core.mapdata.tblformat import DecodeUnitNameAs

            DecodeUnitNameAs(unitname_encoding)
        except KeyError:
            pass
        try:
            if mainSection["objFieldN"]:
                from eudplib.eudlib.objpool import SetGlobalPoolFieldN

                field_n = int(mainSection["objFieldN"])
                SetGlobalPoolFieldN(field_n)
        except KeyError:
            pass

        sectorSize = 15
        try:
            if mainSection["sectorSize"]:
                sectorSize = int(mainSection["sectorSize"])
        except KeyError:
            pass
        except:
            sectorSize = None

        print("---------- Loading plugins... ----------")
        ep.LoadMap(ifname)
        pluginList, pluginFuncDict = loadPluginsFromConfig(ep, config)

        print("--------- Injecting plugins... ---------")

        payloadMain = createPayloadMain(pluginList, pluginFuncDict)
        ep.CompressPayload(True)

        if ep.IsSCDBMap():
            if isFreezeIssued():
                raise RuntimeError(
                    "Can't use freeze protection on SCDB map!\nDisable freeze by following plugin settings:\n\n[freeze]\nfreeze : 0\n"
                )
            print("SCDB - sectorSize disabled")
            sectorSize = None
        elif isFreezeIssued():
            # FIXME: Add variable sectorSize support for freeze
            print("Freeze - sectorSize disabled")
            sectorSize = None
        ep.SaveMap(ofname, payloadMain, sectorSize=sectorSize)

        if isFreezeIssued():
            if isPromptIssued():
                print("Freeze - prompt enabled ")
                sys.stdout.flush()
                os.system("pause")
            print("[Stage 4/3] Applying freeze mpq modification...")
            ret = freezeMpq.applyFreezeMpqModification(ep.u2b(ofname),
                                                       ep.u2b(ofname))
            if ret != 0:
                raise RuntimeError("Error on mpq protection (%d)" % ret)

        MessageBeep(MB_OK)
        return True

    except Exception as e:
        print("==========================================")
        MessageBeep(MB_ICONHAND)
        exc_type, exc_value, exc_traceback = sys.exc_info()
        excs = traceback.format_exception(exc_type, exc_value, exc_traceback)
        formatted_excs = []

        for i, exc in enumerate(excs):
            if isEpExc(exc) and not all(isEpExc(e) for e in excs[i + 1:-1]):
                continue
            ver = ep.eudplibVersion()
            plibPath = (
                'File "C:\\Py\\lib\\site-packages\\eudplib-%s-py3.8-win32.egg\\eudplib\\'
                % ver)
            exc.replace(plibPath, 'eudplib File"')
            formatted_excs.append(exc)

        print("[Error] %s" % e, "".join(formatted_excs), file=sys.stderr)
        if msgbox.isWindows:
            msgbox.SetForegroundWindow(msgbox.GetConsoleWindow())
        return False
Esempio n. 15
0

# Chdir
sfname = sys.argv[1]
oldpath = os.getcwd()
dirname, sfname = os.path.split(sfname)
if dirname:
    os.chdir(dirname)
    sys.path.insert(0, os.path.abspath(dirname))


# Use simple setting system
if sfname[-4:] == '.eds':
    print(' - Running euddraft in compile mode')
    try:
        config = readconfig(sfname)
        mainSection = config['main']
        ifname = mainSection['input']
        ofname = mainSection['output']
        if ifname == ofname:
            raise RuntimeError('input and output file should be different.')

        print('---------- Loading plugins... ----------')
        pluginList, pluginFuncDict = loadPluginsFromConfig(config)

        print('--------- Injecting plugins... ---------')
        applyEUDDraft(ifname, ofname, pluginList, pluginFuncDict)

    except Exception as e:
        print("==========================================")
        print("[Error] %s" % e)