Esempio n. 1
0
def update():
    ac_vals = parse_file(FILE_AC, RE_AC_ONLINE)
    bat_vals = parse_file(
        [FILE_BAT_INFO, FILE_BAT_STATE],
        [RE_FULL_CAPACITY, RE_REMAINING_CAPACITY, RE_PRESENT_RATE])

    bat = '--'
    ac = '--'
    color = BAR_NORMAL_COLORS
    try:
        lastfull = float(bat_vals['lastfull'][0])
        remain = float(bat_vals['remain'][0])
        rate = float(bat_vals['rate'][0])

        percent = math.floor(remain / lastfull * 100.0 + 0.5)
        bat = '%d%%' % percent
        if percent < 25:
            color = Colors(0xFF0000, BAR_NORMAL_COLORS.background,
                           BAR_NORMAL_COLORS.border)
        elif percent < 50:
            color = Colors(0xFFFF00, BAR_NORMAL_COLORS.background,
                           BAR_NORMAL_COLORS.border)

        if ac_vals:
            ac = '*AC*'
        elif rate > 0:
            mins = (3600.0 * (remain / rate)) / 60.0
            hours = math.floor(mins / 60.0)
            mins = math.floor(mins - (hours * 60.0))
            ac = '%02d:%02d' % (hours, mins)
    except Exception, e:
        logger.exception(e)
Esempio n. 2
0
    def _runTest(self, method, printTestName=False, numberOfAssertionFailed=0):
        exceptionRaised = False
        if printTestName:
            print '\t' + Colors.Cyan(method.__name__)
        try:
            if self.args.debug:
                raw_input(
                    '\tenv is up, attach to any process with gdb and press any button to continue.'
                )
            method()
        except unittest.SkipTest:
            print '\t' + Colors.Green('Skipping test')
        except Exception as err:
            msg = 'Unhandled exception: %s' % err
            print '\t' + Colors.Bred(msg)
            traceback.print_exc(file=sys.stdout)
            exceptionRaised = True

        isTestFaild = self.currEnv is None or self.currEnv.getNumberOfFailedAssertion(
        ) > numberOfAssertionFailed or exceptionRaised

        if isTestFaild:
            print '\t' + Colors.Bred('Test Failed')
            self.testsFailed.add(self.currEnv)
        else:
            print '\t' + Colors.Green('Test Passed')

        if self.args.stop_on_failure and isTestFaild:
            if self.args.interactive_debugger:
                while self.currEnv.isUp():
                    time.sleep(1)
            raw_input('press any button to move to the next test')

        return self.currEnv.getNumberOfFailedAssertion()
Esempio n. 3
0
 def checkExitCode(self):
     ret = True
     if self.masterExitCode != 0:
         print '\t' + Colors.Bred('bad exit code for serverId %s' % str(self.masterServerId))
         ret = False
     if self.useSlaves and self.slaveExitCode != 0:
         print '\t' + Colors.Bred('bad exit code for serverId %s' % str(self.slaveServerId))
         ret = False
     return ret
Esempio n. 4
0
    def _assertion(self, checkStr, trueValue, depth=0):
        basemsg = Colors.Yellow(checkStr) + '\t' + Colors.Gray(
            self._getCallerPosition(3 + depth))
        if trueValue and self.verbose:
            print '\t' + Colors.Green('✅  (OK):\t') + basemsg
        elif not trueValue:
            failureSummary = Colors.Bred('❌  (FAIL):\t') + basemsg
            print '\t' + failureSummary
            if self.defaultExitOnFailure:
                raise TestAssertionFailure('Assertion Failed!')

            self.assertionFailedSummary.append(failureSummary)
Esempio n. 5
0
    def _downloadEnterpriseBinaries(self):
        binariesName = 'binaries.tar'
        print Colors.Yellow('installing enterprise binaries')
        print Colors.Yellow('creating RLTest working dir: %s' %
                            RLTest_WORKING_DIR)
        try:
            shutil.rmtree(RLTest_WORKING_DIR)
            os.makedirs(RLTest_WORKING_DIR)
        except Exception:
            pass

        print Colors.Yellow('download binaries')
        args = [
            'wget', RLTest_ENTERPRISE_URL, '-O',
            os.path.join(RLTest_WORKING_DIR, binariesName)
        ]
        self.process = subprocess.Popen(args=args,
                                        stdout=sys.stdout,
                                        stderr=sys.stdout)
        self.process.wait()
        if self.process.poll() != 0:
            raise Exception('failed to download enterprise binaries from s3')

        print Colors.Yellow('extracting binaries')
        debFileName = 'redislabs_%s-%s~%s_amd64.deb' % (
            RLTest_ENTERPRISE_VERSION, RLTest_ENTERPRISE_SUB_VERSION, OS_NAME)
        args = [
            'tar', '-xvf',
            os.path.join(RLTest_WORKING_DIR, binariesName), '--directory',
            RLTest_WORKING_DIR, debFileName
        ]
        self.process = subprocess.Popen(args=args,
                                        stdout=sys.stdout,
                                        stderr=sys.stdout)
        self.process.wait()
        if self.process.poll() != 0:
            raise Exception('failed to extract binaries to %s' %
                            self.RLTest_WORKING_DIR)

        # TODO: Support centos that does not have dpkg command
        args = [
            'dpkg', '-x',
            os.path.join(RLTest_WORKING_DIR, debFileName), RLTest_WORKING_DIR
        ]
        self.process = subprocess.Popen(args=args,
                                        stdout=sys.stdout,
                                        stderr=sys.stdout)
        self.process.wait()
        if self.process.poll() != 0:
            raise Exception('failed to extract binaries to %s' %
                            self.RLTest_WORKING_DIR)

        print Colors.Yellow('finished installing enterprise binaries')
Esempio n. 6
0
    def __init__(self,
                 testName=None,
                 testDescription=None,
                 module=None,
                 moduleArgs=None,
                 env=None,
                 useSlaves=None,
                 shardsCount=None,
                 useAof=None):
        self.testName = testName if testName else '%s.%s' % (
            inspect.getmodule(inspect.currentframe().f_back).__name__,
            inspect.currentframe().f_back.f_code.co_name)
        self.testName = self.testName.replace(' ', '_')

        if testDescription:
            print Colors.Gray('\tdescription: ' + testDescription)

        self.module = module if module else Env.defaultModule
        self.moduleArgs = moduleArgs if moduleArgs else Env.defaultModuleArgs
        self.env = env if env else Env.defaultEnv
        self.useSlaves = useSlaves if useSlaves else Env.defaultUseSlaves
        self.shardsCount = shardsCount if shardsCount else Env.defaultShardsCount
        self.useAof = useAof if useAof else Env.defaultUseAof
        self.verbose = Env.defaultVerbose
        self.logDir = Env.defaultLogDir

        self.assertionFailedSummary = []

        if Env.RTestInstance.currEnv and self.compareEnvs(
                Env.RTestInstance.currEnv):
            self.envRunner = Env.RTestInstance.currEnv.envRunner
        else:
            if Env.RTestInstance.currEnv:
                Env.RTestInstance.currEnv.stop()
            self.envRunner = self.getEnvByName()

        try:
            os.makedirs(self.logDir)
        except Exception:
            pass

        self.start()
        if self.verbose >= 2:
            print Colors.Blue('\tenv data:')
            self.envRunner.printEnvData('\t\t')

        Env.RTestInstance.currEnv = self

        if Env.defaultDebug:
            raw_input(
                '\tenv is up, attach to any process with gdb and press any button to continue.'
            )
Esempio n. 7
0
def update():
    lavg = os.getloadavg()

    color = BAR_NORMAL_COLORS
    if max(lavg) > 1.5:
        # yellow text
        color = Colors(0xFFFF00, BAR_NORMAL_COLORS.background,
                       BAR_NORMAL_COLORS.border)
    if max(lavg) > 4.0:
        # red text
        color = Colors(0xFF0000, BAR_NORMAL_COLORS.background,
                       BAR_NORMAL_COLORS.border)

    return (color, 'LOAD: %.2f %.2f %.2f' % lavg)
Esempio n. 8
0
    def __init__(
        self,
        testName=None,
        module=None,
        moduleArgs=None,
        env=None,
        useSlaves=None,
        shardsCount=None,
        useAof=None,
    ):
        self.testName = testName if testName else '%s.%s' % (
            inspect.getmodule(inspect.currentframe().f_back).__name__,
            inspect.currentframe().f_back.f_code.co_name)
        self.testNamePrintable = self.testName
        self.testName = self.testName.replace(' ', '_')

        print Colors.Cyan(self.testNamePrintable + ':')

        self.module = module if module else Env.defaultModule
        self.moduleArgs = moduleArgs if moduleArgs else Env.defaultModuleArgs
        self.env = env if env else Env.defaultEnv
        self.useSlaves = useSlaves if useSlaves else Env.defaultUseSlaves
        self.shardsCount = shardsCount if shardsCount else Env.defaultShardsCount
        self.useAof = useAof if useAof else Env.defaultUseAof
        self.verbose = Env.defaultVerbose
        self.logDir = Env.defaultLogDir

        self.assertionFailedSummery = []

        if Env.RTestInstance.currEnv and self.compareEnvs(
                Env.RTestInstance.currEnv):
            self.envRunner = Env.RTestInstance.currEnv.envRunner
        else:
            if Env.RTestInstance.currEnv:
                Env.RTestInstance.currEnv.stop()
            self.envRunner = self.getEnvByName()

        try:
            os.makedirs(self.logDir)
        except Exception:
            pass

        self.start()
        if self.verbose >= 2:
            print Colors.Blue('\tenv data:')
            self.envRunner.printEnvData('\t\t')

        Env.RTestInstance.currEnv = self
Esempio n. 9
0
def DisplayInstances(image, boxes, masks, class_ids, class_names, scores):
    N = boxes.shape[0]
    if not N:
        pass
    else:
        assert N == masks.shape[-1] == class_ids.shape[0]

    mask_color = Colors(class_names)
    for i in range(N):

        if not np.any(boxes[i]):
            # Skip this instance. Has no bbox. Likely lost in image cropping or label is not required vehicle
            continue

        class_id = class_ids[i]
        label = class_names[class_id]
        if label == "car" or label == "bus":

            y1, x1, y2, x2 = boxes[i]
            score = scores[i] if scores is not None else None
            color = mask_color[class_id]
            caption = "{} {:.3f}".format(label, score) if score else label
            mask = masks[:, :, i]
            image = ApplyMask(image, mask, color, alpha=0.5)
            image = cv2.rectangle(image, (x1, y1), (x2, y2), color, 2)
            image = cv2.putText(image, caption, (x1, y1),
                                cv2.FONT_HERSHEY_PLAIN, 0.5, color, 2)
    return image
Esempio n. 10
0
File: cloud.py Progetto: unrar/Jeiji
 def describe(self, type, url, port, username, password):
     self.type = type
     self.url = url
     self.port = str(port)
     self.username = username
     self.password = password
     self.described = True
     cc = Colors()
     print(cc.green.format("[INFO] Cloud properly described!"))
Esempio n. 11
0
File: jeiji.py Progetto: unrar/Jeiji
 def __init__(self, instance):
     # Create color manager
     self.cc = Colors()
     # If it's a cloud object
     if isinstance(instance, Cloud):
         self.ref = instance
     #If it's not:
     else:
         self.ref = False
         print(self.cc.red.format("Debug: A Jeiji object can only be used passing a Cloud object instance."))
Esempio n. 12
0
def read_list():
    # path = raw_input('Enter path to BOM: ')
    path = '/Users/alexfeldman/Documents/Scripts/BOM/tester.txt'
    ext = os.path.splitext(path)[1]
    if ext == '.txt':
        with open(path, 'r') as text_file:
            lines = text_file.readlines()
        if len(lines):
            print(Colors.success('Read successfuly'))
    items = []
    Item = namedtuple('Item', 'reference, quantity, value')
Esempio n. 13
0
 def takeEnvDown(self, fullShutDown=False):
     if self.currEnv:
         if self.args.env_reuse and not fullShutDown:
             self.currEnv.flush()
         else:
             self.currEnv.stop()
             if self.args.use_valgrind and self.currEnv and not self.currEnv.checkExitCode(
             ):
                 print Colors.Bred('\tvalgrind check failure')
                 self.testsFailed.add(self.currEnv)
             self.currEnv = None
Esempio n. 14
0
 def _assertion(self, checkStr, trueValue, depth=0):
     if trueValue and self.verbose:
         print '\t' + Colors.Green('assertion success:\t') + Colors.Yellow(
             checkStr) + '\t' + Colors.Gray(
                 self._getCallerPosition(3 + depth))
     elif not trueValue:
         FailureSummery = Colors.Bred('assertion faild:\t') + Colors.Yellow(
             checkStr) + '\t' + Colors.Gray(
                 self._getCallerPosition(3 + depth))
         print '\t' + FailureSummery
         self.assertionFailedSummery.append(FailureSummery)
Esempio n. 15
0
 def _stopProcess(self, role):
     process = self.masterProcess if role == MASTER else self.slaveProcess
     serverId = self.masterServerId if role == MASTER else self.slaveServerId
     if not self._isAlive(process):
         if not self.has_interactive_debugger:
             # on interactive debugger its expected that then process will not be alive
             print '\t' + Colors.Bred('process is not alive, might have crash durring test execution, check this out. server id : %s' % str(serverId))
         return
     try:
         process.terminate()
         process.wait()
         if role == MASTER:
             self.masterExitCode = process.poll()
         else:
             self.slaveExitCode = process.poll()
     except OSError:
         pass
Esempio n. 16
0
    def print_field(self):
        size = len(self.field)
        border = [i for i in range(size)]

        print('   |', end=' ')
        print(*border, sep=' | ', end=' |\n')
        for i in range(size):
            print('%2d' % border[i], end=' | ')
            for j in range(size):
                symbol = self.field[i][j]
                if symbol != 'O':
                    color = Colors.get_color(symbol)
                    print(color + symbol + Colors.ENDC, end=' ')
                else:
                    print(self.field[i][j], end=' ')
                print('|', end=' ')
            print()
Esempio n. 17
0
 def debugPrint(self, msg, force=False):
     if Env.defaultDebugPrints or force:
         print '\t' + Colors.Bold('debug:\t') + Colors.Gray(msg)
Esempio n. 18
0
 def printEnvData(self, prefix=''):
     print Colors.Yellow(prefix + 'master:')
     self._printEnvData(prefix + '\t', MASTER)
     if self.useSlaves:
         print Colors.Yellow(prefix + 'slave:')
         self._printEnvData(prefix + '\t', SLAVE)
Esempio n. 19
0
 def _printEnvData(self, prefix='', role=MASTER):
     print Colors.Yellow(prefix + 'pid: %d' % (self.getPid(role)))
     print Colors.Yellow(prefix + 'port: %d' % (self.getPort(role)))
     print Colors.Yellow(prefix + 'binary path: %s' % (self.redisBinaryPath))
     print Colors.Yellow(prefix + 'server id: %d' % (self.getServerId(role)))
     print Colors.Yellow(prefix + 'using debugger: {}'.format(bool(self.debugger)))
     if self.modulePath:
         print Colors.Yellow(prefix + 'module: %s' % (self.modulePath))
         if self.moduleArgs:
             print Colors.Yellow(prefix + 'module args: %s' % (self.moduleArgs))
     if self.outputFilesFormat:
         print Colors.Yellow(prefix + 'log file: %s' % (self._getFileName(role, '.log')))
         print Colors.Yellow(prefix + 'db file name: %s' % self._getFileName(role, '.rdb'))
     if self.dbDirPath:
         print Colors.Yellow(prefix + 'db dir path: %s' % (self.dbDirPath))
     if self.libPath:
         print Colors.Yellow(prefix + 'library path: %s' % (self.libPath))
Esempio n. 20
0
    def execute(self):
        self.testsFailed = set()
        Env.RTestInstance = self
        if self.args.env_only:
            Env.defaultVerbose = 2
            env = Env(testName='manual test env')
            if self.args.interactive_debugger:
                while env.isUp():
                    time.sleep(1)
            raw_input('press any button to stop')
            env.stop()
            return
        if self.args.tests_file:
            self._loadFileTests(self.args.tests_file)
        else:
            self._loadTests()
        done = 0
        startTime = time.time()
        if self.args.interactive_debugger and len(self.tests) != 1:
            print Colors.Bred(
                'only one test can be run on interactive-debugger use --test-name'
            )
            sys.exit(1)
        while self.tests:
            with self.envScopeGuard():
                test = self.tests.pop(0)
                if inspect.isclass(test):

                    # checking if there are tests to run
                    methodsToTest = []
                    for m in dir(test):
                        if self.args.test_name is not None:
                            if self.args.test_name == m:
                                methodsToTest.append(m)
                        elif m.startswith('test') or m.startswith('Test'):
                            methodsToTest.append(m)

                    if len(methodsToTest) == 0:
                        continue
                    try:
                        testObj = test()
                    except unittest.SkipTest:
                        print '\t' + Colors.Green('Skipping test')
                        continue
                    except Exception as err:
                        msg = 'Unhandled exception: %s' % err
                        print '\t' + Colors.Bred(msg)
                        traceback.print_exc(file=sys.stdout)
                        print '\t' + Colors.Bred('Test Failed')
                        if self.currEnv:
                            self.testsFailed.add(self.currEnv)
                        continue
                    methods = [
                        getattr(testObj, m) for m in dir(testObj)
                        if callable(getattr(testObj, m)) and (
                            m.startswith('test') or m.startswith('Test'))
                    ]
                    numberOfAssertionFailed = 0
                    for m in methods:
                        if self.args.test_name is None or self.args.test_name == m.__name__:
                            numberOfAssertionFailed = self._runTest(
                                m,
                                printTestName=True,
                                numberOfAssertionFailed=numberOfAssertionFailed
                            )
                            done += 1
                elif not inspect.isfunction(test):
                    continue
                elif len(inspect.getargspec(test).args) > 0:
                    env = Env(testName='%s.%s' %
                              (str(test.__module__), test.func_name))
                    self._runTest(lambda: test(env))
                    done += 1
                else:
                    self._runTest(test)
                    done += 1

        self.takeEnvDown(fullShutDown=True)
        endTime = time.time()

        print Colors.Bold('Test Took: %d sec' % (endTime - startTime))
        print Colors.Bold(
            'Total Tests Run: %d, Total Tests Failed: %d, Total Tests Passed: %d'
            % (done, len(self.testsFailed), done - len(self.testsFailed)))
        if len(self.testsFailed) > 0:
            print Colors.Bold('Faild Tests Summery:')
            for testFaild in self.testsFailed:
                print '\t' + Colors.Bold(testFaild.testNamePrintable)
                testFaild.printFailuresSummery('\t\t')
            sys.exit(1)
Esempio n. 21
0
File: nn.py Progetto: fdlm/nn
def train(network, num_epochs, train_fn, train_batches, test_fn=None,
          validation_batches=None, threads=None, early_stop=np.inf,
          early_stop_acc=False, save_epoch_params=False, callbacks=None,
          acc_func=onehot_acc, train_acc=False):
    """
    Train a neural network by updating its parameters.

    Parameters
    ----------
    network : lasagne neural network handle
        Network to be trained.
    num_epochs: int
        Maximum number of epochs to train
    train_fn : theano function
        Function that computes the loss and updates the network parameters.
        Takes parameters from the batch iterators
    train_batches : batch iterator
        Iterator that yields mini batches from the training set. Must be able
        to re-iterate multiple times.
    test_fn : theano function
        Function that computes loss and predictions of the network.
        Takes parameters from the batch iterators.
    validation_batches : batch iterator
        Iterator that yields mini batches from the validation set. Must be able
        to re-iterate multiple times.
    threads : int
        Number of threads to use to prepare mini batches. If None, use
        a single thread.
    early_stop : int
        Number of iterations without loss improvement on validation set that
        stops training.
    early_stop_acc : boolean
        Use validation accuracy instead of loss for early stopping.
    save_epoch_params : str or False
        Save neural network parameters after each epoch. If False, do not save.
        If you want to save the parameters, provide a filename with an
        int formatter so the epoch number can be inserted.
    callbacks : list of callables
        List of callables to call after each training epoch. Can be used to k
        update learn rates or plot data. Functions have to accept the
        following parameters: current epoch number, lists of per-epoch train
        losses, train accuracies, validation losses, validation accuracies.
        The last three lists may be empty, depending on other parameters.
    acc_func : callable
        Function to use to compute accuracies.
    train_acc : boolean
        Also compute accuracy for training set. In this case, the training
        loss will be also re-computed after an epoch, which leads to lower
        train losses than when not using this parameter.

    Returns
    -------
    tuple of four lists
        Train losses, trian accuracies, validation losses,
        validation accuracies for each epoch
    """

    if (test_fn is not None) != (validation_batches is not None):
        raise ValueError('If test function is given, validation set is '
                         'necessary (and vice-versa)!')

    best_val = np.inf if not early_stop_acc else 0.0
    epochs_since_best_val_loss = 0

    if callbacks is None:
        callbacks = []

    if callbacks is None:
        callbacks = []

    best_params = get_params(network)
    train_losses = []
    val_losses = []
    val_accs = []
    train_accs = []

    if threads is not None:
        def threaded(it):
            return dmgr.iterators.threaded(it, threads)
    else:
        def threaded(it):
            return it

    for epoch in range(num_epochs):
        timer = Timer()
        timer.start('epoch')
        timer.start('train')

        try:
            train_losses.append(
                avg_batch_loss(threaded(train_batches), train_fn, timer))
        except RuntimeError as e:
            print(Colors.red('Error during training:'), file=sys.stderr)
            print(Colors.red(str(e)), file=sys.stderr)
            return best_params

        timer.stop('train')

        if save_epoch_params:
            save_params(network, save_epoch_params.format(epoch))

        if validation_batches:
            val_loss, val_acc = avg_batch_loss_acc(
                threaded(validation_batches), test_fn, acc_func)
            val_losses.append(val_loss)
            val_accs.append(val_acc)

        if train_acc:
            train_loss, tr_acc = avg_batch_loss_acc(
                threaded(train_batches), test_fn, acc_func)
            train_losses[-1] = train_loss
            train_accs.append(tr_acc)

        print('Ep. {}/{} {:.1f}s (tr: {:.1f}s th: {:.1f}s)'.format(
            epoch + 1, num_epochs,
            timer['epoch'], timer['train'], timer['theano']),
            end='')
        print('  tl: {:.6f}'.format(train_losses[-1]), end='')

        if train_acc:
            print('  tacc: {:.6f}'.format(tr_acc), end='')

        if validation_batches:
            # early stopping
            cmp_val = val_losses[-1] if not early_stop_acc else -val_accs[-1]
            if cmp_val < best_val:
                epochs_since_best_val_loss = 0
                best_val = cmp_val
                best_params = get_params(network)
                # green output
                c = Colors.green
            else:
                epochs_since_best_val_loss += 1
                # neutral output
                c = lambda x: x

            print(c('  vl: {:.6f}'.format(val_losses[-1])), end='')
            print(c('  vacc: {:.6f}'.format(val_accs[-1])), end='')

            if epochs_since_best_val_loss >= early_stop:
                print(Colors.yellow('\nEARLY STOPPING!'))
                break
        else:
            best_params = get_params(network)

        print('')

        for cb in callbacks:
            cb(epoch, train_losses, val_losses, train_accs, val_accs)

    # set the best parameters found
    set_params(network, best_params)
    return train_losses, val_losses, train_accs, val_accs
Esempio n. 22
0
def saveConfigs(confs):
    with open(confFileName, 'wb') as out_s:
        for obj in confs:
            pickle.dump(obj, out_s)
    return

def loadConfigs():
    confs = []
    with open(confFileName, 'rb') as in_s:
        while True:
            try:
                obj = pickle.load(in_s)
            except EOFError:
                break
            else:
                confs.append(obj)
        return confs



try:
    # print('Loading color scheme configuration.')
    configurations = loadConfigs()
    colorScheme = configurations[0]
    # print('Loaded config file.')
except Exception as e:
    print(f'Cannot load saved configurations: {e}')
    configurations = None
    colorScheme = Colors()
    colorScheme.setScheme()
Esempio n. 23
0
File: cloud.py Progetto: unrar/Jeiji
 def __init__(self):
     cc = Colors()
     print(
         cc.blue.format(
             "[INFO] Cloud reference created. Waiting for description..."))
     self.described = False
Esempio n. 24
0
    def __init__(self):
        parser = CustomArgumentParser(
            fromfile_prefix_chars=RLTest_CONFIG_FILE_PREFIX,
            formatter_class=argparse.ArgumentDefaultsHelpFormatter,
            description='Test Framework for redis and redis module')

        parser.add_argument('--module',
                            default=None,
                            help='path to the module file')

        parser.add_argument('--module-args',
                            default=None,
                            help='arguments to give to the module on loading')

        parser.add_argument(
            '--env',
            '-e',
            default='oss',
            choices=['oss', 'oss-cluster', 'enterprise', 'enterprise-cluster'],
            help='env on which to run the test')

        parser.add_argument('--oss-redis-path',
                            default='redis-server',
                            help='path to the oss redis binary')

        parser.add_argument('--enterprise-redis-path',
                            default=os.path.join(
                                RLTest_WORKING_DIR,
                                'opt/redislabs/bin/redis-server'),
                            help='path to the entrprise redis binary')

        parser.add_argument('--stop-on-failure',
                            action='store_const',
                            const=True,
                            default=False,
                            help='stop running on failure')

        parser.add_argument('--verbose',
                            '-v',
                            action='count',
                            default=0,
                            help='print more information about the test')

        parser.add_argument('--debug',
                            action='store_const',
                            const=True,
                            default=False,
                            help='stop before each test allow gdb attachment')

        parser.add_argument(
            '-t',
            '--test',
            help='Specify test to run, in the form of "file:test"')

        parser.add_argument('--tests-dir',
                            default='.',
                            help='directory on which to run the tests')

        parser.add_argument('--test-name',
                            default=None,
                            help='test name to run')

        parser.add_argument(
            '--tests-file',
            default=None,
            help='tests file to run (with out the .py extention)')

        parser.add_argument('--env-only',
                            action='store_const',
                            const=True,
                            default=False,
                            help='start the env but do not run any tests')

        parser.add_argument(
            '--clear-logs',
            action='store_const',
            const=True,
            default=False,
            help='deleting the log direcotry before the execution')

        parser.add_argument('--log-dir',
                            default='./logs',
                            help='directory to write logs to')

        parser.add_argument('--use-slaves',
                            action='store_const',
                            const=True,
                            default=False,
                            help='run env with slaves enabled')

        parser.add_argument('--shards-count',
                            default=1,
                            type=int,
                            help='Number shards in bdb')

        parser.add_argument('--download-enterprise-binaries',
                            action='store_const',
                            const=True,
                            default=False,
                            help='run env with slaves enabled')

        parser.add_argument('--proxy-binary-path',
                            default=os.path.join(RLTest_WORKING_DIR,
                                                 'opt/redislabs/bin/dmcproxy'),
                            help='dmc proxy binary path')

        parser.add_argument(
            '--enterprise-lib-path',
            default=os.path.join(RLTest_WORKING_DIR, 'opt/redislabs/lib/'),
            help='path of needed libraries to run enterprise binaries')

        parser.add_argument(
            '--env-reuse',
            action='store_const',
            const=True,
            default=False,
            help=
            'reuse exists env, this feature is based on best efforts, if the env can not be reused then it will be taken down.'
        )

        parser.add_argument('--use-aof',
                            action='store_const',
                            const=True,
                            default=False,
                            help='use aof instead of rdb')

        parser.add_argument('--debug-print',
                            action='store_const',
                            const=True,
                            default=False,
                            help='print debug messages')

        parser.add_argument(
            '--use-valgrind',
            action='store_const',
            const=True,
            default=False,
            help=
            'running redis under valgrind (assuming valgrind is install on the machine)'
        )

        parser.add_argument('--valgrind-suppressions-file',
                            default=None,
                            help='path valgrind suppressions file')

        parser.add_argument(
            '--config-file',
            default=None,
            help=
            'path to configuration file, parameters value will be taken from configuration file,'
            'values which was not specified on configuration file will get their value from the command line args,'
            'values which was not specifies either on configuration file nor on command line args will be getting their default value'
        )

        parser.add_argument(
            '--interactive-debugger',
            action='store_const',
            const=True,
            default=False,
            help='runs the redis on a debuger (gdb/lldb) interactivly.'
            'debugger interactive mode is only possible on a single process and so unsupported on cluste or with slaves.'
            'it is also not possible to use valgrind on interactive mode.'
            'interactive mode direcly applies: --no-output-catch and --stop-on-failure.'
            'it is also implies that only one test will be run (if --inv-only was not specify), an error will be raise otherwise.'
        )

        parser.add_argument('--debugger-args',
                            default=None,
                            help='arguments to the interactive debugger')

        parser.add_argument(
            '--no-output-catch',
            action='store_const',
            const=True,
            default=False,
            help='all output will be written to the stdout, no log files.')

        configFilePath = './%s' % RLTest_CONFIG_FILE_NAME
        if os.path.exists(configFilePath):
            args = [
                '%s%s' % (RLTest_CONFIG_FILE_PREFIX, RLTest_CONFIG_FILE_NAME)
            ] + sys.argv[1:]
        else:
            args = sys.argv[1:]
        self.args = parser.parse_args(args=args)

        if self.args.interactive_debugger:
            if self.args.env != 'oss' and self.args.env != 'enterprise':
                print Colors.Bred(
                    'interactive debugger can only be used on non cluster env')
                sys.exit(1)
            if self.args.use_valgrind:
                print Colors.Bred(
                    'can not use valgrind with interactive debugger')
                sys.exit(1)
            if self.args.use_slaves:
                print Colors.Bred(
                    'can not use slaves with interactive debugger')
                sys.exit(1)

            self.args.no_output_catch = True
            self.args.stop_on_failure = True

        if self.args.download_enterprise_binaries:
            self._downloadEnterpriseBinaries()

        if self.args.clear_logs:
            try:
                shutil.rmtree(self.args.log_dir)
            except Exception:
                pass

        Env.defaultModule = self.args.module
        Env.defaultModuleArgs = self.args.module_args
        Env.defaultEnv = self.args.env
        Env.defaultOssRedisBinary = self.args.oss_redis_path
        Env.defaultVerbose = self.args.verbose
        Env.defaultLogDir = self.args.log_dir
        Env.defaultUseSlaves = self.args.use_slaves
        Env.defaultShardsCount = self.args.shards_count
        Env.defaultProxyBinaryPath = self.args.proxy_binary_path
        Env.defaultEnterpriseRedisBinaryPath = self.args.enterprise_redis_path
        Env.defaultEnterpriseLibsPath = self.args.enterprise_lib_path
        Env.defaultUseAof = self.args.use_aof
        Env.defaultDebugPrints = self.args.debug_print
        Env.defaultUseValgrind = self.args.use_valgrind
        Env.defaultValgrindSuppressionsFile = self.args.valgrind_suppressions_file
        Env.defaultInteractiveDebugger = self.args.interactive_debugger
        Env.defaultInteractiveDebuggerArgs = self.args.debugger_args
        Env.defaultNoCatch = self.args.no_output_catch

        sys.path.append(self.args.tests_dir)

        self.tests = []

        self.currEnv = None
Esempio n. 25
0
    def get_symbols_style(self):
        symbols_style = {}
        
        ocad_symbols = self._of.symbols()
        ocad_colors = self._of.colors()
        self.rgb_colors = Colors.convert_cmyk_hash(dict(ocad_colors), icc=True)
        
        self.color_index = [data[0] for data in reversed(ocad_colors)] # 0 pozicijoje yra ta kuria reikia nupieshti veliausiai, todel apverciam
        
        for symbol_id, symbol in ocad_symbols.items():
            #print "symbol_id: ", symbol_id
            symbol_style = {}
            symbols_style[symbol_id] = symbol_style
             
             
        
            #symbol_id = symbol_id.replace(".", "_")
            color_id = symbol.Color() # reikalinga z-index nustatyti
            type = symbol.Otp()
            #print "gavom pslavo koda :", color_id, " simbolis: ", symbol_id, " tipas:"******"518.0":
                print "518.0 style: ", style
            
            if symbol_id == "503.0":
                print "503.0 style: ", style
                
            if symbol_id == "525.0":
                print "525.0 style: ", style
                
            zindex = None
            
            #0: Normal; 1: Protected; 2: Hidden
            if symbol.Status() == 2: # hidden 
                symbol_style["status"] = 2
            
            symbol_style["color"] = self.rgb_colors.get(color_id, (0,0,0))
            #self.set_symbol_style(symbol_id, {"color": self.rgb_colors.get(color_id, (0,0,0))})
            if color_id in self.color_index:
                zindex = self.color_index.index(color_id)

            if zindex== None:
                print "alert no color!", symbol_id, color_id, self.color_index
            
            if type == ocadfile.Line:
                width = style.LineWidth# or style.DblWidth
                symbol_style["line-width"] = width/100.0 * self._prj.map_scale
                
                if style.DblWidth: # and style.DblFillColor: - color gali buti 0
                    symbol_style["double-width"] = style.DblWidth/100.0 * self._prj.map_scale
                    symbol_style["double-color"] = self.rgb_colors.get(style.DblFillColor, (0,0,0))
                    
                    if style.DblFlags: # 0 - fill off, 1 - fill on, 2 - background on?
                        double_zindex = self.color_index.index(style.DblFillColor)
                        symbol_style["double-z-index"] = double_zindex # jeigu nera zindexo - tai nepaisysime
                        
                        #if double_zindex < zindex:
                        #    zindex = double_zindex
                    
                if style.DblLeftWidth: # and style.DblLeftColor: # spalva nesvarbi jeigu nera plocio! ar atvrksciai
                    symbol_style["double-left-width"] = style.DblLeftWidth/100.0 * self._prj.map_scale
                    symbol_style["double-left-color"] = self.rgb_colors.get(style.DblLeftColor, (0,0,0))
                    double_left_zindex = self.color_index.index(style.DblLeftColor)
                    symbol_style["double-left-z-index"] = double_left_zindex
                    
                    #if double_left_zindex < zindex:
                    #    zindex = double_left_zindex
                    
                if style.DblRightWidth: # and style.DblRightColor: # rusiskuose failuose yra DblRightColor - kuriu neranda index'e!
                    symbol_style["double-right-width"] = style.DblRightWidth/100.0 * self._prj.map_scale
                    symbol_style["double-right-color"] = self.rgb_colors.get(style.DblRightColor, (0,0,0))
                    double_right_zindex = self.color_index.index(style.DblRightColor)
                    symbol_style["double-right-z-index"] = double_right_zindex
                    
                    #if double_right_zindex < zindex:
                    #    zindex = double_right_zindex
                
                if style.MainLength:
                    symbol_style["length-main"] = style.MainLength/100.0 * self._prj.map_scale
                    
                if style.EndLength:
                    symbol_style["length-end"] = style.EndLength/100.0 * self._prj.map_scale
                    
                if style.MainGap:
                    symbol_style["length-gap"] = style.MainGap/100.0 * self._prj.map_scale
                    
                if style.nPrimSym and style.nPrimSym > 1:
                    symbol_style["symbol-repeat"] = style.nPrimSym
                    symbol_style["symbol-distance"] = style.PrimSymDist/100.0 * self._prj.map_scale
                     
                elements = symbol.Elements()
                if len(elements):
                    shapes = self.create_symbol_data(elements)
                    symbol_style["symbol-data"] = shapes
                    
                    for shape in shapes:
                        new_zindex = shape[2].get("z-index")
                        #if new_zindex < zindex: # randame maziausia z-index'a!
                        #    zindex = new_zindex
                    
            elif type == ocadfile.Point:
                shapes = self.create_symbol_data(symbol.Elements())
                
                zindex = shapes[0][2].get("z-index") # privalo tureti spalva ir z-index'a tuo paciu !
                for shape in shapes[1:]:
                    new_zindex = shape[2].get("z-index")
                    if new_zindex < zindex: # randame maziausia z-index'a!
                        zindex = new_zindex
                
                symbol_style["symbol-data"] = shapes
            
            elif type in (ocadfile.UnformattedText, ocadfile.FormattedText):
                symbol_style["font-size"] = style.FontSize/10
                symbol_style["font-name"] = style.FontName
                symbol_style["font-weight"] = cairo.FONT_WEIGHT_BOLD if style.Weight == 700 else cairo.FONT_WEIGHT_NORMAL
                symbol_style["font-style"] = cairo.FONT_SLANT_ITALIC if style.Italic ==1 else cairo.FONT_SLANT_NORMAL
                #print "TEXT STYLE:", symbol_id, " -:- ", style
            
            symbol_style["z-index"] = zindex

        return symbols_style
Esempio n. 26
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# vim:syntax=python:sw=4:ts=4:expandtab

from utils import Colors

MODKEY = 'Mod4'

# theme
FONT = '-artwiz-snap-*-*-*-*-*-100-*-*-*-*-*-*'

NORMAL_COLORS = Colors(0xb6b4b8, 0x1c2636, 0x0f1729)
FOCUS_COLORS = Colors(0xffffff, 0x1c2636, 0x0f1729)

BAR_NORMAL_COLORS = Colors(0xa0a0a0, 0x505050, 0x404040)
BAR_FOCUS_COLORS = Colors(0xffffff, 0x1c2636, 0x0f1729)

BORDER = 0

# status bar
STATUS_BAR_SEPARATOR = None
STATUS_BAR_START = None
STATUS_BAR_END = None

# dmenu
DMENU_FONT = FONT
DMENU_NORMAL_COLORS = Colors(0xb6b4b8, 0x1c2636)