python类config()的实例源码

main.py 文件源码 项目:mobileinsight-mobile 作者: mobile-insight 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def exec_legacy(arg):
    try:
        tmp = arg.split(":")
        if len(tmp) < 2:
            raise AssertionError("Error: incorrect service path: " + arg)
        app_name = tmp[0]
        app_path = tmp[1]

        # print "Service: app_name=",app_name," app_path=",app_path
        setup_logger(app_name)

        t = threading.Thread(target=alive_worker, args=(30.0,))
        t.start()

        app_dir = os.path.join(mi2app_utils.get_files_dir(), "app")
        # add this dir to module search path
        sys.path.append(os.path.join(app_dir, app_path))
        app_file = os.path.join(app_dir, app_path, "main.mi2app")
        Logger.info("Phone model: " + mi2app_utils.get_phone_model())
        Logger.info("Running app: " + app_file)
        # print arg,app_dir,os.path.join(app_dir, arg)

        namespace = {"service_context": mi2app_utils.get_service_context()}

        # Load configurations as global variables
        config = ConfigParser()
        config.read('/sdcard/.mobileinsight.ini')

        ii = arg.rfind('/')
        section_name = arg[ii + 1:]

        plugin_config = {}
        if section_name in config.sections():
            config_options = config.options(section_name)
            for item in config_options:
                plugin_config[item] = config.get(section_name, item)

        namespace["plugin_config"] = plugin_config

        gps_provider = GpsListener(on_gps)
        gps_provider.start()

        execfile(app_file, namespace)

        # print app_name, "stops normally"

    except Exception as e:
        # Print traceback logs to analysis
        tb_exc = traceback.format_exc()
        Logger.error(tb_exc)
        l = logging.getLogger("mobileinsight_logger")
        l.error(tb_exc)
        sys.exit(tb_exc)
gui.py 文件源码 项目:high-quality-chat 作者: b6938236 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def record_button(self):
        """
        Records high quality audio files on the artist side.
        :return:
        """
        # Toggle recording
        rec_state = self.app.get_own_state()['recording']
        self.app.get_own_state()['recording'] = not rec_state

        if self.app.get_own_state()['recording']:
            # Update state
            self.app.chat_client.send_sync(constants.SYNC_START_RECORDING)
            # GUI update
            self.ids.record_button.source = SessionScreen.stop_theme
            # Start the progress effect
            progress_thread = threading.Thread(target=self.record_progress)
            progress_thread.start()

            filename = self.app.config.get_file_name(self.app.session_name,
                                                     datetime.now().strftime(constants.DATETIME_HQ))
            head, tail = os.path.split(filename)
            print "Creating: " + tail
            # Make sure folders exist
            if not os.path.exists(head):
                os.makedirs(head)
            # Makes a Recorder with the desired filename
            self.app.recorder = audio.Recorder(filename)
            # Add available audio file to state list
            self.app.add_audio_file(filename)
            # Starts writing to an audio file, including to disk
            self.app.recorder.start()  # Starts recording
            print "Recording..."
        else:
            # Update state
            self.app.chat_client.send_sync(constants.SYNC_STOP_RECORDING)
            # GUI update
            self.ids.record_button.source = SessionScreen.record_red
            # Closes recording threads
            self.app.recorder.stop()

            self.app.phone.stop_start_recording(datetime.now().strftime(constants.DATETIME_LQ))
            self.add_clip()  # adds to gui sidebar

            # Send a sync message for when a clip is available
            available_filename = self.app.get_latest_audio_file()
            _, tail = os.path.split(available_filename)
            self.app.chat_client.send_sync(constants.SYNC_FILE_AVAILABLE,
                                           filename=tail,
                                           length=audio.get_length(available_filename))
gui.py 文件源码 项目:high-quality-chat 作者: b6938236 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_text(self, servername, username, password, callnumber):
        def is_valid(value):
            if value != '' and len(value) != 0:
                return True
            else:
                return False

        if is_valid(servername) and is_valid(username) and is_valid(password) and is_valid(callnumber):
            self.app.config.update_setting('ConnectionDetails', 'server', servername)
            self.app.config.update_setting('ConnectionDetails', 'user', username)
            self.app.config.update_setting('ConnectionDetails', 'password', password)
            self.app.config.update_setting('ConnectionDetails', 'call_no', callnumber)
            connection_details = {'server': servername, 'user': username, 'password': password, 'call_no': callnumber}

        else:
            connection_details = self.app.config.get_section('ConnectionDetails')

        # TODO: All of this code needs to be moved to another screen
        # The generation of connection strings should occur in a completely different screen
        # that is accessible from the main screen.  The producer should be able to enter in the 4 values
        # and it should output a connection string
        # conn_string = username + ';' + password + ";" + servername + ";" + callnumber
        # encoded = base64.b64encode(conn_string)
        # self.app.config.update_setting('ConnectionDetails', 'conn_string', encoded)
        # self.parent.current = 'session'
        #
        # # Make BoxLayout for multiple items
        # popup_box = BoxLayout(orientation='vertical')
        # # Make "Connection String" TextInput
        # popup_text = TextInput(text=encoded, size_hint=(1, .8))
        # popup_box.add_widget(popup_text)
        # # Make "Close" button for popup
        # close_button = Button(text='Close', size_hint=(.4, .2), pos_hint={'center_x': .5})
        # popup_box.add_widget(close_button)
        # popup = Popup(title='Connection String',
        #               content=popup_box,
        #               size_hint=(None, None), size=(400, 400),
        #               auto_dismiss=False)
        # close_button.bind(on_press=popup.dismiss)
        # # Open the popup
        # popup.open()

        self.parent.current = 'producer_session'

        file_name = self.app.config.get_file_name(self.app.session_name, datetime.now().strftime(constants.DATETIME_LQ))
        self.app.phone.make_call(connection_details['call_no'], connection_details['server'], file_name)
        self.app.lq_audio = self.app.phone.recording_start
        print "passing lq_audio to gui: " + self.app.lq_audio
gui.py 文件源码 项目:high-quality-chat 作者: b6938236 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_text(self, conn_string):
        if conn_string is not None and len(conn_string) != 0:  # Use the provided connection string
            connection_details = self.app.config.parse_conn_string()

            if not connection_details['server'] \
                    and not connection_details['user'] \
                    and not connection_details['password'] \
                    and not connection_details['call_no']:
                self.app.config.update_setting('ConnectionDetails', 'server', connection_details['server'])
                self.app.config.update_setting('ConnectionDetails', 'user', connection_details['user'])
                self.app.config.update_setting('ConnectionDetails', 'password', connection_details['password'])
                self.app.config.update_setting('ConnectionDetails', 'call_no', connection_details['call_no'])

            else:
                print "Bad connection string"
                error_message = 'Sorry, that string is not valid'
                popup = Popup(title='Connection String Error',
                              content=Label(text=error_message),
                              size_hint=(None, None), size=(400, 400))
                popup.open()

        else:  # Use the saved config values
            connection_details = self.app.config.get_section('ConnectionDetails')

            def is_valid(value):
                if value != '' and value != 'None' and value is not None:
                    return True
                return False

            if not is_valid(connection_details['server']) \
                    or not is_valid(connection_details['user']) \
                    or not is_valid(connection_details['password']) \
                    or not is_valid(connection_details['call_no']):
                # If the stored values aren't valid, nogood
                print "No connection string and bad config values"
                error_message = 'Sorry, the configuration is not valid'
                popup = Popup(title='Connection String Error',
                              content=Label(text=error_message),
                              size_hint=(None, None), size=(400, 400))
                popup.open()

        if self.app.config.get('ChatSettings', 'role') == "ARTIST":
            self.parent.current = 'artist_session'
        else:
            self.parent.current = 'listener_session'

        filename = self.app.config.get_file_name(self.app.session_name, datetime.now().strftime(constants.DATETIME_LQ))
        self.app.phone.make_call(connection_details['call_no'], connection_details['server'], filename)


问题


面经


文章

微信
公众号

扫码关注公众号