def __init__(self, settings):
     self.log = log.get('Restrictions')
     self.settings = settings
     # Item split : Major, Chozo or Full
     self.split = settings.restrictions['MajorMinor']
     self.suitsRestrictions = settings.restrictions['Suits']
     # checker function chain used by canPlaceAtLocation
     self.checkers = self.getCheckers()
     self.log = log.get("Restrictions")
     self.static = {}
     self.dynamic = {}
 def __init__(self, itemManager, qty, sm):
     self.itemManager = itemManager
     self.qty = qty
     self.sm = sm
     self.maxItems = 105  # 100 item locs and 5 bosses
     self.maxEnergy = 18  # 14E, 4R
     self.log = log.get('ItemPool')
Exemple #3
0
def incremental_compress(input_folder, output_file, incremental_list_file, log_file, logger=None):
    """
    Incrementally compress folder
    @type incremental_list_file: str
    @type log_file: FileIO
    @param input_folder:
    @param output_file:
    @param log_file:
    @param incremental_list_file:
    @raise errors.BackupException:
    """
    if logger is None:
        logger = log.get(__name__)

    start_time = datetime.now()
    logger.info('Archiving %s to %s' % (input_folder, output_file))
    logger.info('Incremental file: %s' % incremental_list_file)
    result = call(tar_call_arguments + ['--listed-incremental=%s' % incremental_list_file,
                                        '--file=%s' % output_file,
                                        input_folder],
                  stdout=log_file,
                  stderr=log_file)
    if result == 0:
        logger.info('Archiving completed by %s seconds' % (datetime.now() - start_time).seconds)
    else:
        logger.critical('Failed to archive %s' % input_folder)
        raise errors.BackupException('Archiving failed')
Exemple #4
0
def chroot_ssh_command(client, directory, command, can_run):
    logger = log.get(__name__)
    chroot_cmd = 'chroot {0} {1}'.format(directory, command)

    logger.info(chroot_cmd)
    channel = client.get_transport().open_session()
    channel.exec_command(chroot_cmd)
    while True:
        rl, wl, xl = select.select([channel], [], [], 0.1)
        if len(rl) > 0:
            msg = channel.recv(1024)
            msg = msg.strip()
            if msg:
                logger.info(msg)
            elif channel.exit_status_ready():
                break
        else:
            if channel.exit_status_ready():
                break

        if can_run() == False:
            return -255

    retcode = channel.recv_exit_status()
    logger.info('retcode: {0}'.format(retcode))

    return retcode
Exemple #5
0
 def __init__(self, startAP, areaGraph, restrictions):
     self.startAP = startAP
     self.areaGraph = areaGraph
     self.restrictions = restrictions
     self.settings = restrictions.settings
     self.smbm = SMBoolManager()
     self.log = log.get('MiniSolver')
Exemple #6
0
 def get_end_game_instructions(self, winner):
     game_logs = log.get(self.gid)
     instructions = []
     msg = ""
     num = ""
     if winner == 1:
         msg = "Add 3 {0} beads to matchbox #{1} "
         num = 3
         log.write_stats(3)
     if winner == 2:
         msg = "Remove 1 {0} bead from matchbox #{1}"
         num = -1
         log.write_stats(-1)
     if winner == 3:
         msg = "Add 1 {0} bead to matchbox #{1}"
         num = 1
         log.write_stats(1)
     for turn_log in game_logs:
         if '1' in turn_log and 'mb' in turn_log:
             instructions.append({
                 'msg':
                 msg.format(COLORS[turn_log['color']], turn_log['mb']),
                 'num':
                 num,
                 'color':
                 turn_log['color']
             })
     return instructions
Exemple #7
0
def get_ssh_connection(address, user, password=None):
    logger = log.get(__name__)
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(address, username=user, password=password)
    logger.info('Connecting to: {0}@{1}'.format(user, address))

    return ssh
class Launcher:
    logger = log.get(__name__)

    def __init__(self):
        self.dev = hid.device(CHESEN_ELECTRONICS_CORP, USB_MISSILE_LAUNCHER)

        if self.dev is None:
            raise ValueError('Launcher not found.')
        else:
            self.dev.open(CHESEN_ELECTRONICS_CORP, USB_MISSILE_LAUNCHER)

    def send(self, cmd):
        self.dev.send_feature_report(cmd)

    def up(self):
        self.logger.info(Command.UP.name)
        self.send(Command.UP)

    def down(self):
        self.logger.info(Command.DOWN.name)
        self.send(Command.DOWN)

    def left(self):
        self.logger.info(Command.LEFT.name)
        self.send(Command.LEFT)

    def right(self):
        self.logger.info(Command.RIGHT.name)
        self.send(Command.RIGHT)

    def fire(self, nanos=FIRE_TIME):
        self.logger.info(Command.FIRE.name)
        self.send(Command.FIRE)
        usleep(nanos)

    def stop(self):
        """
        Stops an ongoing command

        :return:
        """
        self.logger.info(Command.RESET.name)
        self.send(Command.RESET.value)

    def stream(self, stream):
        """
        Execute a chain of commands

        :param stream: A list of TimedCommand
        :return:
        """
        self.logger.debug("Received stream: {}".format([c.cmd
                                                        for c in stream]))
        for command in stream:
            self.logger.info(command.cmd.name)
            self.send(command.cmd.value)
            usleep(command.nanos)
            self.stop()
Exemple #9
0
def mkdirs_ssh(client, path):
    logger = log.get(__name__)
    cmd = 'mkdir -p {0}'.format(path)
    retcode, _, stdout, stderr = run_ssh_command(client, cmd)
    if retcode != 0:
        logger.error("Failed: {0}".format(cmd))
        return False

    return True
 def __init__(self, sm, itemPool, locations):
     self.sm = sm
     self.itemLocations = []
     self.unusedLocations = locations
     self.currentItems = []
     self.itemPool = itemPool
     self.itemPoolBackup = None
     self.unrestrictedItems = set()
     self.log = log.get('ItemLocContainer')
     self.checkConsistency()
Exemple #11
0
def run_ssh_command(client, command):
    logger = log.get(__name__)
    stdin, stdout, stderr = client.exec_command(command)
    retcode = stdout.channel.recv_exit_status()
    logger.info(command)
    logger.info('retcode: {0}'.format(retcode))
    logger.debug(stdout)
    logger.debug(stderr)

    return retcode, stdin, stdout, stderr
Exemple #12
0
 def __init__(self, startAP, graph, restrictions, emptyContainer):
     self.startAP = startAP
     self.cache = RequestCache()
     self.graph = graph
     self.services = RandoServices(graph, restrictions, self.cache)
     self.restrictions = restrictions
     self.settings = restrictions.settings
     self.runtimeLimit_s = self.settings.runtimeLimit_s
     self.baseContainer = emptyContainer
     self.maxDiff = self.settings.maxDiff
     self.log = log.get('Filler')
Exemple #13
0
    def __init__(self, accessPointList, transitions, bidir=True, dotFile=None):
        self.log = log.get('Graph')

        self.accessPoints = {}
        self.InterAreaTransitions = []
        self.bidir = bidir
        for ap in accessPointList:
            ap.distance = 0
            self.accessPoints[ap.Name] = ap
        for srcName, dstName in transitions:
            self.addTransition(srcName, dstName, bidir)
        if dotFile is not None:
            self.toDot(dotFile)
Exemple #14
0
 def __init__(self, accessPointList, transitions, dotFile=None):
     self.log = log.get('Graph')
     self.accessPoints = {}
     self.InterAreaTransitions = []
     self.EscapeAttributes = {'Timer': None, 'Animals': None}
     for ap in accessPointList:
         self.addAccessPoint(ap)
     for srcName, dstName in transitions:
         self.addTransition(srcName, dstName)
     if dotFile is not None:
         self.toDot(dotFile)
     self.apCache = {}
     self._useCache = False
Exemple #15
0
def safe_umount_ssh(client, path):
    logger = log.get(__name__)
    cmd = 'mount | grep "on {0} type"'.format(path)
    _, _, stdout, stderr = run_ssh_command(client, cmd)

    instances = stdout.read().splitlines()
    logger.info('{0} mounted {1} times'.format(path, len(instances)))
    for instance in instances:
        cmd = 'umount {0} -l'.format(path)
        retcode, _, stdout, stderr = run_ssh_command(client, cmd)
        if retcode != 0:
            logger.error("Failed: {0}".format(cmd))
            return False

    return True
Exemple #16
0
def compress_file(input_file, output_file, logger=None):
    """
    Compressing folder to file
    @param input_file: File to compress
    @param output_file: output tar file
    """
    if logger is None:
        logger = log.get(__name__)
    logger.info('Starting compression of the %s' % input_file)
    if not os.path.isfile(input_file):
        raise IOError('%s is not file or not found' % input_file)
    mode = 'w:gz'
    tar = tarfile.open(output_file, mode)
    tar.add(input_file)
    tar.close()
    logger.info('File %s compressed to file %s' % (input_file, output_file))
 def __init__(self, graphSettings, locations, services):
     self.sm = SMBoolManager()
     self.settings = services.settings
     self.graphSettings = graphSettings
     self.startAP = graphSettings.startAP
     self.superFun = self.settings.superFun
     self.container = None
     self.services = services
     self.restrictions = services.restrictions
     self.areaGraph = services.areaGraph
     self.allLocations = locations
     self.locations = self.areaGraph.getAccessibleLocations(
         locations, self.startAP)
     #        print("nLocs Setup: "+str(len(self.locations)))
     self.itemManager = self.settings.getItemManager(
         self.sm, len(self.locations))
     self.forbiddenItems = []
     self.restrictedLocs = []
     self.lastRestricted = []
     self.bossesLocs = sorted(
         ['Draygon', 'Kraid', 'Ridley', 'Phantoon', 'Mother Brain'])
     self.suits = ['Varia', 'Gravity']
     # organized by priority
     self.movementItems = [
         'SpaceJump', 'HiJump', 'SpeedBooster', 'Bomb', 'Grapple',
         'SpringBall'
     ]
     # organized by priority
     self.combatItems = ['ScrewAttack', 'Plasma', 'Wave', 'Spazer']
     # OMG
     self.bossChecks = {
         'Kraid': self.sm.enoughStuffsKraid,
         'Phantoon': self.sm.enoughStuffsPhantoon,
         'Draygon': self.sm.enoughStuffsDraygon,
         'Ridley': self.sm.enoughStuffsRidley,
         'Mother Brain': self.sm.enoughStuffsMotherbrain
     }
     self.okay = lambda: SMBool(True, 0)
     exclude = self.settings.getExcludeItems(self.locations)
     # we have to use item manager only once, otherwise pool will change
     self.itemManager.createItemPool(exclude)
     self.basePool = self.itemManager.getItemPool()[:]
     self.log = log.get('RandoSetup')
     if len(locations) != len(self.locations):
         self.log.debug("inaccessible locations :" + getLocListStr(
             [loc for loc in locations if loc not in self.locations]))
Exemple #18
0
    def get_status(self):
        res = {}
        res['gid'] = self.gid
        res['board'] = self.board.get_status()
        res['matchbox'], res['colors'] = self.get_matchbox()
        winner = self.board.winner()
        if winner > 0:
            res['instructions'] = self.get_end_game_instructions(winner)
            if winner == 1:
                res['quote'] = random.choice(WIN_QUOTES).decode('utf-8')
            elif winner == 2:
                res['quote'] = random.choice(LOSE_QUOTES).decode('utf-8')
            elif winner == 3:
                res['quote'] = random.choice(DRAW_QUOTES).decode('utf-8')
        res['gameover'] = winner
        res['current_player'] = self.current_player
        res['log'] = log.get(self.gid)

        return res
Exemple #19
0
def compress(input_folder, output_file, log_file, logger=None):
    """
    Compressing folder to file
    @type log_file: FileIO
    @type output_file: str
    @param input_folder: Folder to compress
    @param output_file: output tar file
    """
    if logger is None:
        logger = log.get(__name__)

    start_time = datetime.now()
    logger.info('Starting compression of the folder %s' % input_folder)

    logger.info('Archiving to %s' % output_file)
    result = call(tar_call_arguments + ['--file=%s' % output_file, input_folder], stdout=log_file, stderr=log_file)
    if result == 0:
        logger.info('Archiving completed by %s seconds' % (datetime.now() - start_time).seconds)
    else:
        logger.critical('Failed to archive %s' % input_folder)
        raise errors.BackupException('Archiving failed')
    logger.info('Folder %s compressed to file %s' % (input_folder, output_file))
Exemple #20
0
def send(subject, text, files=None, cfg=None, logger=None):
    """
    Sends mail
    @type text: str
    @param subject: subject of the report
    @param text: text of the report
    @param files: attached files
    @param cfg: ParseConfig object
    @type subject: str
    """
    if logger is None:
        logger = log.get(__name__)

    if files is None:
        files = []
    assert type(files) == list

    logger.debug('Processing report, subject: %s, text length: %s, files: %s' % (subject, len(text), len(files)))

    if cfg is None:
        from config import get_config
        cfg = get_config()

    message = _format_message(subject, text, files, logger, cfg)

    try:
        logger.info('Starting smtp connection')
        smtp = smtplib.SMTP(cfg.get('email', 'host'))
        logger.info('Loggin in mail server')
        smtp.starttls()
        smtp.login(cfg.get('email', 'from'), cfg.get('email', 'password'))
        logger.info('Sending message...')
        smtp.sendmail(cfg.get('email', 'from'), cfg.get('email', 'to'), message.as_string())
        logger.info('Message sent')
        smtp.close()
    except (smtplib.SMTPException, smtplib.SMTPResponseException), e:
        logger.error('Unable to send message: %s' % e)
        raise errors.BackupException('Failed to send report')
Exemple #21
0
# built-in
import time
import pickle
import copy
import inspect
import pprint
import log

console = log.get('console')


def save(str_path, data):
    console.debug("invoking %s(%s)" %
                  (inspect.stack()[0][3], pprint.pformat(locals())))
    _save_cache(str_path, data)


def load(str_path, sec_expired=86400):
    console.debug("invoking %s(%s)" %
                  (inspect.stack()[0][3], pprint.pformat(locals())))
    obj = _load_cache(str_path)
    time_now = time.time()
    time_obj = obj.get('time', 0)
    if not time_obj:
        console.debug("could not retrieve time from cached object")
        return None
    #/if
    time_since = time_now - time_obj
    if time_since > sec_expired:
        console.debug(
            "cache expired; %.2f - %.2f = %.2fsec is greater than %.2fsec" %
Exemple #22
0
#!/usr/bin/env python

import sqlite3;
import log;
import config;

connection = None;
cursor = None;
logger = None;

def load_schema(filename='/opt/portus/share/schema.sql'):
	with open(filename, 'r') as fh:
		contents = fh.read();
	logger.debug("Loading Schema");
	cursor.executescript(contents);
	connection.commit();


# Init stuff
if logger == None:
	logger = log.get(__name__);
logger.debug("Database starting up");
dbfile = config.get('db', 'filename');

if connection == None:
	connection = sqlite3.connect(dbfile);
if cursor == None:
	cursor = connection.cursor();


Exemple #23
0
                        default=True)
    parser.add_argument('--invert',
                        help="invert color range",
                        dest='invert',
                        action='store_true',
                        default=False)

    args = parser.parse_args()

    # local mode
    if args.rom == None:
        print("Need --rom parameter")
        sys.exit(-1)

    log.init(args.debug)
    logger = log.get('Palette')

    if args.seed == 0:
        random.seed(random.randint(0, 9999999))
    else:
        random.seed(args.seed)

    settings = {
        # global same shift for everything flag
        "global_shift": True,

        #set to True if all suits should get a separate hue-shift degree
        "individual_suit_shift": False,

        #set to True if all tileset palettes should get a separate hue-shift degree
        "individual_tileset_shift": False,
Exemple #24
0
"""Statistics and analysis of ensembles and predictions"""

import log, ensembles, doc
from math import inf, fabs

logger = log.get("stats")


def statistics(prediction, ground_truth, beta=1):
    """Computes performance statistics for classifiers.

    Parameters
    ----------
    prediction : set
        Set of objects predicted to be labeled positive.

    ground_truth : set
        Set of objects actually labeled positive.

    beta : float, optional
        Sets the beta for an F-beta score. Defaults to 1.

    Returns
    -------
    (float, float, float)
        Tuple representing (precision, recall, f_beta).
    """
    true_positives = ground_truth & prediction
    false_positives = prediction - ground_truth

    if len(prediction) == 0:  # to avoid division-by-zero errors
from launcher import Launcher, TimedCommand, Command, FIRE_TIME
import log

import sys

import socketserver

logger = log.get("server")
launcher = Launcher()


def usage(exit_code=0):
    print("python server.py [--port 31337]")
    sys.exit(exit_code)


class LaunchControl(socketserver.BaseRequestHandler):
    """
    The RequestHandler class for our server.

    It is instantiated once per connection to the server, and must
    override the handle() method to implement communication to the
    client.
    """
    def handle(self):
        # self.request is the TCP socket connected to the client
        self.data = self.request.recv(1024).strip()
        decoded = self.data.decode('utf-8')
        logger.info("{} wrote: {}".format(self.client_address[0], decoded))
        commands = decoded.split()
        cmd_stream = list()
    def __init__(self, romPatcher, settings, sprite):
        self.logger = log.get('Palette')

        self.romPatcher = romPatcher
        if sprite is not None:
            palettes.update(sprite_palettes[sprite])
        self.romLoader = RomLoader.factory(palettes)
        self.palettesROM = self.romLoader.getROM()
        self.outFile = romPatcher.romFile

        self.max_degree = settings["max_degree"]
        self.min_degree = settings["min_degree"]
        self.invert = settings["invert"]

        #boss_tileset_palettes = [0x213510,0x213798,0x213A2C,0x213BC1]
        #boss_pointer_addresses = [0x7E792,0x7E79B,0x7E7A4,0x7E726]
        #gray doors + hud elements [0x28,0x2A,0x2C,0x2E]
        self.tileset_palette_offsets = [0x212D7C,0x212E5D,0x212F43,0x213015,0x2130E7,0x2131A6,0x213264,0x21335F,0x213447,0x2135E4,0x2136BB,0x21383C,0x21392E,0x213AED,0x213BC1,0x214104,0x2141E3,0x213C9C,0x213D7B,0x213E58,0x213F3D,0x214021,0x213510,0x213798,0x213A2C]
        self.bluedoor_bytes = [0x62,0x64,0x66]
        self.palette_single_bytes = [0x08,0x0A,0x0C,0x0E,0x48,0x4A,0x4C,0x4E,0x50,0x52,0x54,0x56,0x58,0x5A,0x68,0x6A,0x6C,0x6E,0x70,0x72,0x74,0x76,0x78,0x7A]  

        #replaced crateria $00 with $01 pointer for nicer colors on surface crateria (was [0x7E6A8,0x7E6B1,[...] before the change)
        self.pointer_addresses = [0x7E6A8,0x7E6B1,0x7E6BA,0x7E6C3,0x7E6CC,0x7E6D5,0x7E6DE,0x7E6E7,0x7E6F0,0x7E6F9,0x7E702,0x7E70B,0x7E714,0x7E71D,0x7E726,0x7E72F,0x7E738,0x7E765,0x7E76E,0x7E777,0x7E780,0x7E789,0x7E792,0x7E79B,0x7E7A4]
        self.pointers_to_insert = []


        #Fx1 palettes and the length of each individual color palette
        #Ridley room fade-in
        self.fx1_palettes_ri = [0x132509]
        self.fx1_length_ri = [0xD1]
        #Brinstar blue glow
        self.fx1_palettes_gb = [0x6ED9F,0x6EDA9,0x6EDB3,0x6EDBD,0x6EDC7,0x6EDD1,0x6EDDB,0x6EDE5,0x6EDEF,0x6EDF9,0x6EE03,0x6EE0D,0x6EE17,0x6EE21]
        self.fx1_length_gb = [0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02]
        #Red brinstar glow purple
        self.fx1_palettes_rb = [0x6EEDD,0x6EEF1,0x6EF05,0x6EF19,0x6EF2D,0x6EF41,0x6EF55,0x6EF69,0x6EF7D,0x6EF91,0x6EFA5,0x6EFB9,0x6EFCD,0x6EFE1]
        self.fx1_length_rb = [0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07]
        #Wrecked Ship green glow
        self.fx1_palettes_ws = [0x6EAE8,0x6EAF0,0x6EAF8,0x6EB00,0x6EB08,0x6EB10,0x6EB18,0x6EB20,0x13CA61]
        self.fx1_length_ws = [0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x6F]
        #Crateria pulse red, 
        self.fx1_palettes_cr = [0x6FD03,0x6FD15,0x6FD27,0x6FD39,0x6FD4B,0x6FD5D,0x6FD6F,0x6FD81,0x6FD93,0x6FDA5,0x6FDB7,0x6FDC9,0x6FDDB,0x6FDED]
        self.fx1_length_cr = [0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06]
        #Tourian slow pulse red/blue,
        self.fx1_palettes_tr = [0x6F640,0x6F656,0x6F66C,0x6F682,0x6F698,0x6F6AE,0x6F6C4,0x6F6DA,0x6F6F0,0x6F706,0x6F71C,0x6F7AF,0x6F7BF,0x6F7CF,0x6F7DF,0x6F7EF,0x6F7FF,0x6F80F,0x6F81F,0x6F82F,0x6F83F,0x6F84F,0x6F85F,0x6F86F,0x6F87F,0x6F94F,0x6F963,0x6F977,0x6F98B,0x6F99F,0x6F9B3,0x6F9C7,0x6F9DB,0x6F9EF,0x6FA03,0x6FA17,0x6FA2B,0x6FA3F,0x6FA53,0x6F897,0x6F8A3,0x6F8AF,0x6F8BB,0x6F8C7,0x6F8D3,0x6F8DF,0x6F8EB,0x6F8F7,0x6F903,0x6F90F,0x6F91B,0x6F927,0x6F933]
        self.fx1_length_tr = [0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03]
        #Maridia quicksand etc.
        self.fx1_palettes_ma = [0x6F4EF,0x6F503,0x6F517,0x6F52B,0x6F547,0x6F553,0x6F55F,0x6F56B,0x6F57F,0x6F593,0x6F5A7,0x6F5BB,0x6F5CF,0x6F5E3,0x6F5F7,0x6F60B]
        self.fx1_length_ma = [0x07,0x07,0x07,0x07,0x03,0x03,0x03,0x03,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07]
        #Lantern glow
        self.fx1_palettes_lanterns = [0x6EFFD,0x6F00B,0x6F019,0x6F027,0x6F035,0x6F043,0x6F054,0x6F062,0x6F070,0x6F07E]
        self.fx1_length_lanterns = [0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02]

        #this isn't implemented, the other elevator colors are probably managed via the global palette D01A0-0F
        self.ceres_elevator_palettes = [0x137871,0x137881,0x137891,0x1378A1,0x1378B1,0x1378C1,0x1378D1,0x1378E1]
        self.ceres_elevator_palettes_length = [0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05]

        self.beam_palettes = [0x843E1]
        self.beam_palettes_length = [0x4F]

        #This is in the general palette so as a side-effect it also changes things like energy drops, missile tip colors and other things
        self.wave_beam_trail_palettes = [0xD01AA]
        self.wave_beam_trail_length = [0x02]
        
        #Palette used for the tip of super missiles
        self.super_missile_palettes = [0xD01B0]
        self.super_missile_length = [0x02]

        #Single address for grapple extension color, shifted with same hue as beam palette
        self.grapple_beam_palettes = [0xDC687]
        self.grapple_beam_length = [0x00]
        
        #Space Pirate / Mbrain beam color | excluded for now as it also affects a lot of explosion effects
        self.mbrain_beam_palettes = [0xD01A4]
        self.mbrain_beam_length = [0x02]
        
        
        #Boss palettes
        #[sporespawn,kraid,phantoon,botwoon,draygon,crocomire,bomb-torizo,gold-torizo,ridley,mbrain]

        #Draygon, Kraid, Crocomire and Mother Brain have seperate colors hidden in tileset palettes which are addressed in the boss shift function
        #self.spore_spawn_palettes = [0x12E359,0x12E3D9]
        #self.spore_spawn_length = [0x3F,0x8F]
        self.spore_spawn_palettes = [0x12E359]
        self.spore_spawn_length = [0x3F]
        self.kraid_palettes = [0x138687,0x13B3F3,0x13B533,0x13AAB0,0x1386C7]
        self.kraid_length = [0x1F,0x8F,0x7F,0x03,0x0F]
        self.phantoon_palettes = [0x13CA01,0x13CB41]
        self.phantoon_length = [0x0F,0x7F]
        self.botwoon_palettes = [0x199319,0x19971B]
        self.botwoon_length = [0x0F,0x7F]
        #draygon projectiles: 12A237-0F , they are gray so wouldn't shift well to begin with, leaving this out
        self.draygon_palettes = [0x12A1F7,0x1296AF]
        self.draygon_length = [0x4F, 0x1F]
        self.crocomire_palettes = [0x12387D,0x1238CB,0x1238FD]
        self.crocomire_length = [0x1F, 0x08,0x0F]
        self.bomb_torizo_palettes = [0x1506C7,0x150707]
        self.bomb_torizo_length = [0x1F, 0x1F]
        self.gold_torizo_palettes = [0x150747,0x150787,0x020032]
        self.gold_torizo_length = [0x1F,0x1F,0xFF]
        self.ridley_palettes = [0x1362AA,0x13631A,0x13646A]
        self.ridley_length = [0x2F,0xA7,0x29]
        self.mbrain_palettes = [0x149472,0x1494B2,0x14D264,0x16E448,0x16E648,0x16E6AC,0x16E74C,0x16EA08,0x16EC08,0x16EDAC,0x16EF97,0x16F117,0x1494F2,0x14D082,0x16F281]
        self.mbrain_length = [0x1F,0x0F,0x3F,0xFF,0x2C,0x4A,0x4A,0xFF,0xC0,0x98,0xA8,0x78,0x1F,0x5F,0xC4]

        #All enemy palettes have a length of 0x0F
        #enemy_names = [boyon,tatori+young tatori,puyo,cacatac,owtch,mellow,mella,memu,multiviola,polyp,rio,squeept,geruta,holtz,oum,chute,gripper,ripperII,ripper,dragon,shutter1-4,kamer,waver,metaree,fireflea,skultera,sciser,zero,tripper,kamer,sbug+sbug(glitched),sidehopper,desgeega,big sidehopper,big sidehopper(tourian),big desgeega,zoa,viola,skree,yard,"samus" geemer,zeela,norfair geemer,geemer,grey geemer,boulder,ebi+projectile,fune,namihe,coven,yapping maw,kago,beetom,powamp,work robot+work robot(disabled),bull,alcoon,atomic,green kihunter,greenish kihunter,red kihunter,shaktool,zeb,zebbo,gamet,geega,grey zebesian,green zebesian,red zebesian,gold zebesian,pink zebesian,black zebesian]
        self.enemy_palettes = [0x110687,0x110B60,0x11198D,0x111E6A,0x11238B,0x112FF3,0x11320C,0x113264,0x1132BC,0x113A7B,0x113E1C,0x1140D1,0x1145FA,0x114A2B,0x11580C,0x11617B,0x1162C0,0x116457,0x11657B,0x116978,0x116DC7,0x118687,0x1188F0,0x118C0F,0x11900A,0x11965B,0x11980B,0x119B7B,0x119B9B,0x11A051,0x11B0A5,0x11B3A1,0x11B5B3,0x11C63E,0x11C8A6,0x11DFA2,0x11E23C,0x11E57C,0x11E5B0,0x11E5D0,0x130687,0x140687,0x141379,0x14159D,0x1419AC,0x141F4F,0x142AFE,0x14365E,0x144143,0x1446B3,0x145821,0x145BC7,0x146230,0x14699A,0x1469BA,0x1469DA,0x155911,0x19878B,0x1989FD,0x198AC1,0x198EDC,0x190687,0x1906A7,0x1906E7,0x190727,0x1906C7,0x190707 ]

        ####Enemy Palette Groups####
        #Animal "enemies"
        self.animal_palettes = [0x13E7FE,0x13F225,0x19E525,0x19E944]

        #Sidehopper enemies
        self.sidehopper_palettes = [0x11AA48, 0x11B085]

        #Desgeega enemies
        self.desgeega_palettes = [0x11AF85,0x11B217]

        #Lava enemies | not implementing these unless lava color gets randomized eventually | not sure if multiviola should be in here
        #hibashi,puromi,magdollite
        self.lava_enemy_palettes = [0x130CFB,0x131470,0x142C1C]

        #All Metroid-colored enemies:
        self.metroid_palettes = [0x11A725,0x11E9AF,0x14F8E6,0x1494D2]

        self.various_metroid_palettes = [0x14F6D1,0x16E892,0x16E7F2,0x16E8F0]
        self.various_metroid_length = [0x3F,0x27,0x47,0x61]

        #Crateria security eye + face tile
        self.crateria_special_enemies = [0x140F8C,0x1467AC]

        #Wrecked ship sparks
        self.wrecked_ship_special_enemies = [0x146587]

        #Tourian rinka and undocumented zebetite animation palette
        self.tourian_special_enemies = [0x113A5B,0x137D87]

        #Ship is treated as an enemy in the game
        self.ship_palette = 0x11259E

        #G4 statue 2nd half, 1st half is handled via one of the saveroom shifts
        self.statue_palette_ridley = 0x155745
        self.statue_palette_phantoon = 0x155765
        self.statue_base = 0x155785
        self.statue_fadeout_palettes = [0x6E242,0x6E256,0x6E26A,0x6E27E,0x6E292,0x6E2A6,0x6E2BA,0x6E2CE,0x3839C]
        self.statue_fadeout_size = [0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x07]

        #Degree shuffle array for individual tileset shuffles
        #Insert two entries for [0,1,2,4,5,6,7,8]
        #[0 0 1 1 2 2 3 4 4 5 5 6 6 7 7 8 8 9 10 11 12 13 14 15 16]
        self.degree_list=[]

        #Boss degree list follows this order: [sporespawn,kraid,phantoon,botwoon,draygon,crocomire,bomb-torizo,gold-torizo,ridley,mbrain]
        self.boss_degree_list=[]

        ###########################
        #Suit Palette Information:#
        ###########################
        #Loading and heat-damage glow palettes:
        #Every heat palette is seperated by 2 (unused?) bytes
        #Loader Power Suit: 0x6DB6B, 0x6DBBA, 0x6DC09, 0x6DC58, 0x6DCA4 
        #Heat Power Suit: 0x6E466, 0x6E488, 0x6E4AA, 0x6E4CC, 0x6E4EE, 0x6E510, 0x6E532, 0x6E554, 0x6E576, 0x6E598, 0x6E5BA, 0x6E5DC, 0x6E5FE, 0x6E620, 0x6E642, 0x6E664  |||| final one: 0x6E664 ?
        #Loader Varia Suit: 0x6DCD1, 0x6DD20, 0x6DD6F, 0x6DDBE, 0x6DE0A
        #Heat Varia Suit : 0x6E692, 0x6E6B4, 0x6E6D6, 0x6E6F8, 0x6E71A, 0x6E73C, 0x6E75E, 0x6E780, 0x6E7A2, 0x6E7C4, 0x6E7E6, 0x6E808, 0x6E82A, 0x6E84C, 0x6E86E, 0x6E890  |||| final one: 0x6E890 ?
        #Loader Gravity Suit: 0x6DE37, 0x6DE86, 0x6DED5, 0x6DF24, 0x6DF70
        #Heat Gravity Suit: 0x6E8BE, 0x6E8E0, 0x6E902, 0x6E924, 0x6E946, 0x6E968, 0x6E98A, 0x6E9AC, 0x6E9CE, 0x6E9F0, 0x6EA12, 0x6EA34, 0x6EA56, 0x6EA78, 0x6EA9A, 0x6EABC |||| final one: 0x6EABC ?
        #[$9B:9540-$9B:97E0] not suit palettes?
        #other_palette_offsets = [0x0D9400,0x0D9520,0x0D9540,0x0D9560,0x0D9580,0x0D95A0,0x0D95C0,0x0D95E0,0x0D9600,0x0D9620,0x0D9640,0x0D9660,0x0D9680,0x0D96A0,0x0D9780,0x0D97A0,0x0D97C0,0x0D97E0,0x0D9800,0x0D9820,0x0D9840,0x0D9860,0x0D9880,0x0D98A0,0x0D98C0,0x0D98E0,0x0D9900,0x0D9920,0x0D9940,0x0D9960,0x0D9980,0x0D99A0,0x0D99C0,0x0D99E0,0x0D9A00,0x0D9A20,0x0D9A40,0x0D9A60,0x0D9A80,0x0D9AA0,0x0D9AC0,0x0D9AE0,0x0D9B00,0x0D9B20,0x0D9B40,0x0D9B60,0x0D9B80,0x0D9BA0,0x0D9BC0,0x0D9BE0,0x0D9C00,0x0D9C20,0x0D9C40,0x0D9C60,0x0D9C80,0x0D9CA0,0x0D9CC0,0x0D9CE0,0x0D9D00,0x0D9D20,0x0D9D40,0x0D9D60,0x0D9D80,0x0D9DA0,0x0D9DC0,0x0D9DE0,0x0D9E00,0x0D9E20,0x0D9E40,0x0D9E60,0x0D9E80,0x0D9EA0,0x0D9EC0,0x0D9EE0,0x0D9F00,0x0D9F20,0x0D9F40,0x0D9F60,0x0D9F80,0x0D9FA0,0x0D9FC0,0x0D9FE0,0x0DA000,0x0DA020,0x0DA040,0x0DA060,0x0DA080,0x0DA0A0,0x0DA0C0,0x0DA0E0,0x0DA100]


        #########################
        #        SETTINGS        #
        #########################
        self.settings = settings

        #set to True if all suits should get a separate hue-shift degree
        #"individual_suit_shift": True,
        #set to True if all tileset palettes should get a separate hue-shift degree
        #"individual_tileset_shift": True,
        #Match ship palette with power suit palette
        #"match_ship_and_power": True,
        #Group up similar looking enemy palettes to give them similar looks after hue-shifting
        #(e.g. metroids, big+small sidehoppers)
        #"seperate_enemy_palette_groups": True,
        #Match boss palettes with boss room degree
        #"match_room_shift_with_boss": False,
        ### These variables define what gets shifted
        #"shift_tileset_palette": True,
        #"shift_boss_palettes": True,
        #"shift_suit_palettes": True,
        #"shift_enemy_palettes": True,
        #"shift_beam_palettes": True,
        #"shift_ship_palette": True

        #Change offsets to work with SM practice rom, this was just used for easier feature debugging, changes where new palettes are inserted.
        self.practice_rom = False

        # base address to relocate the compressed palettes
        if self.practice_rom == True:
            # practice rom free space 0x2F51C0 -> 0x2F7FFF
            self.base_address = 0x2F51C0
        else:
            # after the custom credits
            self.base_address = 0x2fe0b0

        self.power_palette_offsets = [0x0D9400,0x0D9820,0x0D9840,0x0D9860,0x0D9880,0x0D98A0,0x0D98C0,0x0D98E0,0x0D9900,0x0D9B20,0x0D9B40,0x0D9B60,0x0D9B80,0x0D9BA0,0x0D9BC0,0x0D9BE0,0x0D9C00,0x0D9C20,0x0D9C40,0x0D9C60,0x0D9C80,0x0D9CA0,0x0D9CC0,0x0D9CE0,0x0D9D00,0x6DB6B, 0x6DBBA, 0x6DC09, 0x6DC58, 0x6DCA4,0x6E466, 0x6E488, 0x6E4AA, 0x6E4CC, 0x6E4EE, 0x6E510, 0x6E532, 0x6E554, 0x6E576, 0x6E598, 0x6E5BA, 0x6E5DC, 0x6E5FE, 0x6E620, 0x6E642, 0x6E664,0x6DB8F,0x6DC2D,0x6DC7C,0x6DBDE]
        self.varia_palette_offsets = [0x0D9520,0x0D9920,0x0D9940,0x0D9960,0x0D9980,0x0D99A0,0x0D99C0,0x0D99E0,0x0D9A00,0x0D9D20,0x0D9D40,0x0D9D60,0x0D9D80,0x0D9DA0,0x0D9DC0,0x0D9DE0,0x0D9E00,0x0D9E20,0x0D9E40,0x0D9E60,0x0D9E80,0x0D9EA0,0x0D9EC0,0x0D9EE0,0x0D9F00,0x6DCD1, 0x6DD20, 0x6DD6F, 0x6DDBE, 0x6DE0A,0x6E692, 0x6E6B4, 0x6E6D6, 0x6E6F8, 0x6E71A, 0x6E73C, 0x6E75E, 0x6E780, 0x6E7A2, 0x6E7C4, 0x6E7E6, 0x6E808, 0x6E82A, 0x6E84C, 0x6E86E, 0x6E890,0x6DCF5,0x6DD44,0x6DD93,0x6DDE2]
        self.gravity_palette_offsets = [0x0D9540,0x0D9560,0x0D9580,0x0D95A0,0x0D95C0,0x0D95E0,0x0D9600,0x0D9620,0x0D9640,0x0D9660,0x0D9680,0x0D96A0,0x0D9780,0x0D97A0,0x0D97C0,0x0D97E0,0x0D9800,0x0D9A20,0x0D9A40,0x0D9A60,0x0D9A80,0x0D9AA0,0x0D9AC0,0x0D9AE0,0x0D9B00,0x0D9F20,0x0D9F40,0x0D9F60,0x0D9F80,0x0D9FA0,0x0D9FC0,0x0D9FE0,0x0DA000,0x0DA020,0x0DA040,0x0DA060,0x0DA080,0x0DA0A0,0x0DA0C0,0x0DA0E0,0x0DA100,0x6DE37, 0x6DE86, 0x6DED5, 0x6DF24, 0x6DF70,0x6E8BE, 0x6E8E0, 0x6E902, 0x6E924, 0x6E946, 0x6E968, 0x6E98A, 0x6E9AC, 0x6E9CE, 0x6E9F0, 0x6EA12, 0x6EA34, 0x6EA56, 0x6EA78, 0x6EA9A, 0x6EABC,0x6DE5B,0x6DEAA,0x6DEF9,0x6DF48]
Exemple #27
0
    # parse args
    args = parser.parse_args()

    if args.output is None and args.rom is None:
        print("Need --output or --rom parameter")
        sys.exit(-1)
    elif args.output is not None and args.rom is not None:
        print("Can't have both --output and --rom parameters")
        sys.exit(-1)

    if args.plandoRando != None and args.output == None:
        print("plandoRando param requires output param")
        sys.exit(-1)

    log.init(args.debug)
    logger = log.get('Rando')
    # service to force an argument value and notify it
    argDict = vars(args)

    def forceArg(arg, value, msg):
        if argDict[arg] != value:
            argDict[arg] = value
            print(msg)
            return '\n' + msg
        else:
            return ''

    # if rando preset given, load it first
    if args.randoPreset != None:
        loadRandoPreset(args.randoPreset, args)
Exemple #28
0
import os
import re
import socket

import log

logger = log.get("ftp")

CRLF = "\r\n"
FTP_PORT = 21
RECV_BUF_SZ = 1024


class FTP:
    host = None
    port = FTP_PORT
    socket = None
    user = "******"
    passwd = ""
    sock_file = ""

    def __init__(self, host, port=None, user=None, passwd=None):
        self.host = host
        if port is not None:
            self.port = port
        if user is not None:
            self.user = user
        if passwd is not None:
            self.passwd = passwd
        self.connect()
        self.login()
 def __init__(self):
     self.log = log.get('Compressor')
Exemple #30
0
"""Ensembles of motifs"""

import numpy as np
import settings, log

logger = log.get("ensembles")

class Ensemble:
    """Ensemble base class.
    
    Parameters
    ----------
    image : img.SparseImage
        A sparse image encoding a set of motifs and the points they select from a data set.

    Attributes
    ----------
    size : int
        Number of motifs present in the ensemble.

    domain : img.Point list
        Points classified by motifs in the ensemble.

    motifs : motifs.Motif list
        Motifs present in the ensemble.
    """

    def __init__(self, image):
        # keep the image around for a few things
        logger.info(f"Building ensemble from image {image}...")
        self._image = image
Exemple #31
0
def run():
	logger = log.get("core");
	logger.info("Starting up");
	
	db.load_schema();
	
	portname = config.get('core', 'serialport');
	logger.debug("Opening Serial: {}".format(portname));
	try:
		port = serial.Serial(
			portname,
			baudrate=9600,
			timeout=2,
		);
	except serial.SerialException as e:
		logger.error("Could not open serial port {}".format(portname));
		exit(1);
	
	logger.debug("Checking for GPS device");
	# Check whether there is a GPS device on this serial port
	line = port.readline();
	if line.strip() == '':
		# There doesn't appear to be a GPS device on this port (or anything)
		logger.error("No GPS Device found on serial port %s" % portname);
		exit(1);
	
	logger.debug("Waiting for GPRMC");
	while line[1:6] != 'GPRMC':
		try:
			line = port.readline().strip().decode("utf-8");
		except UnicodeDecodeError:
			pass
		#print(line[1:6]);
	
	logger.debug("Got GPRMC");
	
	pattern = '[A-Z]+,([0-9]{6}),[A-Z],[0-9\.]+,[A-Z],[0-9\.]+,[A-Z],[0-9\.]+,[0-9\.]+,([0-9]{6}).*';
	
	m = re.search(pattern, line);
	
	d = m.group(2);
	t = m.group(1);
	dt = d[2:4] + d[0:2] + t[0:4] + d[4:] + '.' + t[4:];
	
	date = time.strftime("%Y")[0:2] + d[4:] + d[2:4] + d[0:2];
	logger.debug(date);
	
	logger.debug("Setting date: " + dt);
	nl = open("/dev/null", "w");
	subprocess.call(["sudo", "/bin/date",  '-u',  dt],stdout=nl);
	
	# Now need to output status to status file
	statusfile = config.get('core', 'statusfile');
	fh = open(statusfile, 'w');
	fh.write('running');
	fh.close();

	# Prepare the regular expressions
#	ggapattern = '[A-Z]+,([0-9]{6}),([0-9\.]+),([A-Z]),([0-9\.]+),([A-Z]),([0-2]),([0-9]{2}),([0-9\.]+),([0-9\.]+),([0-9\.]+)';
	ggapattern = '\$GPGGA,([0-9]{6}),([0-9\.]+),([NS]),([0-9\.]+),([EW]),([0-2]),([0-9]{2}),([0-9\.]+),([\-]?[0-9]+\.[0-9]),M,([\-]?[0-9]+\.[0-9])';
	ggare = re.compile(ggapattern);
	rmcpattern = '\$GPRMC,([0-9]{6}),[AV],[0-9\.]+,[NS],[0-9\.]+,[EW],([0-9\.]+),([0-3][0-9]{2}\.[0-9]),([0-9]{6}),([0-3][0-9]{2}\.[0-9]),([EW])';
	rmcre = re.compile(rmcpattern);
	
	while True:
		text = port.readline();
		text = text.strip().decode("utf-8");
		
		if text[0] != '$':
			# Caught an incomplete line
			continue;
		
		sentence = text[1:6];
		logger.debug("Recieved {}".format(sentence));
		if sentence == 'GPGGA':
			# Positional data
			try:
				matches = ggare.search(text);
			except AttributeError:
				# Invalid data
				continue;
			parts = matches.groups();
			parts = (date + parts[0],) + parts[1:];
			db.cursor.execute('INSERT INTO points VALUES (?,?,?,?,?,?,?,?,?,?)', parts);
			db.connection.commit();
		elif sentence == 'GPRMC':
			# Transit data
			try:
				matches = rmcre.search(text);
			except AttributeError:
				logging.debug("Invalid GPRMC pattern recieved");
				continue;
			parts = matches.groups();
			d = parts[3]
			date = time.strftime("%Y")[0:2] + d[4:] + d[2:4] + d[0:2];
			parts = (date + parts[0],) + parts[1:3] + parts[4:]
			db.cursor.execute('INSERT INTO transits VALUES (?,?,?,?,?)', parts);
			db.connection.commit();
Exemple #32
0
#!/usr/bin/python2.7

import sys
import os, os.path
import argparse
import log
import paramiko
import socket
import time
import signal
from ssh_helpers import *

log.setup('noderoot', '/var/log')
logger = log.get(__name__)
default_mounts = ['var/tmp', 'run', 'dev', 'proc', 'sys', 'dev/pts']
do_run = True


def can_run():
    global do_run
    return do_run


def signal_handler(signal, frame):
    global do_run
    logger.info('Ctrl-C caught')

    # Ctrl-C pressed more then once!
    if do_run == False:
        sys.exit(1)
Exemple #33
0
"""
This client will allow you to connect to a running server from this project and execute a sequence of commands
with timeouts.
"""

import socket
import sys
import log


class LauncherException(Exception):
    """Launcher hardware/software state error"""
    pass


logger = log.get("client")


def usage(exit_code=0):
    print(
        "NOTE: CMD is one of [UP, DOWN, LEFT, RIGHT, FIRE, RESET]\n\n" +
        "python client.py --port 31337 CMD[,<sleep in nanoseconds/number of missiles>]"
    )
    sys.exit(exit_code)


if __name__ == "__main__":
    if not len(sys.argv) > 3:
        usage(1)
    else:
        if not str.isdigit(sys.argv[2]):
Exemple #34
0
"""Defines sparse images - the result of evaluating motifs on documents.
"""

import orm, log, motifs
import json
from collections import defaultdict
from os import path

logger = log.get("img")


class Point:
    """A node in a document, as selected by a motif.

    Parameters
    ----------
    filepath : str
        The filepath of the document the point is selected from.

    identifier : int
        The identifier for the point in the document at `filepath`.

    Attributes
    ----------
    filepath : str
        The filepath of the document the point is selected from.

    identifier : int
        The identifier for the point in the document at `filepath`.
    """
    def __init__(self, filepath, identifier):
Exemple #35
0
"""Command-line interface for Motel."""

import orm, log, img, doc, ensembles, stats
import click
from motifs import Motif
from os import path
import json, csv

logger = log.get("cli")


# entry point for the cli
@click.group()
@click.option("--quiet", is_flag=True)
def run(quiet):
    """Entry point for the CLI."""
    # if the quiet flag is passed, disable logging to stdout
    if quiet:
        log.enable_quiet_mode()


# make a database from a single document
@run.command()
def test():
    """Test command.

    Notes
    -----
    Only intended to ensure all modules (sans `nlp`) are imported correctly.

    When run, prints "Motel requirements installed and loaded successfully." to standard output.
 def __init__(self, settings, container, fillerFactory):
     self.settings = settings
     self.maxDiff = self.settings.maxDiff
     self.baseContainer = container
     self.fillerFactory = fillerFactory
     self.log = log.get('ChozoWrapperFiller')