def init_icon_maps(): global ICON_MAPS ICON_MAPS = { "/" : open_icon_map(os.path.join(platform.get_platform().source_dir(), "images", "aprs_pri.png")), "\\": open_icon_map(os.path.join(platform.get_platform().source_dir(), "images", "aprs_sec.png")), }
def __init__(self, i2c): self.i2c = i2c platform.get_platform() if platform.platform_pyb: self.i2c_send = self.pyb_i2c_send self.i2c_recv = self.pyb_i2c_recv else: if platform.platform_esp: self.i2c_send = self.esp_i2c_send self.i2c_recv = self.esp_i2c_recv else: raise platform.PlatformError('unknow platform')
def do_browse(self, _, dir): if self.filename.get_text(): start = os.path.dirname(self.filename.get_text()) else: start = None if dir: fn = platform.get_platform().gui_select_dir(start) else: fn = platform.get_platform().gui_save_file(start) if fn: self.filename.set_text(fn)
def init_icon_maps(): global ICON_MAPS ICON_MAPS = { "/": open_icon_map( os.path.join(platform.get_platform().source_dir(), "images", "aprs_pri.png")), "\\": open_icon_map( os.path.join(platform.get_platform().source_dir(), "images", "aprs_sec.png")), }
def __main__(): output_parts = [] output_parts.append(PACKAGE_NAME[0].upper()) output_parts.append(PACKAGE_NAME[1:]) output_parts.append(' version: ') output_parts.append(VERSION) output_parts.append('\n') output_parts.append('Platform: ') output_parts.append(get_platform()) output_parts.append('\n') implementation = sys.implementation output_parts.append('Python implementation: ') output_parts.append(implementation.name) output_parts.append('\n') version = implementation.version output_parts.append('Python version: ') output_parts.append(str(version[0])) output_parts.append('.') output_parts.append(str(version[1])) if version[3] == 'final': output_parts.append(' final') output_parts.append('\n') output = ''.join(output_parts) sys.stdout.write(output)
def do_qst(self): size_limit = self.config.getint("settings", "qst_size_limit") pform = platform.get_platform() s, o = pform.run_sync(self.text) if s: print "Command failed with status %i" % s return o[:size_limit]
def do_update(self): p = platform.get_platform() try: fn, headers = p.retrieve_url(self.__url) content = file(fn).read() except Exception, e: print "[NBDC] Failed to fetch info for %i: %s" % (self.__buoy, e) self.set_name("NBDC %s" % self.__buoy) return
def __init__(self): # create root logger self.logger = logging.getLogger() self.logger.setLevel(logging.DEBUG) self.LOG = logging.getLogger(__name__) # Set CHIRP_DEBUG in environment for early console debugging. # It can be a number or a name; otherwise, level is set to 'debug' # in order to maintain backward compatibility. CHIRP_DEBUG = os.getenv("CHIRP_DEBUG") self.early_level = logging.WARNING if CHIRP_DEBUG: try: self.early_level = int(CHIRP_DEBUG) except ValueError: try: self.early_level = log_level_names[CHIRP_DEBUG] except KeyError: self.early_level = logging.DEBUG # If we're on Win32 or MacOS, we don't use the console; instead, # we create 'debug.log', redirect all output there, and set the # console logging handler level to DEBUG. To test this on Linux, # set CHIRP_DEBUG_LOG in the environment. console_stream = None console_format = '%(levelname)s: %(message)s' if 'CHIRP_TESTENV' not in os.environ and ( hasattr(sys, "frozen") or not os.isatty(0) or os.getenv("CHIRP_DEBUG_LOG")): p = platform.get_platform() log = file(p.config_file("debug.log"), "w", 0) sys.stdout = log sys.stderr = log console_stream = log console_format = self.log_format self.early_level = logging.DEBUG self.console = logging.StreamHandler(console_stream) self.console_level = self.early_level self.console.setLevel(self.early_level) self.console.setFormatter(logging.Formatter(console_format)) self.logger.addHandler(self.console) # Set CHIRP_LOG in environment to the name of log file. logname = os.getenv("CHIRP_LOG") self.logfile = None if logname is not None: self.create_log_file(logname) level = os.getenv("CHIRP_LOG_LEVEL") if level is not None: self.set_log_verbosity(level) else: self.set_log_level(logging.DEBUG) if self.early_level <= logging.DEBUG: self.LOG.debug(version_string())
def display_in_browser(self): f = tempfile.NamedTemporaryFile(suffix=".html") name = f.name f.close() f = file(name, "w") f.write(self.make_html()) f.flush() f.close() p = platform.get_platform() p.open_html_file(f.name)
def __parse_site(self): url = "http://waterdata.usgs.gov/nwis/inventory?search_site_no=%s&format=sitefile_output&sitefile_output_format=xml&column_name=agency_cd&column_name=site_no&column_name=station_nm&column_name=dec_lat_va&column_name=dec_long_va&column_name=alt_va" % self.__site p = platform.get_platform() try: fn, headers = p.retrieve_url(url) content = file(fn).read() except Exception, e: print "[NSGS] Failed to fetch info for %s: %s" % (self.__site, e) self.set_name("NSGS NWIS Site %s" % self.__site) return
def create_form_from_mail(self, mail): id = self.config.get("user", "callsign") + \ time.strftime("%m%d%Y%H%M%S") + \ mail.get("Message-id", str(random.randint(0, 1000))) mid = platform.get_platform().filter_filename(id) ffn = os.path.join(self.config.form_store_dir(), _("Inbox"), "%s.xml" % mid) try: form = create_form_from_mail(self.config, mail, ffn) except Exception, e: print "Failed to create form from mail: %s" % e return
def load_subs(): global sublist if sublist: return True f = platform.get_platform().config_file("subst.conf") if not f: return False sublist = SubstitutionList(f) return True
def __parse_level(self): url = "http://waterdata.usgs.gov/nwis/uv?format=rdb&period=1&site_no=%s" % self.__site p = platform.get_platform() try: fn, headers = p.retrieve_url(url) line = file(fn).readlines()[-1] except Exception, e: print "[NSGS] Failed to fetch info for site %s: %s" % (self.__site, e) self.set_comment("No data") self.set_timestamp(time.time()) return
def __init__(self, mainapp, safe=False): self.mainapp = mainapp self.safe = safe self.platform = platform.get_platform() try: self.default_port = self.platform.list_serial_ports()[0] except: self.default_port = "" self.tips = gtk.Tooltips() self._file = self.platform.config_file("d-rats.config") self.config = ConfigParser.ConfigParser() if not self.safe: self.load_config(self._file) self.fields = {} self.init_config() self.build_gui()
def version_string(): args = (CHIRP_VERSION, platform.get_platform().os_version_string(), sys.version.split()[0]) return "CHIRP %s on %s (Python %s)" % args
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import sys from optparse import OptionParser if __name__ == "__main__": o = OptionParser() o.add_option("-s", "--safe", dest="safe", action="store_true", help="Safe mode (ignore configuration)") o.add_option("-c", "--config", dest="config", help="Use alternate configuration directory") (opts, args) = o.parse_args() import platform if opts.config: platform.get_platform(opts.config) import mainapp app = mainapp.MainApp(safe=opts.safe) sys.exit(app.main())