示例#1
0
文件: Pool.py 项目: crooks/pymaster
 def process(self):
     if timing.now() < self.next_process:
         return 0
     log.debug("Beginning Pool processing.")
     smtp = smtplib.SMTP(config.get('mail', 'server'))
     for fn in self.pick_files():
         if not fn.startswith('m'):
             # Currently all messages are prefixed with an m.
             continue
         fqfn = os.path.join(config.get('paths', 'pool'), fn)
         f = open(fqfn, 'r')
         msg = email.message_from_file(f)
         f.close()
         log.debug("Pool processing: %s", fn)
         if not 'To' in msg:
             log.warn("%s: Malformed pool message. No recipient "
                      "specified.", fn)
             continue
         msg["Message-ID"] = Utils.msgid()
         msg["Date"] = email.Utils.formatdate()
         msg["From"] = "%s <%s>" % (config.get('general', 'longname'),
                                    config.get('mail', 'address'))
         try:
             smtp.sendmail(msg["From"], msg["To"], msg.as_string())
             log.debug("Email sent to: %s", msg["To"])
         except smtplib.SMTPRecipientsRefused, e:
             log.warn("SMTP failed with: %s", e)
         self.delete(fqfn)
示例#2
0
 def __init__(self):
     # This URL checks for an acceptable format of config line.
     self.handled_mime_types = ['text', 'application', 'image']
     user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
     self.headers = { 'User-Agent' : user_agent }
     self.maxsize = config.get('thresholds', 'url_size_limit')
     self.fromhdr = 'url@' + config.get('domains', 'default')
示例#3
0
def resize_images(data_type='train'):
    """Resize the images from 'image_dir' and save into 'output_dir'."""
    if data_type not in ('train', 'test', 'validate'):
        raise ValueError("data_type has to be 'train', 'test' or 'validate'.")

    image_dir, output_dir, image_size = absolute_dir_wrapper(config.get('%s_image_dir' % data_type)), \
                                        absolute_dir_wrapper(config.get('%s_resized_image_dir' % data_type)), \
                                        config.get('image_size')

    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    images = os.listdir(image_dir)
    num_images = len(images)
    for i, image in enumerate(images):
        img_output_dir = os.path.join(output_dir, image)
        if os.path.exists(img_output_dir):
            continue

        with open(os.path.join(image_dir, image), 'r+b') as f:
            with Image.open(f) as img:
                img = img.resize(image_size, Image.ANTIALIAS)
                img.save(img_output_dir, img.format)
        if (i + 1) % 100 == 0:
            print("[{}/{}] Resized {} images.".format(i + 1, num_images,
                                                      data_type))
示例#4
0
文件: libmimix.py 项目: crooks/mimix
 def fn_wrap(*args, **kwargs):
     dbkeys = os.path.join(config.get('database', 'path'),
                           config.get('database', 'directory'))
     with sqlite3.connect(dbkeys) as conn:
         conn.text_factory = str
         retval = fn(conn, *args, **kwargs)
     return retval
示例#5
0
文件: keys.py 项目: crooks/mimix
    def generate(self):
        log.info("Generating new RSA keys")
        seckey = RSA.generate(config.getint('general', 'keylen'))
        pubkey = seckey.publickey()
        pubpem = pubkey.exportKey(format='PEM')
        keyid = hashlib.md5(pubpem).hexdigest()
        expire = config.getint('general', 'keyvalid')

        insert = (keyid,
                  config.get('general', 'name'),
                  config.get('general', 'address'),
                  pubpem,
                  seckey.exportKey(format='PEM'),
                  timing.today(),
                  timing.date_future(days=expire),
                  1,
                  config.getboolean('general', 'smtp'),
                  100,
                  0)
        self.exe('''INSERT INTO keyring (keyid, name, address, pubkey, seckey,
                                         validfr, validto, advertise, smtp,
                                         uptime, latency)
                           VALUES (?,?,?,?,?,?,?,?,?,?,?)''', insert)
        self.conn.commit()
        return (str(keyid), seckey)
示例#6
0
    def get_efi_boot_line(self, grub_dict):
        """Get linuxefi command and initrdefi command from grub_dict

        Get linuxefi command and initrdefi command from grub_dict according to
        specified option on configuration argument while running runner.py
        """
        configuration_type = config.get('general', 'CONFIGURATION_TYPE')
        http_server_ip = config.get('baremetal', 'HTTP_SERVER')
        LOG.info('config_type')
        LOG.info(configuration_type)
        boot_lines = dict()

        if configuration_type == 'simplex':
            boot_lines = grub_dict['aio']['serial']
        elif configuration_type == 'duplex':
            boot_lines = grub_dict['aio']['serial']
        elif configuration_type == 'multinode_controller_storage':
            boot_lines = grub_dict['standard']['serial']
        elif configuration_type == 'multinode_dedicated_storage':
            boot_lines = grub_dict['standard']['serial']

        prefix = 'uefi/images'
        linuxefi_cmd = boot_lines['linuxefi']
        linuxefi_http_cmd = list()

        for parameter in linuxefi_cmd.split(' '):
            if 'inst.ks' in parameter:
                ks_file = parameter.split('/')[-1]
                parameter = 'inst.ks=http://{server}/stx/{iso}/{ks_file}' \
                    .format(server=http_server_ip, iso=self.iso_name,
                            ks_file=ks_file)
                linuxefi_http_cmd.append(parameter)
            elif 'inst.stage2' in parameter:
                parameter = 'inst.stage2=http://{server}/stx/{iso}' \
                    .format(server=http_server_ip, iso=self.iso_name)
                linuxefi_http_cmd.append(parameter)
            elif 'vmlinuz' in parameter:
                parameter = '{prefix}{parameter}'.format(prefix=prefix,
                                                         parameter=parameter)
                linuxefi_http_cmd.append(parameter)
            else:
                linuxefi_http_cmd.append(parameter)
        inst_repo = 'inst.repo=http://{server}/stx/{iso}'\
            .format(server=http_server_ip, iso=self.iso_name)
        linuxefi_http_cmd.append(inst_repo)
        boot_lines['linuxefi'] = ' '.join(linuxefi_http_cmd)

        initrd_cmd = boot_lines['initrdefi']
        initrd_prefix_cmd = list()

        for parameter in initrd_cmd.split(' '):
            if 'initrd.img' in parameter:
                parameter = '{prefix}{parameter}'.format(prefix=prefix,
                                                         parameter=parameter)
                initrd_prefix_cmd.append(parameter)
            else:
                initrd_prefix_cmd.append(parameter)
        boot_lines['initrdefi'] = ' '.join(initrd_prefix_cmd)
        return boot_lines
示例#7
0
 def __init__(self, secring, idlog, chunkmgr):
     self.destalw = ConfFiles(config.get('etc', 'dest_alw'))
     self.destblk = ConfFiles(config.get('etc', 'dest_blk'))
     self.headalw = ConfFiles(config.get('etc', 'head_alw'))
     self.headblk = ConfFiles(config.get('etc', 'head_blk'))
     self.remailer_type = "mixmaster-%s" % config.get('general', 'version')
     self.secring = secring
     self.idlog = idlog
     self.chunkmgr = chunkmgr
示例#8
0
文件: Mail.py 项目: crooks/pymaster
 def __init__(self, pubring, secring, idlog, encode, chunkmgr):
     maildir = config.get('paths', 'maildir')
     self.inbox = mailbox.Maildir(maildir, factory=None, create=False)
     decode = DecodePacket.Mixmaster(secring, idlog, chunkmgr)
     self.decode = decode
     self.server = config.get('mail', 'server')
     self.pubring = pubring
     self.encode = encode
     log.info("Initialized Mail handler. Mailbox=%s, Server=%s",
               maildir, self.server)
示例#9
0
    def breed(self, num):
        genome_bits = config.get('Igenome-bits')
        mutation_rate = 10000 * config.get('Fmutation-rate')
        new_specimens = []
        while True:
            for i_m, spec_m in enumerate(self.specimens):
                #print('spec_m: ' + str(spec_m))
                m = Util.int2bin(spec_m.seats_potential, genome_bits )
                m += Util.int2bin(spec_m.rect.w, genome_bits)
                m += Util.int2bin(spec_m.rect.h, genome_bits)
                m += Util.int2bin(spec_m.rows, genome_bits)
                m += Util.int2bin(spec_m.rows_spacing, genome_bits)
                m += Util.int2bin(spec_m.seat_separator, genome_bits)
                while True:
                    i_f = randrange(0,len(self.specimens))
                    if i_f == i_m:
                        continue;
                    else:
                        spec_f = self.specimens[i_f]
                        #print('spec_f: ' + str(spec_f))
                        f = Util.int2bin(spec_f.seats_potential, genome_bits )
                        f += Util.int2bin(spec_f.rect.w, genome_bits)
                        f += Util.int2bin(spec_f.rect.h, genome_bits)
                        f += Util.int2bin(spec_f.rows, genome_bits)
                        f += Util.int2bin(spec_f.rows_spacing, genome_bits)
                        f += Util.int2bin(spec_f.seat_separator, genome_bits)

                        n = self._crossover(m, f)

                        mut = randrange(0,10000)
                        if mut <= mutation_rate:
                            print 'mutate!'
                            n = self._mutate(n)

                        def get_chunks(n):
                            n = "".join(n)
                            for i in range(0, len(n), genome_bits):
                                yield n[i:i+genome_bits]

                        g = get_chunks(n)
                        seats_n = Util.bin2int(g.next())
                        width = Util.bin2int(g.next())
                        height = Util.bin2int(g.next())
                        rows = Util.bin2int(g.next())
                        rows_spacing = Util.bin2int(g.next())
                        seat_separator = Util.bin2int(g.next())
                        #print 'new seats: %d' % seats_n
                        spec_n = Specimen(width, height, seats_n, rows, rows_spacing, seat_separator)
                        #print('spec_n: ' + str(spec_n))
                        new_specimens.append(spec_n)
                        break
                if len(new_specimens) >= num:
                    return new_specimens
                    break
示例#10
0
文件: Client.py 项目: crooks/mimix
def server_mode(args):
    pidfile = os.path.join(config.get('general', 'piddir'),
                           config.get('general', 'pidfile'))
    errlog = os.path.join(config.get('logging', 'dir'), 'err.log')
    s = server.Server(pidfile, stderr=errlog)
    if args.start:
        s.start()
    elif args.stop:
        s.stop()
    elif args.run:
        s.run(conlog=True)
示例#11
0
    def follow_node_installation(self):
        """This function is intended to follow nodes installation"""

        user_name = config.get('credentials', 'STX_DEPLOY_USER_NAME')
        password = config.get('credentials', 'STX_DEPLOY_USER_PSWD')

        LOG.info('Node %s: Following node installation.', self.name)
        installation = pexpect.spawn(
            ('ipmitool -I lanplus -H {node_bmc_ip} '
             '-U {node_bmc_user} -P {node_bmc_pswd} '
             'sol activate').format(node_bmc_ip=self.bmc_ip,
                                    node_bmc_user=self.bmc_user,
                                    node_bmc_pswd=self.bmc_pswd))
        installation.logfile = open(
            '{}/iso_setup_installation.txt'.format(LOG_PATH), 'wb')
        installation.timeout = int(config.get('iso_installer', 'BOOT_TIMEOUT'))
        installation.expect('Start PXE over IPv4.')
        LOG.info('Node %s: Trying to boot using PXE', self.name)
        installation.expect('Linux version')
        LOG.info('Node %s: Loading Linux Kernel', self.name)
        installation.expect('Welcome to')
        LOG.info('Node %s: CentOS have been loaded', self.name)
        installation.expect('Starting installer, one moment...')
        LOG.info('Node %s: Starting installer ...', self.name)
        installation.expect('Performing post-installation setup tasks')
        LOG.info('Node %s: Performing post-installation setup tasks',
                 self.name)
        installation.expect('login:'******'Node %s: the system boot up correctly', self.name)
        LOG.info('Node %s: logging into the system', self.name)
        installation.sendline(user_name)
        installation.expect('Password:'******'Node %s: setting a new password', self.name)
        installation.expect('UNIX password:'******'New password:'******'Retype new password:'******'$')
        LOG.info('Node %s: the password was changed successfully', self.name)
        installation.close()
        LOG.info(
            'Node %s: Closing SOL session after successfully '
            'installation', self.name)
        deactivate_sol = bash(
            ('ipmitool -I lanplus -H {node_bmc_ip} '
             '-U {node_bmc_user} -P {node_bmc_pswd} '
             'sol deactivate').format(node_bmc_ip=self.bmc_ip,
                                      node_bmc_user=self.bmc_user,
                                      node_bmc_pswd=self.bmc_pswd))
        if not deactivate_sol.stderr:
            LOG.info('Node %s: SOL session closed successfully', self.name)
示例#12
0
    def configure_temp_network(self):
        """Setup a temporal controller IP"""

        controller_tmp_ip = config.get('iso_installer', 'CONTROLLER_TMP_IP')
        controller_tmp_gateway = config.get('iso_installer',
                                            'CONTROLLER_TMP_GATEWAY')
        LOG.info('Configuring temporal network')

        self.child.expect(PROMPT)

        # -----------------------------
        # getting OS network interfaces
        timeout_before = self.child.timeout
        self.child.timeout = 10
        self.child.sendline('ls /sys/class/net')
        cmd_stdout = []

        try:
            for stdout in self.child:
                cmd_stdout.append(stdout.strip().decode('utf-8'))
        except pexpect.exceptions.TIMEOUT:
            LOG.info('custom timeout reached')

        network_interfaces = []
        network_interfaces.extend(''.join(cmd_stdout[-1:]).split())
        # returning to the original timeout value
        self.child.timeout = timeout_before
        controller_tmp_interface = network_interfaces[0]
        # -----------------------------

        self.child.sendline('sudo ip addr add {0}/24 dev {1}'.format(
            controller_tmp_ip, controller_tmp_interface))
        self.child.expect('Password:'******'sudo ip link set {} up'.format(controller_tmp_interface))

        self.child.expect(PROMPT)
        self.child.sendline(
            'sudo ip route add default via {}'.format(controller_tmp_gateway))

        LOG.info('Network configured, testing ping')
        self.child.sendline('ping -c 1 127.0.0.1')
        self.child.expect('1 packets transmitted')
        LOG.info('Ping successful')

        # updating networks in the config.ini
        configuration_file = os.path.join(PROJECT_PATH, 'Config', 'config.ini')
        configuration_type = config.get('general', 'CONFIGURATION_TYPE')
        network.update_networks_config(network_interfaces, configuration_file,
                                       configuration_type)
示例#13
0
文件: Chain.py 项目: crooks/pymaster
 def __init__(self, pubring):
     mlist2 = config.get('keys', 'mlist2')
     if not os.path.isfile(mlist2):
         raise ChainError("%s: Stats file not found" % mlist2)
     self.mlist2 = mlist2
     self.shortname = config.get('general', 'shortname')
     self.pubring = pubring
     # The following two variables define the time when the statfile was
     # last modified.
     self.exittime = 0
     self.nodetime = 0
     log.info("Chain handler initialised. Stats=%s", mlist2)
示例#14
0
文件: Mail.py 项目: crooks/pymaster
 def send_remailer_key(self):
     msg = email.message.Message()
     payload = '%s\n\n' % Utils.capstring()
     payload += 'Here is the Mixmaster key:\n\n'
     payload += '=-=-=-=-=-=-=-=-=-=-=-=\n'
     f = open(config.get('keys', 'pubkey'), 'r')
     payload += f.read()
     f.close()
     msg.set_payload(payload)
     msg["Subject"] = "Remailer key for %s" % config.get('general',
                                                         'shortname')
     return msg
示例#15
0
文件: Mail.py 项目: crooks/pymaster
 def send_remailer_adminkey(self):
     filename = config.get('etc', 'adminkey')
     msg = email.message.Message()
     if os.path.isfile(filename):
         f = open(filename, 'r')
         payload = f.read()
         f.close()
     else:
         payload = "No adminkey available\n"
     msg.set_payload(payload)
     msg["Subject"] = ("Admin PGP Key for the %s Remailer"
                       % config.get('general', 'shortname'))
     return msg
示例#16
0
 def __init__(self):
     self.senderprog = ["/usr/sbin/sendmail", "-t"]
     self.footer = config.get("email", "footer")
     self.registerTemplate = config.get("email", "register")
     self.registerSubject = config.get("email", "registersubject")
     self.deleteTemplate = config.get("email", "delete")
     self.deleteSubject = config.get("email", "deletesubject")
     self.updateOldSubject = config.get("email", "updateoldsubject")
     self.updateOldTemplate = config.get("email", "updateold")
     self.updateNewSubject = config.get("email", "updatenewsubject")
     self.updateNewTemplate = config.get("email", "updatenew")
     self.mailaddress = config.get("email", "myaddress")
     self.doSend = self.sendWithProg
示例#17
0
文件: Mail.py 项目: crooks/pymaster
 def send_remailer_help(self):
     filename = config.get('etc', 'helpfile')
     msg = email.message.Message()
     if os.path.isfile(filename):
         f = open(filename, 'r')
         payload = f.read()
         f.close()
     else:
         payload = "No help information available\n"
     msg.set_payload(payload)
     msg["Subject"] = ("Help info for the %s remailer"
                       % config.get('general', 'shortname'))
     return msg
示例#18
0
文件: Pool.py 项目: crooks/pymaster
 def __init__(self, encode):
     self.next_process = timing.future(mins=1)
     self.interval = config.get('pool', 'interval')
     self.rate = config.getint('pool', 'rate')
     self.size = config.getint('pool', 'size')
     self.pooldir = config.get('paths', 'pool')
     # We need the packet encoder in order to generate dummy messages.
     self.encode = encode
     log.info("Initialised pool. Path=%s, Interval=%s, Rate=%s%%, "
              "Size=%s.",
              self.pooldir, self.interval, self.rate, self.size)
     log.debug("First pool process at %s",
               timing.timestamp(self.next_process))
示例#19
0
def run_evaluator(drawsurf, circles, gen_evaluator, generation):
    one_seat_space = config.get('Fseat-size') ** 2
    for spec_c, specimen in enumerate(generation):
        for i in xrange(1, config.get('Ipacking-iter')):
            Util.pack(circles, specimen, damping=0.1/i )

        if config.getControl('showing specimen') == 0:
            ds = drawsurf
        else:
            ds = None
        standing, sitting, seats_space, floor_space, stat, cost, comfort, space =\
                process_specimen(ds, specimen, circles, one_seat_space)
        gen_evaluator.addStat(spec_c, stat,( standing, sitting, seats_space, floor_space, stat, cost, comfort, space) )
        yield spec_c, specimen, standing, sitting, seats_space, floor_space, stat, cost, comfort, space
示例#20
0
def get_loader(data_type):
    print('loading %s data' % data_type)
    if data_type not in ('train', 'test', 'validate'):
        raise ValueError("data_type has to be 'train', 'test' or 'validate'.")

    resize_images(data_type)

    root = absolute_dir_wrapper(config.get('%s_resized_image_dir' % data_type))
    json = absolute_dir_wrapper(config.get('%s_caption_path' % data_type))
    vocab = build_and_save_vocab()

    transform = transforms.Compose([
        transforms.RandomCrop(config.get('crop_size')),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize(config.get('img_mean'), config.get('img_std'))
    ])

    batch_size = config.get('batch_size')
    shuffle = config.get('shuffle')
    num_workers = config.get('workers')

    coco = CocoDataset(root=root, json=json, vocab=vocab, transform=transform)

    data_loader = torch.utils.data.DataLoader(dataset=coco,
                                              batch_size=batch_size,
                                              shuffle=shuffle,
                                              num_workers=num_workers,
                                              collate_fn=collate_fn)
    return data_loader
示例#21
0
文件: Utils.py 项目: crooks/pymaster
def capstring():
    """Return the remailer capstring.
    """
    caps = '$remailer{\"%s\"} = ' % config.get('general', 'shortname')
    caps += '\"<%s> mix' % config.get('mail', 'address')
    if config.getboolean('general', 'middleman'):
        caps += ' middle'
    if config.getint('pool', 'size') >= 5:
        caps += ' reord'
    if config.has_option('general', 'extflags'):
        caps += ' %s' % config.get('general', 'extflags')
    caps += ' klen%s' % config.getint('general', 'klen')
    caps += '\";'
    return caps
示例#22
0
    def boot_installer(self):
        """Interact with the installation process at boot time

        The aim of this function is send the appropriate arguments in order to
        boot the ISO
        """
        boot_timeout = int(config.get('iso_installer', 'BOOT_TIMEOUT'))
        self.child.expect('Escape character')
        LOG.info('connected to the VM (controller-0)')
        # send a escape character
        self.child.sendline('\x1b')
        self.child.expect('boot:')
        cmd_boot_line = common.get_cmd_boot_line()
        self.child.sendline(cmd_boot_line)
        LOG.info('kernel command line sent: %s', cmd_boot_line)
        # send a enter character
        self.child.sendline('\r')
        # setting a boot timeout
        self.child.timeout = boot_timeout
        self.child.expect('Loading vmlinuz')
        LOG.info('Loading vmlinuz')
        self.child.expect('Loading initrd.img')
        LOG.info('Loading initrd.img')
        self.child.expect('Starting installer, one moment...')
        LOG.info('Starting installer ...')
        self.child.expect('Performing post-installation setup tasks')
        LOG.info('Performing post-installation setup tasks')
示例#23
0
 def __init__(self):
     self.secring = config.get('keys', 'secring')
     # State that we last did a Cache reload at some arbitrary date in the
     # past.
     self.last_cache = timing.dateobj('2000-01-01')
     # The cache will hold all the keys (as objects, keyed by keyid).
     self.cache = {}
     if not os.path.isfile(self.secring):
         # If the Secret Keyring doesn't exist, we certainly want to
         # generate a new keypair.
         log.info("Secret Keyring %s doesn't exist.  Generating new Key "
                  "pair.", self.secring)
         self.newkeys()
     self.read_secring()
     # self.cache is always defined because read_keyring initializes it.
     if len(self.cache) == 0:
         # We have no valid keys!  Better generate a new Secret/Public pair
         # and write them to the approprite files.  This should probably
         # only happen on initiation of a new remailer or after a very long
         # period of inactivity.  At all other times the expire/renew
         # process should take care of it.
         self.newkeys()
         self.read_secring()
     log.info("Initialized Secring. Path=%s, Keys=%s",
              self.secring, len(self.cache))
示例#24
0
文件: keys.py 项目: crooks/mimix
 def advertise(self, mykey):
     # mykey is a tuple of (Keyid, BinarySecretKey)
     criteria = (mykey[0],)
     self.exe("""SELECT name,address,validfr,validto,smtp, pubkey
              FROM keyring WHERE keyid=?""", criteria)
     name, address, fr, to, smtp, pub = self.cursor.fetchone()
     filename = os.path.join(config.get('http', 'wwwdir'),
                             'remailer-conf.txt')
     with open(filename, 'w') as f:
         f.write("Name: %s\n" % name)
         f.write("Address: %s\n" % address)
         f.write("KeyID: %s\n" % mykey[0])
         f.write("Valid From: %s\n" % fr)
         f.write("Valid To: %s\n" % to)
         f.write("SMTP: %s\n" % libmimix.booltext(smtp))
         f.write("\n%s\n\n" % pub)
         # Only the addresses of known remailers are advertised. It's up to
         # the third party to gather further details directly from the
         # source.  The query only grabs distinct addresses as we only
         # expect to find a single remailer per address, even if multiple
         # keys may be current.
         self.exe('''SELECT DISTINCT address FROM keyring
                WHERE keyid != ? AND advertise''', criteria)
         data = self.cursor.fetchall()
         f.write("Known remailers:-\n")
         for row in data:
             f.write("%s\n" % row)
     log.debug("Wrote HTML config to: %s", filename)
示例#25
0
 def __init__(self):
     pubring = config.get('keys', 'pubring')
     if not os.path.isfile(pubring):
         raise PubringError("%s: Pubring not found" % pubring)
     self.pubring = pubring
     self.read_pubring()
     log.info("Initialized Pubring. Path=%s, Keys=%s",
              pubring, len(self.cache))
    def __init__(self):
        self.waitingQueue = {}
        self.matchingQueue = {}
    
        splitPattern = config.getPattern("SplitPattern")
        subSplitPattern = config.getPattern("SubSplitPattern")
        namePattern = config.getPattern("NamePattern")
        placePattern = config.getPattern("PlacePattern")
        numberPattern = config.getPattern("NumberPattern")
        ignorePattern = config.getPattern("IgnorePattern")
        self.splitFormat = re.compile(splitPattern)
        self.subSplitFormat = re.compile(subSplitPattern)
        self.nameFormat = re.compile(namePattern)
        self.placeFormat = re.compile(placePattern)
        self.numberFormat = re.compile(numberPattern)
        self.ignoreFormat = re.compile(ignorePattern, re.U)
        
        stripMark = config.get("StripMark", "value")
        stripMark = '^{0}+|{0}+$'.format(stripMark)
        self.stripFormat = re.compile(stripMark)
        
        finalReplacePattern = config.items("ReplacePunctuation")
        self.finalReplacement = {}
        for item in finalReplacePattern:
            self.finalReplacement[item[0]] = re.compile(item[1])

        self.name = ["灵梦", "魔理沙", "八云紫", "红美玲", "AA", "BB", "CC"]
        self.place = ["正門", "納屋", "大浴場"]
        self.placeFind = ["正门", "仓库", "大浴场"]
        self.itemReplace = ["苹果", "橘子", "香蕉", "鸭梨"]

        translator = config.get("Translator", "value")
        if translator == "BaiduAPI":
            self.translator = BaiduAPITranslator()
        else:
            self.translator = BaiduTranslator()

        #setting params function
        self.setTranslateParams = self.translator.setParams
        self.stopTranslate = self.translator.stopTranslate
        
        #re related
        self.percentString = re.compile("%[^%]*%")
        #have target text between %%
        self.insideOutPattern = re.compile("%[^%]*\"[^%]*\"[^%^\*^\)]*%")
示例#27
0
def qemu_configuration_files():
    """Custom Qemu configuration files"""

    xml = config.get('qemu', 'XML')
    config_file = config.get('qemu', 'CONFIG_FILE')

    if os.path.isfile(xml):
        # deleting default libvirt networks configuration
        ebash('sudo rm -rf {}'.format(xml))

    parameters = ['user = "******"', 'group = "root"']

    for param in parameters:
        stdout = ebash("sudo cat {0} | grep -w '^{1}'".format(
            config_file, param)).stdout
        if not stdout:
            # the param not in config_file
            ebash("echo '{0}' | sudo tee -a {1}".format(param, config_file))
示例#28
0
 def decrypt(self, keybin, iv):
     # Hash a textual password and then use that hash, along with the
     # extracted IV, as the key for 3DES decryption.
     password = config.get('general', 'passphrase')
     pwhash = MD5.new(data=password).digest()
     des = DES3.new(pwhash, DES3.MODE_CBC, IV=iv)
     decrypted_key = des.decrypt(keybin)
     # The decrypted key should always be 712 Bytes
     return decrypted_key
示例#29
0
文件: Utils.py 项目: crooks/pymaster
def pool_filename(prefix):
    """Make up a suitably random filename for the pool entry.
    """
    while True:
        fn = prefix + Crypto.Random.get_random_bytes(8).encode("hex")
        fq = os.path.join(config.get('paths', 'pool'), fn)
        if not os.path.isfile(fq):
            break
    return fq
示例#30
0
    def __init__(self):
        super().__init__()

        self.translate_url = "https://fanyi-api.baidu.com/api/trans/vip/translate"

        self.appid = config.get("BaiduAPI", "appid")
        self.password = config.get("BaiduAPI", "password")

        self.data = {
            'from': 'jp',  # 输入的语言
            'to': 'zh',  # 需要输出的语言
            'q': None,  # 需要翻译的词或句子
            'appid': self.appid,
            'sign': None,  # 由query生成的一个数字
            'salt': None,
        }

        self.session = requests.session()
示例#31
0
文件: runner.py 项目: starlingx/test
def run_suite_option(suite_name):
    """Run Specified Test Suite and creates the results structure

    Args:
    - suite_name: name of the suite that will be executed
    """

    # Get suite details
    suite = common.Suite(suite_name, MAIN_SUITE)
    # Create results directory if does not exist
    results_dir = common.check_results_dir(SUITE_DIR)
    # Create output directory to store execution results
    output_dir = common.create_output_dir(results_dir, suite.name)
    # Create a link pointing to the latest run
    common.link_latest_run(SUITE_DIR, output_dir)
    # Updating config.ini LOG_PATH variable with output_dir
    config_path = os.path.join(SUITE_DIR, 'Config', 'config.ini')
    update_config_ini(config_ini=config_path, LOG_PATH=output_dir)
    # Get configuration and environent from general config file
    config_type = config.get('general', 'CONFIGURATION_TYPE')
    env = config.get('general', 'ENVIRONMENT')
    env_yaml = config.get('general', 'ENV_YAML_FILE')
    # Check configuration and add it as default to the tags
    default_tag = get_config_tag(config_type)
    # Select tags to be used, empty if not set to execute all
    include_tags = ('{0}AND{1}'.format(default_tag, ARGS.tags)
                    if ARGS.tags else default_tag)
    if ARGS.run_suite_name == 'Setup':
        include_tags = ('{0}AND{1}'.format(include_tags, ARGS.environment))
    metadata_list = get_metadata()
    # Run sxt-test-suite using robot framework
    return robot.run(suite.path,
                     outputdir=output_dir,
                     debugfile=LOG_NAME,
                     test=ARGS.tests,
                     variable=[
                         'CONFIGURATION_TYPE :{}'.format(default_tag),
                         'ENVIRONMENT :{}'.format(env),
                         'ENV_YAML :{}'.format(env_yaml)
                     ],
                     include=include_tags,
                     tagstatinclude=include_tags,
                     metadata=metadata_list)
示例#32
0
文件: IDLog.py 项目: crooks/pymaster
 def __init__(self):
     logfile = config.get('general', 'idlog')
     idlog = shelve.open(logfile, flag='c', writeback=False)
     idexp = config.getint('general', 'idexp')
     nextday = timing.future(days=1)
     self.idlog = idlog
     self.idexp = idexp
     self.nextday = nextday
     log.info("Packet ID log initialized. Entries=%s, ExpireDays=%s",
              len(idlog), idexp)
示例#33
0
文件: IDLog.py 项目: crooks/pymaster
 def __init__(self):
     logfile = config.get('general', 'explog')
     pktlog = shelve.open(logfile, flag='c', writeback=True)
     nextday = timing.future(days=1)
     pktexp = config.getint('general', 'packetexp')
     self.pktlog = pktlog
     self.nextday = nextday
     self.pktexp = pktexp
     log.info("Packet Chunk log initialized. Entries=%s, ExpireDays=%s",
              len(pktlog), pktexp)
示例#34
0
    def __init__(self):
        self._colors = {
            "green": "\033[1;32m",
            "red": "\033[1;31m",
            "yellow": "\033[1;33m",
            "blue": "\033[1;34m",
            "COLOR_END": "\033[1;m",
        }

        self._loglevel = config.get(section="logging", item="loglevel", default="INFO")
示例#35
0
 def setUp(self):
     self.assertEquals(config.get("storage", "dbfile"), "testdata/db.sqlite3")
     with open ("testdata/testdata_twosms", "r") as myfile:
         self.twosms = myfile.readlines()
     with open ("testdata/testdata_manygood", "r") as myfile:
         self.manygood = myfile.readlines()
     with open ("testdata/errordump_utopszkij", "r") as myfile:
         self.utopszkij = myfile.readlines()
     mailer = FakeMailer()
     self.db = Database(mailer)
     self.db.__clear()
示例#36
0
    def config(self, config_file):

        config_timeout = int(
            config.get('installer', 'CONFIG_CONTROLLER_TIMEOUT'))
        self.child.expect(PROMPT)
        LOG.info('Applying configuration (this will take several minutes)')
        self.child.sendline(
            'sudo some_line --config-file {}'.format(config_file))
        self.child.timeout = config_timeout
        self.child.expect('Configuration was applied')
        LOG.info(self.child.before)
 def __init__(self):
     self.mark = config.get('mark', 'value')
     #origin line number in file
     self.originLineNumber = {}
     self.content = []
     self.address = None
     #re get pattern
     translatePattern = config.getPattern("TranslatePattern")
     ignorePattern = config.getPattern("IgnorePattern")
     self.obtain = re.compile(translatePattern)
     self.ignore = re.compile(ignorePattern, re.U)
示例#38
0
    def newkeys(self):
        """Generate a new Secret/Public key and write them to the configured
        files.  In the case of the Secret Key, it's appended to Secring.  The
        Public Key overwrites the existing file.
        """

        log.debug("Generating new keypair")
        keyobj = RSA.generate(1024)
        #public = RSA.public(keyobj)
        secret, public = self.rsaobj2mix(keyobj)
        keyid = MD5.new(data=public[2:258]).hexdigest()
        log.info("Generated new Secret Key with Keyid: %s", keyid)
        iv = Crypto.Random.get_random_bytes(8)
        pwhash = MD5.new(data=config.get('general', 'passphrase')).digest()
        des = DES3.new(pwhash, DES3.MODE_CBC, IV=iv)
        secenc = des.encrypt(secret)
        today = timing.today()
        expire = timing.datestamp(timing.future(
                                 days=config.getint('keys', 'validity_days')))
        f = open(config.get('keys', 'secring'), 'a')
        f.write('-----Begin Mix Key-----\n')
        f.write('Created: %s\n' % today)
        f.write('Expires: %s\n' % expire)
        f.write('%s\n' % keyid)
        f.write('0\n')
        f.write('%s' % iv.encode('base64'))
        f.write('%s\n' % self.wrap(secenc.encode("base64"), 40))
        f.write('-----End Mix Key-----\n\n')
        f.close()
        log.debug("Secret Key written to %s",
                      config.get('keys', 'secring'))
        f = open(config.get('keys', 'pubkey'), 'w')
        f.write('%s ' % config.get('general', 'shortname'))
        f.write('%s ' % config.get('mail', 'address'))
        f.write('%s ' % keyid)
        f.write('2:%s ' % config.get('general', 'version'))
        if config.getboolean('general', 'middleman'):
            conf = "MC"
        else:
            conf = "C"
        f.write('%s ' % conf)
        f.write('%s %s\n\n' % (today, expire))
        f.write('-----Begin Mix Key-----\n')
        f.write('%s\n' % keyid)
        f.write('%s\n' % len(public))
        f.write('%s\n' % self.wrap(public.encode("base64"), 40))
        f.write('-----End Mix Key-----\n\n')
        f.close()
        log.debug("Public Key written to %s",
                      config.get('keys', 'pubkey'))
示例#39
0
文件: Mail.py 项目: crooks/pymaster
 def send_remailer_conf(self):
     msg = email.message.Message()
     payload = "Remailer-Type: %s\n" % config.get('general', 'version')
     payload += "Supported format: Mixmaster\n"
     payload += "Pool size: %s\n" % config.get('pool', 'size')
     payload += ("Maximum message size: %s kB\n"
                 % config.get('general', 'klen'))
     payload += "In addition to other remailers, this remailer also sends "
     payload += "mail to these\n addresses directly:\n"
     #TODO SUpported direct delivery addresses
     payload += "The following header lines will be filtered:\n"
     #TODO Filtered headers
     payload += "The following domains are blocked:\n"
     #TODO Dest Blocks
     payload += '\n%s\n\n' % Utils.capstring()
     payload += "SUPPORTED MIXMASTER (TYPE II) REMAILERS\n"
     for h in self.pubring.headers:
         payload += h + "\n"
     msg.set_payload(payload)
     msg["Subject"] = ("Capabilities of the %s remailer"
                       % config.get('general', 'shortname'))
     return msg
示例#40
0
文件: runner.py 项目: starlingx/test
def get_metadata():
    """Construct default metadata to be displayed on reports

     Return:
         metadata_list: List with names and values to be added as metadata
    """

    metadata_list = []
    system = ('System:{}'.format(config.get('general', 'CONFIGURATION_TYPE')))
    iso = ('ISO:{}'.format(get_iso_name()))
    metadata_list.extend([system, iso])

    return metadata_list
示例#41
0
文件: Logger.py 项目: five3/zyw
def zx_logger(d, cate=25):
    data = {}
    if not d.get('title'):
        print 'no data get'
        return
    data['title'] = d.get('title').text()
    data['content'] = d.get('content').html()
    data['description'] = (len(d.get('content').text()) > 35) and d.get(
        'content').text()[:35] or d.get('content').text()
    data['featured_image'] = d.get('imgs') and d.get(
        'imgs')[0] or '/static/zhiyuw/cy_images/images/infor.jpg'
    des = os.path.join(config.get('images_dir'), 'zx')
    downloader = DownloadImage(des)
    for img in d.get('imgs'):
        src = img.attrib.get('src')
        if not src.startswith('http'):
            src = '%s://%s:%s%s' % (d.get('request_info').get('proxy'),
                                    d.get('request_info').get('hostname'),
                                    d.get('request_info').get('port', 80), src)
        img_path = downloader.download_image(src)
        if img_path:
            img_static_path = config.get('static_dir') + img_path.replace(
                config.get('images_dir'), '')
            data['content'] = data['content'].replace(
                'src="%s"' % src, 'src="%s"' % img_static_path)
        else:
            with open(config.get('log'), 'a') as f:
                f.write('Download Image Fail "' + src + '" For url:' +
                        d.get('request_info').get('url'))
    data['cate'] = cate
    data['reference'] = d.get('request_info').get('url')
    controller.save_content(data)
    if cate == 25:
        with open(config['zx']['log'], 'w') as f:
            f.write('%s\n' % d.get('index'))
    elif cate == 26:
        with open(config['gyrc']['log'], 'w') as f:
            f.write('%s-%s-%s\n' % d.get('index')[:3])
示例#42
0
文件: Mail.py 项目: crooks/pymaster
 def remailer_foo(self, inmsg):
     if not 'Subject' in inmsg:
         # The Subject defines the remailer-foo action.  Without one,
         # there is no action to take.
         return False
     if 'Reply-To' in inmsg:
         # A Reply-To header overrides the address to respond to.
         inmsg['From'] = inmsg['Reply-To']
     elif not 'From' in inmsg:
         # No Reply-To and no From.  We don't know where to send the
         # remailer-foo message so no point in trying.
         return False
     addy = inmsg['From']
     sub = inmsg['Subject'].lower().strip()
     if sub == 'remailer-key':
         outmsg = self.send_remailer_key()
     elif sub == 'remailer-conf':
         outmsg = self.send_remailer_conf()
     elif sub == 'remailer-help':
         outmsg = self.send_remailer_help()
     elif sub == 'remailer-adminkey':
         outmsg = self.send_remailer_adminkey()
     elif sub == 'remailer-stats':
         #TODO Not yet implemented remailer-stats
         return True
     else:
         log.info("%s: No programmed response for this Subject", sub)
         self.msg2file(inmsg)
         return False
     outmsg["From"] = "%s <%s>" % (config.get('general', 'longname'),
                                   config.get('mail', 'address'))
     outmsg["Message-ID"] = Utils.msgid()
     outmsg['Date'] = email.utils.formatdate()
     outmsg['To'] = addy
     self.smtp.sendmail(outmsg["From"], outmsg["To"], outmsg.as_string())
     log.debug("Sent %s to %s", outmsg['Subject'], outmsg['To'])
     return True
示例#43
0
    def handle_grub(self):
        """Pointing source files to http server on grub"""

        installation_type = config.get('general', 'CONFIGURATION_TYPE')
        grub_dict = analyze_grub(os.path.join(self.tftp_dir, 'grub.cfg'))
        grub_lines = self.get_efi_boot_line(grub_dict)
        grub_entry = (
            "menuentry '{config}'{{\n{linuxefi}\n{initrdefi}\n}}".format(
                config=installation_type,
                linuxefi=grub_lines['linuxefi'],
                initrdefi=grub_lines['initrdefi']))
        grub_timeout = 'timeout=5\n'
        with open(os.path.join(self.tftp_dir, 'grub.cfg'), 'w') as grub_file:
            grub_file.writelines(grub_timeout)
            grub_file.write(grub_entry)
示例#44
0
文件: runner.py 项目: starlingx/test
def get_iso_name():
    """Check real name of the ISO used on the deployment

     Return:
         real_name: ISO real name
    """

    name = config.get('general', 'STX_ISO_FILE')
    # Check if synlink was used instead of updating config file
    try:
        real_name = os.readlink('{}/{}'.format(SUITE_DIR, name))
    except OSError:
        real_name = name

    return real_name
示例#45
0
    def configure_temp_network(self):
        """Setup a temporal IP"""

        tmp_ip = config.get('installer', 'some_variable')
        tmp_interface = config.get('installer', 'some_variable')
        tmp_gateway = config.get('iso_installer', 'CONTROLLER_TMP_GATEWAY')
        LOG.info('Configuring temporal network')
        self.child.expect(PROMPT)
        self.child.sendline('sudo ip addr add {0}/24 dev {1}'.format(
            tmp_ip, tmp_interface))
        self.child.expect('Password:'******'sudo ip link set {} up'.format(tmp_interface))

        self.child.expect(PROMPT)
        self.child.sendline(
            'sudo ip route add default via {}'.format(tmp_gateway))

        LOG.info('Network configured, testing ping')
        self.child.sendline('ping -c 1 127.0.0.1')
        self.child.expect('1 packets transmitted')
        LOG.info('Ping successful')
示例#46
0
文件: Client.py 项目: crooks/mimix
def send_msg(args):
    # The Database needs to be open to build Chains and for Mix to encode
    # messages.
    with sqlite3.connect(dbkeys()) as conn:
        conn.text_factory = str
        # Create a message object, either from file or stdin.
        if args.filename:
            with open(args.filename, 'r') as f:
                msg = Parser().parse(f)
        else:
            sys.stdout.write("Type message here.  Finish with Ctrl-D.\n")
            msg = Parser().parsestr(sys.stdin.read())

        # Create or override important headers
        if args.recipient:
            msg['To'] = args.recipient
        if args.sender:
            msg['From'] = args.sender
        if args.subject:
            msg['Subject'] = args.subject
        if 'To' not in msg:
            sys.stderr.write("Message has no recipient specified.\nUse "
                             "\"--recipient RECIPIENT_ADDRESS\" "
                             "to add one.\n")
            sys.exit(1)
        if 'From' not in msg:
            msg['From'] = config.get('general', 'sender')

        m = mix.send(conn, msg.as_string(), args.chainstr)

        if args.stdout:
            sys.stdout.write(m.text)
        else:
            payload = {'base64': m.text}
            url = '%s/collector.py/msg' % m.send_to_address
            try:
                # Send the message to the first hop.
                r = requests.post(url, data=payload)
                if r.status_code == requests.codes.ok:
                    sys.stdout.write("Message delivered to %s\n"
                                     % m.send_to_address)
                else:
                    sys.stderr.write("Delivery to %s failed with status "
                                     "code: %s.\n" % (url, r.status_code))
            except requests.exceptions.ConnectionError:
                #TODO Mark down remailer statistics.
                sys.stderr.write("Unable to connect to %s.\n"
                                 % m.send_to_address)
示例#47
0
    def config_controller(self, config_file):
        """Configure controller with provided configuration file

        :param config_file: which is the configuration file for
            config_controller
        """
        config_controller_timeout = int(
            config.get('iso_installer', 'CONFIG_CONTROLLER_TIMEOUT'))
        self.child.expect(PROMPT)
        LOG.info('Applying configuration (this will take several minutes)')
        self.child.sendline(
            'sudo config_controller --force --config-file {}'.format(
                config_file))
        self.child.timeout = config_controller_timeout
        self.child.expect('Configuration was applied')
        LOG.info(self.child.before)
示例#48
0
def process_specimen(drawsurf, specimen, circles, one_seat_space):
    standing = specimen.update2(drawsurf, circles)
    sitting = len(specimen.seats)
    seats_space = sitting * one_seat_space
    floor_space = specimen.rect.w * specimen.rect.w - seats_space

    cost = config.get('Ffactor-cost') * \
            (config.get('Fmax-cost') - \
            seats_space * config.get('Fcost-seat') - \
            seats_space * config.get('Fcost-space'))
    comfort = config.get('Ffactor-comfort') * \
            (sitting - config.get('Fmin-comfort') )
    space = config.get('Ffactor-capacity') * \
            (sitting + standing - \
            config.get('Fmin-space'))
    if cost < 0 or comfort < 0 or space < 0:
        stat = 0
    else:
        stat = cost + comfort + space

    return standing, sitting, seats_space, floor_space, stat, cost, comfort, space
示例#49
0
    def first_login(self):
        """Change the password at first login"""

        user_name = config.get('credentials', 'STX_DEPLOY_USER_NAME')
        self.child.expect('localhost login:'******'the system boot up correctly')
        LOG.info('logging into the system')
        self.child.sendline(user_name)
        self.child.expect('Password:'******'setting a new password')
        self.child.expect('UNIX password:'******'New password:'******'Retype new password:'******'$')
        LOG.info('the password was changed successfully')
示例#50
0
 def boot_installer(self):
     boot_timeout = int(config.get('installer', 'BOOT_TIMEOUT'))
     self.child.expect('Escape character')
     # send a escape character
     self.child.sendline('\x1b')
     self.child.expect('boot:')
     cmd_boot_line = common.get_cmd_boot_line()
     self.child.sendline(cmd_boot_line)
     LOG.info('kernel command line sent: {}'.format(cmd_boot_line))
     # send a enter character
     self.child.sendline('\r')
     # setting a boot timeout
     self.child.timeout = boot_timeout
     self.child.expect('Loading vmlinuz')
     LOG.info('Loading vmlinuz')
     self.child.expect('Loading initrd.img')
     LOG.info('Loading initrd.img')
     self.child.expect('Starting installer, one moment...')
     LOG.info('Starting installer ...')
     self.child.expect('Performing post-installation setup tasks')
     LOG.info('Performing post-installation setup tasks')
示例#51
0
    def download_image(self, src, fn=None):
        if not fn:
            fn = src.split('/')[-1]

        print "Download Image From: ", src
        try:
            r = requests.get(
                src,
                stream=True)  # here we need to set stream = True parameter
            full_name = self.des_dir + '/' + fn
            with open(full_name, 'wb') as f:
                for chunk in r.iter_content(chunk_size=1024):
                    if chunk:  # filter out keep-alive new chunks
                        f.write(chunk)
                        f.flush()
                f.close()
            return full_name
        except Exception, e:
            with open(config.get('log'), 'a') as f:
                f.write('Download Image Error:' + src + '\nError Info: \n' +
                        e.message)
示例#52
0
def config_controller(config_file):
    """Configures master controller using its corresponding init file"""

    config_controller_timeout = int(
        config.get('iso_installer', 'CONFIG_CONTROLLER_TIMEOUT'))
    nodes_file = os.path.join(os.environ['PYTHONPATH'], 'baremetal',
                              'baremetal_setup.yaml')
    nodes = yaml.safe_load(open(nodes_file))
    controller_0 = nodes['nodes']['controller-0']
    master_controller = Node(controller_0)
    serial_cmd = ('ipmitool -I lanplus -H {node_bmc_ip} -U {node_bmc_user} '
                  '-P {node_bmc_pswd} sol activate'.format(
                      node_bmc_ip=master_controller.bmc_ip,
                      node_bmc_user=master_controller.bmc_user,
                      node_bmc_pswd=master_controller.bmc_pswd))

    configuring_controller = pexpect.spawn(serial_cmd)
    configuring_controller.logfile = open(
        '{}/iso_setup_installation.txt'.format(LOG_PATH), 'wb')
    configuring_controller.sendline('\r')
    configuring_controller.expect(PROMPT)
    LOG.info('Applying configuration (this will take several minutes)')
    configuring_controller.sendline(
        'sudo config_controller --force --config-file {}'.format(config_file))
    configuring_controller.timeout = config_controller_timeout
    configuring_controller.expect('Configuration was applied')
    LOG.info(configuring_controller.before)
    configuring_controller.logfile.close()
    LOG.info('Closing the log')
    configuring_controller.close()
    closing_serial_connection = (bash(
        'ipmitool  -I lanplus -H {node_bmc_ip} -U {node_bmc_user} '
        '-P {node_bmc_pswd} sol deactivate'.format(
            node_bmc_ip=master_controller.bmc_ip,
            node_bmc_user=master_controller.bmc_user,
            node_bmc_pswd=master_controller.bmc_pswd)))
    if closing_serial_connection.stderr:
        LOG.info(closing_serial_connection.stderr)
示例#53
0
def install_iso_master_controller():
    """Launch ISO installation on controller-0"""

    nodes_file = os.path.join(os.environ['PYTHONPATH'], 'baremetal',
                              'baremetal_setup.yaml')
    nodes = yaml.safe_load(open(nodes_file))

    # Update config.ini with OAM and MGMT interfaces
    network_interfaces = []
    network_interfaces.insert(0, nodes['nodes']['controller-0']['oam_if'])
    network_interfaces.insert(1, nodes['nodes']['controller-0']['mgmt_if'])
    configuration_file = os.path.join(PROJECT_PATH, 'Config', 'config.ini')
    configuration_type = config.get('general', 'CONFIGURATION_TYPE')
    network.update_networks_config(network_interfaces, configuration_file,
                                   configuration_type)

    # Installing STX on main controller
    controller_0 = nodes['nodes']['controller-0']
    master_controller = Node(controller_0)
    master_controller.boot_server_to_pxe()
    master_controller.follow_node_installation()

    return master_controller
示例#54
0
def validate(data_loader_valid, encoder, decoder, criterion, vocab):
    encoder.eval()
    decoder.eval()
    valid_losses = AverageMeter()

    alpha_c = config.get('alpha_c', 0.)

    with torch.no_grad():
        for i, (images, captions, lengths) in enumerate(data_loader_valid):
            images = images.to(device)
            captions = captions.to(device)

            features = encoder.forward(images)
            prediction, alphas = decoder.forward(features, captions)

            att_regularization = alpha_c * ((1 - alphas.sum(1))**2).mean()
            loss = criterion(prediction.permute(0, 2, 1),
                             captions) + att_regularization

            total_caption_length = calculate_caption_lengths(
                vocab.word2idx, captions)
            valid_losses.update(loss.item(), total_caption_length)

    return valid_losses.avg
示例#55
0
import soundcloud
from Config import config

client = soundcloud.Client(client_id=config.get('Soundcloud',
                                                'clientid',
                                                fallback='Vide'),
                           client_secret=config.get('Soundcloud',
                                                    'clientsecret',
                                                    fallback='Vide'),
                           username=config.get('Soundcloud',
                                               'username',
                                               fallback='Vide'),
                           password=config.get('Soundcloud',
                                               'password',
                                               fallback='Vide'))


def getPlaylist():
    playlists = client.get('me/playlists')
    data = []
    for playlist in playlists:
        data.append(getPlaylistData(playlist))

    return data


def getPlaylistData(playlist):
    data = {
        "titre": playlist.title,
        "url_image": playlist.artwork_url,
        "uri": playlist.uri,
#!/usr/bin/env python
import os
import subprocess
import shutil
import re
import operator
from Config import config

root = config.get('path', 'root')
defects4j_path = config.get('path', 'defects4j')
defects4j_bin_path = os.path.join(defects4j_path, 'framework', 'bin')
defects4j_projects_path = os.path.join(defects4j_path, 'framework', 'projects')
defects4j_checkout_path = config.get('path', 'checkout')
defects4j_fix_checkout_path = config.get('path', 'fix_checkout')
output_path = config.get('path', 'output')
git_url = config.get('git', 'url')


def str_intersection(s1, s2):
    out = ""
    for c in s1.split("/"):
        if c in s2 and c not in out:
            out += c + "/"
    return out


def parse_project_info(value):
    project_info = {}
    for line in value.splitlines():
        split = line.split(':', 1)
        if len(split) == 2:
示例#57
0
 def __init__(self):
     self.child = pexpect.spawn(config.get('iso_installer', 'VIRSH_CMD'))
     self.child.logfile = open('{}/iso_setup_console.txt'.format(LOG_PATH),
                               'wb')
#!/usr/bin/env python
from __future__ import print_function
import os
import subprocess
import sys
import requests
import time
import signal
from Config import config

root = config.get('path', 'root')
defects4j_checkout_path = config.get('path', 'checkout')
output_path = config.get('path', 'output')


def start_detector_service():
    jar = os.path.join(
        root, "target",
        "automatic-diff-dissection-1.0-jar-with-dependencies.jar")
    cmd = "java -cp %s add.main.Server" % (jar)
    # , stdout=subprocess.PIPE
    pro = subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid)
    time.sleep(2)
    return pro


def stop_detector_service(pro):
    os.killpg(os.getpgid(pro.pid), signal.SIGTERM)
    time.sleep(5)

示例#59
0
from Config import config
from Utils import bash_utils as bash
from Utils import logger
from Utils import network
import kmodpy
import yaml

# reloading config.ini
reload(config)

# Global variables
THIS_PATH = os.path.dirname(os.path.abspath(__file__))

# setup the logger
LOG_FILENAME = 'setup.log'
LOG_PATH = config.get('general', 'LOG_PATH')
LOG = logger.setup_logging(
    'setup', log_file='{path}/{filename}'.format(
        path=LOG_PATH, filename=LOG_FILENAME), console_log=False)


def exit_dict_status(code):
    """Exit status

    The aim of this function is to provide a exit status in dictionary format
    as an string in order to grab it for for perform actions.

    :param code: which is the exit status code
        code 0: which represents an exit status god.
        code 1: which represents an exit status bad.
    """
示例#60
0
import psutil

from Config import config
from Libraries import common
from Utils import logger
from Utils import network

# reloading config.ini
reload(config)

# Global variables
THIS_PATH = os.path.dirname(os.path.abspath(__file__))
PROJECT_PATH = os.path.dirname(THIS_PATH)
CURRENT_USER = getpass.getuser()
PASSWORD = config.get('credentials', 'STX_DEPLOY_USER_PSWD')
PROMPT = '$'

# setup the logger
LOG_FILENAME = 'iso_setup.log'
LOG_PATH = config.get('general', 'LOG_PATH')
LOG = logger.setup_logging('iso_setup',
                           log_file='{path}/{filename}'.format(
                               path=LOG_PATH, filename=LOG_FILENAME),
                           console_log=False)


class Installer(object):
    """Install a StarlingX ISO though serial console"""
    def __init__(self):
        self.child = pexpect.spawn(config.get('iso_installer', 'VIRSH_CMD'))