Example #1
0
 def test_config_update(self, _, mock: Mock):
     mock.return_value = 2
     conf = Config()
     mock.return_value = 10
     self.assertEqual(True, conf.check_config_update())
     conf.update_config()
     self.assertEqual(10, conf.last_modification)
Example #2
0
 def SetAllSoundFxObjectVolumes(
     self, volume=None
 ):  # MFH - single function to go through all sound objects (and iterate through all sound lists) and set object volume to the given volume
     # MFH TODO - set every sound object's volume here...
     if volume is None:
         self.sfxVolume = Config.get("audio", "SFX_volume")
         self.crowdVolume = Config.get("audio", "crowd_volume")
         volume = self.sfxVolume
     self.starDingSound.setVolume(volume)
     self.bassDrumSound.setVolume(volume)
     self.T1DrumSound.setVolume(volume)
     self.T2DrumSound.setVolume(volume)
     self.T3DrumSound.setVolume(volume)
     self.CDrumSound.setVolume(volume)
     for s in self.acceptSounds:
         s.setVolume(volume)
     for s in self.cancelSounds:
         s.setVolume(volume)
     self.rockSound.setVolume(volume)
     self.starDeActivateSound.setVolume(volume)
     self.starActivateSound.setVolume(volume)
     self.battleUsedSound.setVolume(volume)
     self.rescueSound.setVolume(volume)
     self.coOpFailSound.setVolume(volume)
     self.crowdSound.setVolume(self.crowdVolume)
     self.starReadySound.setVolume(volume)
     self.clapSound.setVolume(volume)
     self.failSound.setVolume(volume)
     self.starSound.setVolume(volume)
     self.startSound.setVolume(volume)
     self.selectSound1.setVolume(volume)
     self.selectSound2.setVolume(volume)
     self.selectSound3.setVolume(volume)
Example #3
0
 def SetAllSoundFxObjectVolumes(
     self,
     volume=None
 ):  #MFH - single function to go through all sound objects (and iterate through all sound lists) and set object volume to the given volume
     #MFH TODO - set every sound object's volume here...
     if volume is None:
         self.sfxVolume = Config.get("audio", "SFX_volume")
         self.crowdVolume = Config.get("audio", "crowd_volume")
         volume = self.sfxVolume
     self.starDingSound.setVolume(volume)
     self.bassDrumSound.setVolume(volume)
     self.T1DrumSound.setVolume(volume)
     self.T2DrumSound.setVolume(volume)
     self.T3DrumSound.setVolume(volume)
     self.CDrumSound.setVolume(volume)
     for s in self.acceptSounds:
         s.setVolume(volume)
     for s in self.cancelSounds:
         s.setVolume(volume)
     self.rockSound.setVolume(volume)
     self.starDeActivateSound.setVolume(volume)
     self.starActivateSound.setVolume(volume)
     self.battleUsedSound.setVolume(volume)
     self.rescueSound.setVolume(volume)
     self.coOpFailSound.setVolume(volume)
     self.crowdSound.setVolume(self.crowdVolume)
     self.starReadySound.setVolume(volume)
     self.clapSound.setVolume(volume)
     self.failSound.setVolume(volume)
     self.starSound.setVolume(volume)
     self.startSound.setVolume(volume)
     self.selectSound1.setVolume(volume)
     self.selectSound2.setVolume(volume)
     self.selectSound3.setVolume(volume)
Example #4
0
 def test2(self):
     c = Config()
     
     c.from_dict({
         'static_files': {
             'root':'/path/to/root/',
             'filter':'*.jpg'
             },
            
         
         'users':{
             'id_property':'email',
             'data_dir':'/data/system/userdata/'
             },
         
         })
         
     self.assertDictEqual(c['users'], {
             'id_property':'email',
             'data_dir':'/data/system/userdata/'
             })
             
     self.assertDictEqual(c['static_files'], {
             'root':'/path/to/root/',
             'filter':'*.jpg'
             })
def print_model_summary(network):
    sample_inputs = tf.random.normal(shape=(Config.batch_size,
                                            Config.get_image_size()[0],
                                            Config.get_image_size()[1],
                                            Config.image_channels))
    sample_outputs = network(sample_inputs, training=True)
    network.summary()
class ConfigDialog(QtGui.QDialog):
    def __init__(self, parent=None):
        """Initializes the Dialog"""
        self.logger = logging.getLogger('pymetadatamanager.configuration_dialog')
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_ConfigDialog()
        self.ui.setupUi(self)

        self.config = Config()
        self.ui.lineEdit_tv_dirs.setText(",".join(self.config.tv_dirs))
        self.ui.lineEdit_movie_dirs.setText(",".join(self.config.movie_dirs))
        self.ui.checkBox_prefer_local.setChecked(self.config.prefer_local)
        self.ui.lineEdit_mediainfo_path.setText(self.config.mediainfo_path)
        self.ui.pushButton_tv_browse.clicked.connect(self.tv_browser)
        self.ui.pushButton_movie_browse.clicked.connect(self.movie_browser)
        self.ui.pushButton_mediainfo_browse.clicked.connect(self.mediainfo_browser)
        self.ui.buttonBox.accepted.connect(self.save_values)

    def tv_browser(self):
        old_filename = self.ui.lineEdit_tv_dirs.text()
        filename = QtGui.QFileDialog.getExistingDirectory(self, "TV Directory", \
                                                          old_filename)
        if not filename == '':
            self.ui.lineEdit_tv_dirs.setText(filename)
        else:
            self.ui.lineEdit_tv_dirs.setText(old_filename)

    def movie_browser(self):
        old_filename = self.ui.lineEdit_movie_dirs.text()
        filename = QtGui.QFileDialog.getExistingDirectory(self, "Movie Directory", \
                                                          old_filename)
        if not filename == '':
            self.ui.lineEdit_movie_dirs.setText(filename)
        else:
            self.ui.lineEdit_movie_dirs.setText(old_filename)

    def mediainfo_browser(self):
        old_path = self.ui.lineEdit_mediainfo_path.text()
        path = QtGui.QFileDialog.getOpenFileName(self, \
                                             "MediaInfo Path", \
                                             os.path.expanduser("~"))
        if not path == '':
            self.ui.lineEdit_mediainfo_path.setText(path)
        else:
            self.ui.lineEdit_mediainfo_path.setText(old_path)

    def save_values(self):
        del self.config.tv_dirs[:]
        for dir in str(self.ui.lineEdit_tv_dirs.text()).split(","):
            self.config.tv_dirs.append(dir)
        del self.config.movie_dirs[:]
        for dir in str(self.ui.lineEdit_movie_dirs.text()).split(","):
            self.config.movie_dirs.append(dir)
        self.config.mediainfo_path = self.ui.lineEdit_mediainfo_path.text()
        if self.ui.checkBox_prefer_local.isChecked():
            self.config.prefer_local = 1
        else:
            self.config.prefer_local = 0
        self.config.write_config_file()
Example #7
0
def init(engine):
    # define configuration keys for all available mods
    for m in getAvailableMods(engine):
        Config.define("mods", "mod_" + m, bool, False, text = m,  options = {False: _("Off"), True: _("On")})

    # init all active mods
    for m in getActiveMods(engine):
        activateMod(engine, m)
Example #8
0
 def setup(self):
     """"preform basic configuration, create the Config object which enables configuration to preform
     configuration with usage of config.json"""
     logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
     self.config = Config()
     self.config.start()
     self.client = Client(self.config)
     self.agentLog = collector.AgentLogCollector()
     logging.info("Agent initialized successfully!")
Example #9
0
def get_dbcon():
    db = MySQLdb.connect(host=Config.get('Database', 'Host'),
                         user=Config.get('Database', 'User'),
                         passwd=Config.get('Database', 'Password'),
                         db=Config.get('Database', 'Database'),
                         charset='utf8')
    cur = db.cursor()
    cur.execute('SET NAMES utf8mb4')
    return db, cur
Example #10
0
    def build_default(deployment_home, cwd, CommandClasses):
        """
        Create a runtime from the command line arguments and configuration on
        disk.

        If you want something more custom, e.g. in testing, you can build
        it yourself ;)
        """

        if len(CommandClasses):
            arg_parser = CommandClasses[0].build_arg_parser()
        else:
            arg_parser = Runtime.__create_placeholder_arg_parser()
        Runtime.add_default_arguments(arg_parser)

        runtime = Runtime()

        for CommandClass in CommandClasses:
            CommandClass.register_services(runtime)

        for ServiceClass in runtime.each_service_class():
            add_default_arguments_method = getattr(ServiceClass,
                                                   'add_default_arguments',
                                                   None)
            if add_default_arguments_method and callable(
                    add_default_arguments_method):
                ServiceClass.add_default_arguments(arg_parser)

        options = arg_parser.parse_args()
        if not hasattr(options, 'deployment_home'):
            options.deployment_home = deployment_home

        config = Config()
        config.set_options(options)
        config.set_cwd(cwd)
        if hasattr(CommandClass, 'DOTFILE_NAME'):
            config.set_dotfile_name(CommandClass.DOTFILE_NAME)

        try:
            config.read()
        except Exception as e:
            if not hasattr(
                    CommandClass,
                    'is_config_required') or CommandClass.is_config_required():
                exc_info = sys.exc_info()
                raise e, None, exc_info[2]

        log = Log()
        log.set_options(options)

        runtime.set_options(options)
        runtime.set_config(config)
        runtime.set_log(log)
        runtime.set_cwd(cwd)

        return runtime
Example #11
0
	def on_mainWindow_delete_event(self, widget, event):
		# leave edit mode and persist configs to database
		commands.leave_edit_mode(self)
		# persist config to config file
		Config.persist()
		# close Database
		if DB.close() == True:
			return False
		else:
			return True
Example #12
0
def setup_logging():
    verbose = Config.getboolean('Logging', 'VerboseStdout')
    console = logging.StreamHandler()
    console.setLevel(logging.INFO if verbose else logging.WARNING)
    logfile = logging.FileHandler(Config.get('Logging', 'Logfile'))
    logfile.setLevel(logging.INFO)
    logging.basicConfig(
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        level=logging.INFO,
        handlers=[console, logfile])
 def find_facility(board, scanner_index):
     target: Scanner or None = None
     for sb, si in Config.getScanners().items():
         if si.board == board and si.scannerIndex == scanner_index:
             target = si
             break
     if target is not None:
         for fn, fv in Config.getFacilities().items():
             if fv.scanner == target or fv.outscanner == target:
                 return fv, fv.scanner if fv.scanner == target else fv.outscanner
     else:
         return None, None
Example #14
0
class Wrapper(object):
    def __init__(self, config=None, file=None):
        if config:
            self.config = config
        elif file:
            self.config = Config(file)

    def disabled(self):
        self.config.disable()

    def output(self, line):
        print self.config.format(line)
Example #15
0
	def __init__(self):
		self.config = Config()
		self.__running = True
		import os
		os.environ['SDL_VIDEO_CENTERED'] = '1'
		self.__screen = pygame.display.set_mode(
			self.config.get(self.config.RESOLUTION))
		if self.config.get(self.config.FULLSCREEN):
			self.toggle_fullscreen()
		pygame.display.set_caption("ISN Project")
		self.__clock = pygame.time.Clock()
		self.__dtime = 0
		self.__scene = Scenes.test_scene.SceneTest(self)
Example #16
0
 def test6(self):
     s = Config()
     s.from_dict({
             'root':'/path/to/root/',
             'filter':'*.jpg'
             })
         
     c = Config()
     c['static_files'] = s
     
     self.assertDictEqual(c.get('static_files'), {
             'root':'/path/to/root/',
             'filter':'*.jpg'
             })
Example #17
0
def changeconfiguration():
    section = request.form.get('section')
    key = request.form.get('key')
    value = request.form.get('value')

    # solution for checkboxes
    if value is None:
        value = "False"

    Config.update(section, key, value)
    # check if logging changed
    if section == "logging":
        deque_handler.setnrentries(int(Config.get('logging', 'maxlogentries')))
    return redirect(url_for('.showconfiguration'))
Example #18
0
def loadControls():
    global controllerDict
    controllers = []
    allcontrollers = VFS.listdir(controlpath)
    default = ["defaultd.ini", "defaultg.ini", "defaultm.ini"]
    for name in allcontrollers:
        if name.lower().endswith(".ini") and len(name) > 4:
            if name in default:
                continue
            controllers.append(name[0:len(name)-4])

    i = len(controllers)
    controllerDict = dict([(str(controllers[n]),controllers[n]) for n in range(0, i)])
    controllerDict["defaultg"] = _("Default Guitar")
    controllerDict["defaultd"] = _("Default Drum")
    defMic = None
    if Microphone.supported:
        controllerDict["defaultm"] = _("Default Microphone")
        defMic = "defaultm"
    tsControl    = _("Controller %d")
    tsControlTip = _("Select the controller for slot %d")
    i = 1
    Config.define("game", "control0",           str,   "defaultg", text = tsControl % 1,                options = controllerDict, tipText = tsControlTip % 1)

    controllerDict[_("None")] = None

    Config.define("game", "control1",           str,   "defaultd", text = tsControl % 2,                options = controllerDict, tipText = tsControlTip % 2)
    Config.define("game", "control2",           str,   defMic,     text = tsControl % 3,                options = controllerDict, tipText = tsControlTip % 3)
    Config.define("game", "control3",           str,   None,       text = tsControl % 4,                options = controllerDict, tipText = tsControlTip % 4)
    def __init__(self):
        """
        """
        self.testStartTime = datetime.fromtimestamp(
            time.time()).strftime('%Y-%m-%d_%H-%M')
        self.testEndingTime = ""

        # Create tester instance
        parameters = Config.XmlLib.ParseXml(
            ROOT_PATH + os.sep + "configuration" + os.sep +
            "{}.xml".format("CONFIG_SET"), "MAIN_BOARD")

        # Config logger level for system module
        loggerInfo = Config.XmlLib.ParseXml(
            ROOT_PATH + os.sep + "configuration" + os.sep +
            "{}.xml".format("CONFIG_SET"), "LOGGER_INFO")

        self.logger = LoggerEx.ConfigLoggerEx(
            'CTRL', loggerInfo['MOD_LOG_LEVEL']['CTRL'], LOG_FILE_NAME,
            loggerInfo['FORMAT']['FILE'], loggerInfo['FORMAT']['CONSOLE'])

        # Import configuration from XML file
        self.logger.info("\nImport configuration from XML file:")
        self.config = Config.XmlLib(self.logger,
                                    ROOT_PATH + os.sep + "configuration")
        self.logger.info("")
Example #20
0
def showsubscriptions():
    subscriptions = semanticEnrichment.get_subscriptions()
    return render_template(
        'subscriptions.html',
        subscriptions=subscriptions.values(),
        id=str(uuid.uuid4()),
        endpoint=Config.getEnvironmentVariable('SE_CALLBACK'))
Example #21
0
class EventType:

    ARRIVAL = -1
    #Silly implementation, find a workaround
    SERVICE_FINISH = []
    config = Config('perfsim.config')
    NUM_SERVER = config.NUM_SERVER
    for i in range(0, NUM_SERVER):
        SERVICE_FINISH.append(i)
    #NOTE  : Service finish may or may not mean departure

    def type_from_num(self, queue_number):
        #This function will always be called with queue number

        #For zeroth row, the event is SERVICE_FINISH[1]

        return EventType.SERVICE_FINISH[queue_number]

    def queue_from_event(self, etype):
        '''
        Right now, the enumeration is simple. The queue associated with
        SERVICE_FINISH[i] is i - 1
        '''
        return etype

    def name(self, number):
        if (number == -1):
            return "ARRIVAL"
        else:
            return "SERVICE_FINISH Q" + str(number)

    name = classmethod(name)
    type_from_num = classmethod(type_from_num)
    queue_from_event = classmethod(queue_from_event)
Example #22
0
def _subscribe_forTypeId(ngsi_type, entityId, sublist):
    logger.debug("Subscribe for " + str(ngsi_type) + " " + str(entityId))
    # check if subscription already in sublist
    # solution is not optimal... but no other option at the moment
    if entityId:
        for key, value in sublist.items():
            sub = value.subscription
            try:
                tmposid = sub['entities'][0]['id']
                if tmposid == entityId:
                    logger.debug("Subscription for " + tmposid +
                                 " already existing!")
                    return
            except KeyError:
                pass

    # create subscription
    filename = ""
    if ngsi_type is ngsi_parser.NGSI_Type.Sensor:
        filename = 'static/json/subscription_sensor.json'
    elif ngsi_type is ngsi_parser.NGSI_Type.IoTStream:
        filename = 'static/json/subscription_iotstream.json'
    elif ngsi_type is ngsi_parser.NGSI_Type.StreamObservation:
        filename = 'static/json/subscription_streamobservation.json'

    with open(filename) as jFile:
        subscription = json.load(jFile)
        subscription['id'] = subscription['id'] + str(uuid.uuid4())
        # replace callback
        subscription['notification']['endpoint'][
            'uri'] = Config.getEnvironmentVariable('SE_CALLBACK')
        # set entity to subscribe to
        if entityId:
            subscription['entities'][0]['id'] = entityId
        _add_subscription(subscription, sublist)
def draw_boxes_on_image(image, boxes, scores, classes):
    idx2class_dict = Config.idx2class()
    num_boxes = boxes.shape[0]
    for i in range(num_boxes):
        class_and_score = "{}: {:.3f}".format(str(idx2class_dict[classes[i]]),
                                              scores[i])
        cv2.rectangle(img=image,
                      pt1=(boxes[i, 0], boxes[i, 1]),
                      pt2=(boxes[i, 2], boxes[i, 3]),
                      color=(250, 206, 135),
                      thickness=2)

        text_size = cv2.getTextSize(text=class_and_score,
                                    fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                                    fontScale=0.5,
                                    thickness=1)
        text_width, text_height = text_size[0][0], text_size[0][1]
        cv2.rectangle(img=image,
                      pt1=(boxes[i, 0], boxes[i, 1]),
                      pt2=(boxes[i, 0] + text_width,
                           boxes[i, 1] - text_height),
                      color=(203, 192, 255),
                      thickness=-1)
        cv2.putText(img=image,
                    text=class_and_score,
                    org=(boxes[i, 0], boxes[i, 1] - 2),
                    fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                    fontScale=0.5,
                    color=(0, 0, 0),
                    thickness=1)
    return image
Example #24
0
def _initialise_subscriptions(subscriptions):
    # first get active subscriptions
    _get_active_subscriptions(subscriptions)

    # iterate list and check for IotStream, StreamObservation, Sensor subscription, if not found subscribe
    for t in (ngsi_parser.NGSI_Type.IoTStream, ngsi_parser.NGSI_Type.Sensor,
              ngsi_parser.NGSI_Type.StreamObservation):
        subscribe = True
        for key, value in subscriptions.items():
            sub = value.subscription
            try:
                if ngsi_parser.get_type(sub['entities'][0]) is t:
                    # it is of type IotStream, check if it is our endpoint
                    if sub['notification']['endpoint'][
                            'uri'] == Config.getEnvironmentVariable(
                                'SE_CALLBACK'):
                        logger.debug("Subscription for " + str(t) +
                                     " already existing!")
                        subscribe = False
                        break
            except KeyError:
                pass
        if subscribe:
            logger.debug("Initialise system with subscription for " + str(t))
            _subscribe_forTypeId(t, None, subscriptions)
Example #25
0
def users():
    return "Disabled for now"
    page = request.args['page'] if 'page' in request.args else 1
    try:
        page = int(page)
    except:
        page = 1

    page = max(1, page)
    perPage = 200

    g.dbsession = Config.ScopedSession()
    now = datetime.now(utc)

    total = g.dbsession.query(Credential).filter(Credential.expiration > now).count()
    pages = ceil(total / perPage)
    page = min(pages, page)

    pagerange = range(max(0, page - 3) + 1, min(pages, page + 2) + 1)


    members = g.dbsession.query(Credential).filter(Credential.expiration > now)\
        .order_by(Credential.memberid)\
        .order_by(Credential.priority)\
        .order_by(Credential.expiration).offset((page - 1) * perPage).limit(perPage).all()

    membersgrouped = dict((k,list(v)) for k,v in groupby(members, lambda m : m.memberid))

    for k,v in membersgrouped.items():
        #blah = list(v)
        print(k,len(list(v)))

    return render_template('users.html', activity=activity, members=membersgrouped,ctx="users",page=page, pages=pages,pagerange=pagerange)
Example #26
0
    def setPriority(self, pid=None, priority=2):
        """ Set The Priority of a Windows Process.  Priority is a value between 0-5 where
            2 is normal priority.  Default sets the priority of the current
            python process but can take any valid process ID. """

        import win32api, win32process, win32con

        priorityClasses = [
            win32process.IDLE_PRIORITY_CLASS,
            win32process.BELOW_NORMAL_PRIORITY_CLASS,
            win32process.NORMAL_PRIORITY_CLASS,
            win32process.ABOVE_NORMAL_PRIORITY_CLASS,
            win32process.HIGH_PRIORITY_CLASS,
            win32process.REALTIME_PRIORITY_CLASS
        ]

        threadPriorities = [
            win32process.THREAD_PRIORITY_IDLE,
            #win32process.THREAD_PRIORITY_ABOVE_IDLE,
            #win32process.THREAD_PRIORITY_LOWEST,
            win32process.THREAD_PRIORITY_BELOW_NORMAL,
            win32process.THREAD_PRIORITY_NORMAL,
            win32process.THREAD_PRIORITY_ABOVE_NORMAL,
            win32process.THREAD_PRIORITY_HIGHEST,
            win32process.THREAD_PRIORITY_TIME_CRITICAL
        ]

        pid = win32api.GetCurrentProcessId()
        tid = win32api.GetCurrentThread()
        handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
        win32process.SetPriorityClass(handle, priorityClasses[priority])
        win32process.SetThreadPriority(tid, threadPriorities[priority])
        if Config.get('performance', 'restrict_to_first_processor'):
            win32process.SetProcessAffinityMask(handle, 1)
Example #27
0
def cmd_pq(update: Update, context: CallbackContext):
    ci, fro, fron, froi = cifrofron(update)
    msg = update.message
    if (not msg.reply_to_message) or (msg.reply_to_message.from_user.id !=
                                      context.bot.id):
        cmdreply(context.bot, ci, '<send that as a reply to my message!>')
        return

    repl = msg.reply_to_message
    replid = repl.message_id

    if (repl.sticker or not repl.text):
        cmdreply(context.bot, ci, '<only regular text messages are supported>')
        return
    if (replid in pqed_messages) or (already_pqd(repl.text)):
        cmdreply(context.bot, ci, '<message already forwarded>')
        return
    if replid in command_replies:
        cmdreply(context.bot, ci, '<that is a silly thing to forward!>')
        return
    if pq_limit_check(froi) >= 5:
        cmdreply(context.bot, ci, '<slow down a little!>')
        return
    context.bot.forwardMessage(chat_id=Config.get('Telegram', 'QuoteChannel'),
                               from_chat_id=ci,
                               message_id=replid)
    pqed_messages.add(replid)
    log_pq(ci, froi, repl.text)
    def run(self):
        self.reload_boards()
        for api in self.authModules:
            try:
                api.refresh_database()
            except Exception as e:
                logger.error(
                    f"Failed to refresh database, module: {api.__module__}, e: {e}"
                )
        while self._run:
            try:
                r = self._inqueue.get(block=True, timeout=60)
            except Empty:
                #  Do our AWS checks
                for api in self.authModules:
                    try:
                        api.refresh_database()
                    except Exception as e:
                        logger.error(
                            f"Failed to refresh database, module: {api.__module__}, e: {e}"
                        )
                continue

            if type(r) == tuple:
                if r[0] == 'unlock':
                    (c, board, relay, duration, credential) = r
                    self.boards[board].Unlock(relay, duration, credential)
                elif r[0] == "lock":
                    (a, board, relay, credential) = r
                    self.boards[board].Lock(relay, credential)
                elif r[0] == 'aws':
                    for api in self.authModules:
                        api.refresh_database()
                elif r[0] == "status":
                    fv: Facility
                    # def facilityStatus(f : Facility):
                    #    return self.boards[f.board].relaystatus[f.relay]
                    status = dict(
                        (f.name, self.boards[f.board].relaystatus[f.relay])
                        for f in Config.Facilities.values())
                    # status = list(map(facilityStatus,Config.Facilities.values()))
                    self._outqueue.put(status)
                elif r[0] == "query":
                    response = []
                    bv: ReaderBoard
                    for bn, bv in self.boards.items():
                        response.append(bv.__repr__())
                    for bv in query_devices(
                            ignored_devices=self.boards.values()):
                        response.append(bv)
                    self._outqueue.put(response)
                elif r[0] == "reload":
                    # We have to do this here, even though it's also done in the webpanel, because
                    # Config is different here vs webpanel due to multiprocessing
                    Config.Reload()
                    self.reload_boards()
                    for api in self.authModules:
                        api.on_close()
                    self.authModules = self.load_authorizations()
                    self._outqueue.put("OK")
Example #29
0
    def __init__(self,
                 target,
                 name,
                 function,
                 resultQueue,
                 loaderSemaphore,
                 onLoad=None,
                 onCancel=None):
        Thread.__init__(self)
        self.semaphore = loaderSemaphore
        self.target = target
        self.name = name
        self.function = function
        self.resultQueue = resultQueue
        self.result = None
        self.onLoad = onLoad
        self.onCancel = onCancel
        self.exception = None
        self.time = 0.0
        self.canceled = False

        #myfingershurt: the following should be global and done ONCE:
        self.logLoadings = Config.get("game", "log_loadings")

        if target and name:
            setattr(target, name, None)
Example #30
0
def init(engine):
    # define configuration keys for all available mods
    for m in getAvailableMods(engine):
        Config.define("mods",
                      "mod_" + m,
                      bool,
                      False,
                      text=m,
                      options={
                          False: _("Off"),
                          True: _("On")
                      })

    # init all active mods
    for m in getActiveMods(engine):
        activateMod(engine, m)
Example #31
0
class Password:
    def __init__(self):
        self.encryption_key = Config().get_secret()
        if self.encryption_key is None:
            self.set_encryption_key()
        else:  # just take what's given
            self.cipher = Fernet(self.encryption_key)

    def get_encryption_key(self):
        return self.encryption_key

    def set_encryption_key(self):
        self.encryption_key = Fernet.generate_key()
        Config().set_secret(self.encryption_key.decode())  # store as string
        # Don't forget to update the cipher!!!
        self.cipher = Fernet(self.encryption_key)

    def encrypt(self, plain_password):
        return self.cipher.encrypt(plain_password.encode())

    def decrypt(self, encrypted_password):
        try:
            return self.cipher.decrypt(encrypted_password).decode()
        except InvalidToken:
            return "ERROR: Invalid Encryption Key"

    @staticmethod
    def generate(mn=16, mx=64):
        return ''.join(
            choice(ascii_letters + digits) for _ in range(randint(mn, mx)))
async def get_ts_daily_adjusted(symbol: str, config: Config, cache: bool = True) -> pd.DataFrame:
    """Returns time series data for the given symbol using the Alpha Vantage api in an
    async method."""
    ts = TimeSeries(key=config.get('key', 'ALPHA_VANTAGE'),
                    output_format='pandas')
    try:
        data, _ = await ts.get_daily_adjusted(symbol, outputsize='full')
    except ValueError as e:
        if 'higher API call' in str(e):
            raise ce.RateLimited
        elif 'Invalid API call' in str(e):
            raise ce.UnknownAVType
        else:
            raise
    idx = pd.date_range(min(data.index), max(data.index))
    data = data.reindex(idx[::-1])
    data['4. close'].fillna(method='backfill', inplace=True)
    data['5. adjusted close'].fillna(method='backfill', inplace=True)
    data['6. volume'].fillna(0.0, inplace=True)
    data['7. dividend amount'].fillna(0.0, inplace=True)
    data.apply(lambda x: x.fillna(data['4. close'], inplace=True)
               if x.name in ['1. open',
                             '2. high',
                             '3. low']
               else x.fillna(1.0, inplace=True))
    data.index.name = 'date'
    data = meta_label_columns(data, symbol)
    if cache:
        save_data(name_generator(
            symbol, IngestTypes.TimeSeriesDailyAdjusted), data)
    await ts.close()
    return data
async def get_cc_daily(symbol: str, config: Config, market: str = 'USD',
                       sanitize: bool = True, cache: bool = True) -> pd.DataFrame:
    """Returns CryptoCurrency data for the given symbol using the Alpha Vantage api in an
    async method."""
    cc = CryptoCurrencies(key=config.get('key', 'ALPHA_VANTAGE'),
                          output_format='pandas')
    try:
        data, _ = await cc.get_digital_currency_daily(symbol, market)
    except ValueError as e:
        if 'higher API call' in str(e):
            raise ce.RateLimited
        elif 'Invalid API call' in str(e):
            raise ce.UnknownAVType
        else:
            raise
    if sanitize:
        data = data[~(data.index >= datetime.now().date().strftime('%Y%m%d'))]
        cols = [x for x in data.columns if 'b. ' in x]
        data = data.drop(cols, axis=1)
    data = meta_label_columns(data, symbol)
    if cache:
        save_data(name_generator(
            symbol, IngestTypes.CryptoCurrenciesDaily), data)
    await cc.close()
    return data
Example #34
0
 def __init__(self, batch_labels):
     self.downsampling_ratio = Config.downsampling_ratio  #获取网络输出的大小与网络输入的下降率
     self.features_shape = np.array(
         Config.get_image_size(),
         dtype=np.int32) // self.downsampling_ratio  #变成网络输出大小
     self.batch_labels = batch_labels  #batch 标签信息
     self.batch_size = batch_labels.shape[0]  #batch的大小
Example #35
0
    def setPriority(self, pid = None, priority = 2):
        """ Set The Priority of a Windows Process.  Priority is a value between 0-5 where
            2 is normal priority.  Default sets the priority of the current
            python process but can take any valid process ID. """

        import win32api, win32process, win32con

        priorityClasses = [win32process.IDLE_PRIORITY_CLASS,
                           win32process.BELOW_NORMAL_PRIORITY_CLASS,
                           win32process.NORMAL_PRIORITY_CLASS,
                           win32process.ABOVE_NORMAL_PRIORITY_CLASS,
                           win32process.HIGH_PRIORITY_CLASS,
                           win32process.REALTIME_PRIORITY_CLASS]

        threadPriorities = [win32process.THREAD_PRIORITY_IDLE,
                            #win32process.THREAD_PRIORITY_ABOVE_IDLE,
                            #win32process.THREAD_PRIORITY_LOWEST,
                            win32process.THREAD_PRIORITY_BELOW_NORMAL,
                            win32process.THREAD_PRIORITY_NORMAL,
                            win32process.THREAD_PRIORITY_ABOVE_NORMAL,
                            win32process.THREAD_PRIORITY_HIGHEST,
                            win32process.THREAD_PRIORITY_TIME_CRITICAL]

        pid = win32api.GetCurrentProcessId()
        tid = win32api.GetCurrentThread()
        handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
        win32process.SetPriorityClass(handle, priorityClasses[priority])
        win32process.SetThreadPriority(tid, threadPriorities[priority])
        if Config.get('performance', 'restrict_to_first_processor'):
            win32process.SetProcessAffinityMask(handle, 1)
Example #36
0
def _get_hot_slice_by_threads(rlbb, nav_slice):
    ops_and_scores = rlbb.with_scores[nav_slice] if rlbb else []

    ops = [Comment(id=id) for (id, score) in ops_and_scores]

    max_from_thread = 3

    # Got the OPs, now I need to bulk fetch the top replies.
    pipeline = redis.pipeline()
    for comment in ops:
        pipeline.get(comment.redis_score.key)

    for comment in ops:
        pipeline.zrevrange(comment.popular_replies.key, 0, max_from_thread - 1, withscores=True)

    results = pipeline.execute()

    op_scores, pop_reply_lists = results[:len(ops)], results[len(ops):]

    ids = []

    if ops_and_scores:
        # Lowest score sets the threshold, but replies get a "boost" factor
        cutoff = ops_and_scores[-1][1] / Config.get('reply_boost', 1)
        for op, op_score, pop_replies in zip(ops, op_scores, pop_reply_lists):
            items = [(int(id), float(score or 0)) for (id,score) in [(op.id, op_score)] + pop_replies]
            items.sort(key=lambda (id, score): -score)
            ids += [id for (id, score) in items if score >= cutoff][:max_from_thread]

    return ids
Example #37
0
def test_passenger_generation():
    """Tests passenger generation"""
    config_name = get_full_class_name(Config)
    with patch(config_name + '.graph_dict',
               new_callable=PropertyMock) as mock_graph_dict:
        with patch(config_name + '.lines_dict',
                   new_callable=PropertyMock) as mock_lines_dict:
            with patch(config_name + '.traffic_data_dict',
                       new_callable=PropertyMock) as mock_traffic_dict:
                mock_graph_dict.return_value = {
                    'A': [('B', 1)],
                    'B': [('A', 1)]
                }
                mock_lines_dict.return_value = {
                    0: {
                        'id': 0,
                        'bus_capacity': 1,
                        'frequency1': 10000000,
                        'frequency2': 1000000000,
                        'route1': ['B', 'A'],
                        'route2': ['A', 'B']
                    }
                }
                config = Config(["A", "B"], {}, {}, {}, 1.0)
                mock_traffic_dict.return_value = {
                    'A': {
                        'A': 0,
                        'B': 120
                    },
                    'B': {
                        'A': 0,
                        'B': 0
                    }
                }

                generated = []
                model = []
                simulation = Simulation(config)
                print(config.lines_dict)
                simulation.refresh()
                simulation.refresh()

                for i in range(100000):
                    simulation.refresh()
                    if simulation.stops['A'].passengers:
                        generated.append(
                            simulation.stops['A'].passengers[0].count)

                for i in range(len(generated) - 1, 0, -1):
                    generated[i] -= generated[i - 1]
                    model.append(np.random.poisson(2))
                model.append(np.random.poisson(2))
                generated = np.sort(np.array(generated))
                model = np.sort(np.array(model))
                res = sum(np.abs(generated - model) != 0)

                assert res / len(
                    generated) <= 0.02, " jak nie dziolo to odpalic od nowa i nie narzekac, " \
                                        "bo tak naprawde dziala tylko czasem nie"
Example #38
0
def main(image):
    # Configuration for hyper-parameters
    config = Config()

    # Image Preprocessing
    transform = config.test_transform

    # Load vocabulary
    with open(os.path.join(config.vocab_path, 'vocab.pkl'), 'rb') as f:
        vocab = pickle.load(f)

    # Build Models
    encoder = EncoderCNN(config.embed_size)
    encoder.eval()  # evaluation mode (BN uses moving mean/variance)
    decoder = DecoderRNN(config.embed_size, config.hidden_size, len(vocab),
                         config.num_layers)

    # Load the trained model parameters
    encoder.load_state_dict(
        torch.load(
            os.path.join(config.teacher_cnn_path, config.trained_encoder)))
    decoder.load_state_dict(
        torch.load(
            os.path.join(config.teacher_lstm_path, config.trained_decoder)))
    # Prepare Image
    image = Image.open(image)
    image_tensor = Variable(transform(image).unsqueeze(0))

    # Set initial states
    state = (Variable(torch.zeros(config.num_layers, 1, config.hidden_size)),
             Variable(torch.zeros(config.num_layers, 1, config.hidden_size)))

    # If use gpu
    if torch.cuda.is_available():
        encoder.cuda()
        decoder.cuda()
        state = [s.cuda() for s in state]
        image_tensor = image_tensor.cuda()

    # Generate caption from image
    feature = encoder(image_tensor)
    sampled_ids = decoder.sample(feature, state)
    sampled_ids = sampled_ids.cpu().data.numpy()

    # Decode word_ids to words
    sampled_caption = []
    for word_id in sampled_ids:
        word = vocab.idx2word[word_id]
        sampled_caption.append(word)
        if word_id == 96:
            sampled_caption.append('<end>')
            break
        if word == '<end>':
            break
    sentence = ' '.join(sampled_caption)

    # Print out image and generated caption.
    print(sentence)
    return sentence
Example #39
0
    def build_default(deployment_home, cwd, CommandClasses):
        """
        Create a runtime from the command line arguments and configuration on
        disk.

        If you want something more custom, e.g. in testing, you can build
        it yourself ;)
        """

        if len(CommandClasses):
            arg_parser = CommandClasses[0].build_arg_parser()
        else:
            arg_parser = Runtime.__create_placeholder_arg_parser()
        Runtime.add_default_arguments(arg_parser)

        runtime = Runtime()

        for CommandClass in CommandClasses:
            CommandClass.register_services(runtime)

        for ServiceClass in runtime.each_service_class():
            add_default_arguments_method = getattr(ServiceClass, 'add_default_arguments', None)
            if add_default_arguments_method and callable(add_default_arguments_method):
                ServiceClass.add_default_arguments(arg_parser)

        options = arg_parser.parse_args()
        if not hasattr(options, 'deployment_home'):
            options.deployment_home = deployment_home

        config = Config()
        config.set_options(options)
        config.set_cwd(cwd)
        if hasattr(CommandClass, 'DOTFILE_NAME'):
            config.set_dotfile_name(CommandClass.DOTFILE_NAME)

        try:
            config.read()
        except Exception as e:
            if not hasattr(CommandClass, 'is_config_required') or CommandClass.is_config_required():
                exc_info = sys.exc_info()
                raise e, None, exc_info[2]

        log = Log()
        log.set_options(options)

        runtime.set_options(options)
        runtime.set_config(config)
        runtime.set_log(log)
        runtime.set_cwd(cwd)

        return runtime
Example #40
0
    def setUp(self):
        config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)
        self.e = GameEngine(config)
        self.e.loadImgDrawing(self, "svg", "mfhlogo.png")

        while not self.svg:
            self.e.run()

        glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Example #41
0
def activateMod(engine, modName):
    modPath = _getModPath(engine)
    m = os.path.join(modPath, modName)
    t = os.path.join(m, "theme.ini")
    if os.path.isdir(m):
        engine.resource.addDataPath(m)
        if os.path.isfile(t):
            theme = Config.load(t)
            Theme.open(theme)
Example #42
0
    def testLoading(self):
        config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)
        e = GameEngine(config)
        infoFile   = e.resource.fileName("tutorials", "bangbang", "song.ini")
        guitarFile = e.resource.fileName("tutorials", "bangbang", "guitar.ogg")
        songFile   = e.resource.fileName("tutorials", "bangbang", "song.ogg")
        noteFile   = e.resource.fileName("tutorials", "bangbang", "notes.mid")
        song = Song(e, infoFile, guitarFile, songFile, None, noteFile)

        assert int(song.bpm) == 120
Example #43
0
    def __init__(self, dataPath = os.path.join("..", "data")):
        self.resultQueue = Queue()
        self.dataPaths = [dataPath]
        self.loaderSemaphore = BoundedSemaphore(value = 1)
        self.loaders = []

        #myfingershurt: the following should be global, and only done at startup.  Not every damn time a file is loaded.
        self.songPath = []
        self.baseLibrary = Config.get("setlist", "base_library")
        #evilynux - Support for songs in ~/.fretsonfire/songs (GNU/Linux and MacOS X)
        if self.baseLibrary == "None" and os.name == "posix":
            path = os.path.expanduser("~/." + Version.PROGRAM_UNIXSTYLE_NAME)
            if os.path.isdir(path):
                self.baseLibrary = path
                Config.set("setlist", "base_library", path)

        if self.baseLibrary and os.path.isdir(self.baseLibrary):
            self.songPath = [self.baseLibrary]

        self.logLoadings = Config.get("game", "log_loadings")
Example #44
0
 def test7(self):
     c = Config()
     
     c.from_dict({
         'static_files': {
             'root':'/path/to/root/',
             'filter':'*.jpg'
             },
            
         
         'users':{
             'id_property':'email',
             'data_dir':'/data/system/userdata/'
             },
         
         })
     
     self.assertEqual(c.static_files.root, '/path/to/root/')
     self.assertEqual(c.static_files.filter, '*.jpg')
     self.assertEqual(c.users['id_property'], 'email')
     self.assertEqual(c.users['data_dir'], '/data/system/userdata/')
Example #45
0
 def test4(self):
     c = Config()
     
     c.from_dict({
         'static_files': {
             'root':'/path/to/root/',
             'filter':'*.jpg'
             },
            
         
         'users':{
             'id_property':'email',
             'data_dir':'/data/system/userdata/'
             },
         
         })
         
     s = c.sub('users')
     
     self.assertEqual(s.get('id_property'), 'email')
     self.assertEqual(s.get('data_dir'), '/data/system/userdata/')
Example #46
0
 def run(self):
     self.semaphore.acquire()
     game_priority = Config.get("performance", "game_priority")
     # Reduce priority on posix
     if os.name == "posix":
         # evilynux - Beware, os.nice _decreases_ priority, hence the reverse logic
         os.nice(5 - game_priority)
     elif os.name == "nt":
         self.setPriority(priority = game_priority)
     self.load()
     self.semaphore.release()
     self.resultQueue.put(self)
Example #47
0
    def __init__(self, name, number):

        self.logClassInits = Config.get("game", "log_class_inits")
        if self.logClassInits == 1:
            Log.debug("Player class init (Player.py)...")

        self.name     = name

        self.reset()
        self.keyList     = None

        self.progressKeys = []
        self.drums        = []
        self.keys         = []
        self.soloKeys     = []
        self.soloShift    = None
        self.soloSlide    = False
        self.actions      = []
        self.yes          = []
        self.no           = []
        self.conf         = []
        self.up           = []
        self.down         = []
        self.left         = []
        self.right        = []
        self.controller   = -1
        self.controlType  = -1

        self.guitarNum    = None
        self.number       = number

        self.bassGrooveEnabled = False
        self.currentTheme = 1

        self.lefty       = _playerDB.execute('SELECT `lefty` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self.twoChordMax = _playerDB.execute('SELECT `twochord` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self.drumflip    = _playerDB.execute('SELECT `drumflip` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self.assistMode  = _playerDB.execute('SELECT `assist` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self.autoKick    = _playerDB.execute('SELECT `autokick` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self.neck        = _playerDB.execute('SELECT `neck` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self.neckType    = _playerDB.execute('SELECT `necktype` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self.whichPart   = _playerDB.execute('SELECT `part` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self._upname      = _playerDB.execute('SELECT `upname` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        self._difficulty  = _playerDB.execute('SELECT `difficulty` FROM `players` WHERE `name` = ?', [self.name]).fetchone()[0]
        #MFH - need to store selected practice mode and start position here
        self.practiceMode = False
        self.practiceSpeed = 1.0
        self.practiceSection = None
        self.startPos = 0.0

        self.hopoFreq = None
Example #48
0
def savePlayers():
    for pref in _playerDB.execute('SELECT * FROM `players` WHERE `changed` = 1').fetchall():
        try:
            c = Config.load(VFS.resolveWrite(_makePlayerIniName(str(pref[0]))), type = 2)
            c.set("player","leftymode",int(pref[1]))
            c.set("player","drumflip",int(pref[2]))
            c.set("player","auto_kick",int(pref[3]))
            c.set("player","assist_mode",int(pref[4]))
            c.set("player","two_chord_max",int(pref[5]))
            c.set("player","necktype",int(pref[6]))
            c.set("player","neck",str(pref[7]))
            c.set("player","part",int(pref[8]))
            c.set("player","difficulty",int(pref[9]))
            c.set("player","name",str(pref[10]))
            c.set("player","controller",int(pref[11]))
            del c
            _playerDB.execute('UPDATE `players` SET `changed` = 0 WHERE `name` = ?', [pref[0]])
        except:
            c = VFS.open(_makePlayerIniName(str(pref[0])), "w")
            c.close()
            c = Config.load(VFS.resolveWrite(_makePlayerIniName(str(pref[0]))), type = 2)
            c.set("player","leftymode",int(pref[1]))
            c.set("player","drumflip",int(pref[2]))
            c.set("player","auto_kick",int(pref[3]))
            c.set("player","assist_mode",int(pref[4]))
            c.set("player","two_chord_max",int(pref[5]))
            c.set("player","necktype",int(pref[6]))
            c.set("player","neck",str(pref[7]))
            c.set("player","part",int(pref[8]))
            c.set("player","difficulty",int(pref[9]))
            c.set("player","name",str(pref[10]))
            c.set("player","controller",int(pref[11]))
            del c
            _playerDB.execute('UPDATE `players` SET `changed` = 0 WHERE `name` = ?', [pref[0]])
    _playerDB.execute('UPDATE `players` SET `loaded` = 0')
    _playerDB.commit()
Example #49
0
    def checkIfEnabled(self):
        if Config.get("video","shader_use"):
            if self.enabled:
                self.turnon = True
            else:
                self.set(os.path.join(Version.dataPath(), "shaders"))
        else:
            self.turnon = False

        if self.turnon:
            for i in self.shaders.keys():
                try:
                    value = Config.get("video","shader_"+i)
                    if value != "None":
                        if value == "theme":
                            if isTrue(Config.get("theme","shader_"+i).lower()):
                                value = i
                            else:
                                continue
                        self.assigned[i] = value
                except KeyError:
                    continue
            return True
        return False
Example #50
0
def setNewKeyMapping(engine, config, section, option, key):
    oldKey = config.get(section, option)
    config.set(section, option, key)
    keyCheckerMode = Config.get("game", "key_checker_mode")
    if key == "None" or key is None:
        return True
    b = isKeyMappingOK(config, option)
    if b != 0:
        if keyCheckerMode > 0:
            from views import Dialogs
            Dialogs.showMessage(engine, _("This key conflicts with the following keys: %s") % str(b))
        if keyCheckerMode == 2:   #enforce no conflicts!
            config.set(section, option, oldKey)
        return False
    return True
    def __init__(self, parent=None):
        """Initializes the Dialog"""
        self.logger = logging.getLogger('pymetadatamanager.configuration_dialog')
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_ConfigDialog()
        self.ui.setupUi(self)

        self.config = Config()
        self.ui.lineEdit_tv_dirs.setText(",".join(self.config.tv_dirs))
        self.ui.lineEdit_movie_dirs.setText(",".join(self.config.movie_dirs))
        self.ui.checkBox_prefer_local.setChecked(self.config.prefer_local)
        self.ui.lineEdit_mediainfo_path.setText(self.config.mediainfo_path)
        self.ui.pushButton_tv_browse.clicked.connect(self.tv_browser)
        self.ui.pushButton_movie_browse.clicked.connect(self.movie_browser)
        self.ui.pushButton_mediainfo_browse.clicked.connect(self.mediainfo_browser)
        self.ui.buttonBox.accepted.connect(self.save_values)
Example #52
0
def deleteControl(control):
    VFS.unlink(_makeControllerIniName(control))
    defaultUsed = -1
    for i in range(4):
        get = Config.get("game", "control%d" % i)
        if get == control:
            if i == 0:
                Config.set("game", "control%d" % i, "defaultg")
                defaultUsed = 0
            else:
                Config.set("game", "control%d" % i, None)
        if get == "defaultg" and defaultUsed > -1:
            Config.set("game", "control%d" % i, None)
    loadControls()
Example #53
0
 def updateHandicapValue(self):
     self.handicapValue = 100.0
     slowdown = Config.get("audio","speed_factor")
     earlyHitHandicap      = 1.0 #self.earlyHitWindowSizeHandicap #akedrou - replace when implementing handicap.
     for j in range(len(HANDICAPS)):
         if (self.handicap>>j)&1 == 1:
             if j == 1: #scalable
                 if slowdown != 1:
                     if slowdown < 1:
                         cut = (100.0**slowdown)/100.0
                     else:
                         cut = (100.0*slowdown)/100.0
                     self.handicapValue *= cut
                 if earlyHitHandicap != 1.0:
                     self.handicapValue *= earlyHitHandicap
             else:
                 self.handicapValue *= HANDICAPS[j]
Example #54
0
    def testSaving(self):
        config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)
        e = GameEngine(config)

        # Make a temp copy
        tmp   = "songtest_tmp"
        files = ["song.ini", "guitar.ogg", "song.ogg", "notes.mid"]
        try:
            os.mkdir(tmp)
            for f in files:
                shutil.copy(e.resource.fileName("tutorials", "bangbang", f), tmp)

            infoFile   = os.path.join(tmp, "song.ini")
            guitarFile = os.path.join(tmp, "guitar.ogg")
            songFile   = os.path.join(tmp, "song.ogg")
            noteFile   = os.path.join(tmp, "notes.mid")
            song       = Song(e, infoFile, guitarFile, songFile, None, noteFile)

            events1 = song.track[0].getAllEvents()

            song.save()
            song       = Song(e, infoFile, guitarFile, songFile, None, noteFile)

            events2 = song.track[0].getAllEvents()

            notes1 = [(time, event) for time, event in events1 if isinstance(event, Note)]
            notes2 = [(time, event) for time, event in events2 if isinstance(event, Note)]

            for i, event in enumerate(zip(notes1, notes2)):
                t1, n1 = event[0]
                t2, n2 = event[1]

                if "-v" in sys.argv:
                    print "%8d. %.3f + %.3f\t%2d\t     %.3f + %.3f\t%2d" % (i, t1, n1.length, n1.number, t2, n2.length, n2.number)

                # Allow 2ms of rounding error
                assert abs(t1 - t2) < 2
                assert abs(n1.length - n2.length) < 2
                assert n1.number == n2.number
        finally:
            # Load another song to free the copy
            pygame.mixer.music.load(e.resource.fileName("tutorials", "bangbang", "guitar.ogg"))
            shutil.rmtree(tmp)
Example #55
0
    def __init__(self, target, name, function, resultQueue, loaderSemaphore, onLoad = None, onCancel = None):
        Thread.__init__(self)
        self.semaphore   = loaderSemaphore
        self.target      = target
        self.name        = name
        self.function    = function
        self.resultQueue = resultQueue
        self.result      = None
        self.onLoad      = onLoad
        self.onCancel    = onCancel
        self.exception   = None
        self.time        = 0.0
        self.canceled    = False

        #myfingershurt: the following should be global and done ONCE:
        self.logLoadings = Config.get("game", "log_loadings")

        if target and name:
            setattr(target, name, None)
Example #56
0
def loadPlayers():
    global playername, playerpref, playerstat
    playername = []
    playerpref = []
    playerstat = []
    allplayers = VFS.listdir(playerpath)
    for name in allplayers:
        if name == "default.ini":
            continue
        if name.lower().endswith(".ini") and len(name) > 4:
            playername.append(name[0:len(name)-4])
            pref = _playerDB.execute('SELECT * FROM `players` WHERE `name` = ?', [playername[-1]]).fetchone()
            try:
                if len(pref) == 14:
                    playerpref.append((pref[1], pref[2], pref[3], pref[4], pref[5], pref[6], pref[7], pref[8], pref[9], pref[10]))
            except TypeError:
                try:
                    c = Config.load(VFS.resolveRead(_makePlayerIniName(name[:-4])), type = 2)
                    lefty  = c.get("player","leftymode")
                    drumf  = c.get("player","drumflip")
                    autok  = c.get("player","auto_kick")
                    assist = c.get("player","assist_mode")
                    twoch  = c.get("player","two_chord_max")
                    neck   = c.get("player","neck")
                    neckt  = c.get("player","necktype")
                    part   = c.get("player","part")
                    diff   = c.get("player","difficulty")
                    upname = c.get("player","name")
                    control= c.get("player","controller")
                    del c
                    _playerDB.execute('INSERT INTO `players` VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 1)', [playername[-1], lefty, drumf, autok, assist, twoch, neckt, neck, part, diff, upname, control])
                    playerpref.append((lefty, drumf, autok, assist, twoch, neckt, neck, part, diff, upname))
                except IOError:
                    _playerDB.execute('INSERT INTO `players` VALUES (?, 0, 0, 0, 0, 0, 0, ``, 0, 2, ``, 0, 0, 1)', [playername[-1]])
                    playerpref.append((0, 0, 0, 0, 0, 0, '', 0, 2, '', 0))
            _playerDB.execute('UPDATE `players` SET `loaded` = 1 WHERE `name` = ?', [playername[-1]])
            _playerDB.commit()
    return 1
Example #57
0
    def testNetworking(self):
        config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)
        e1 = GameEngine(config)

        e1.startServer()
        session1 = e1.connect("localhost")
        session2 = e1.connect("localhost")

        while not session1.isConnected() or not session2.isConnected():
            e1.run()

        session1.world.createPlayer("mario")
        session2.world.createPlayer("luigi")

        for i in range(10):
            e1.run()

        assert len(e1.server.world.players) == 2
        assert len(session1.world.players) == 2
        assert len(session2.world.players) == 2

        session3 = e1.connect("localhost")

        for i in range(10):
            e1.run()

        assert len(session3.world.players) == 2

        session1.disconnect()

        for i in range(10):
            e1.run()

        assert len(e1.server.world.players) == 1
        assert len(session2.world.players) == 1

        e1.quit()
Example #58
0
 def refreshBaseLib(self):
     self.baseLibrary = Config.get("setlist", "base_library")
     if self.baseLibrary and os.path.isdir(self.baseLibrary):
         self.songPath = [self.baseLibrary]