Post Reply 
Python: ZSYS module (mimics SYS)
05-21-2023, 08:27 PM (This post was last modified: 10-09-2024 08:16 AM by StephenG1CMZ.)
Post: #2
RE: Python: ZSYS module (mimics SYS)
Version 0.1 of ZSYS identifies calculator makers.
(Specific calculators cannot generally be identified).




Code:


"""ZSYS mimics part of sys where needed.

It allows portable code to identify calculator platforms despite most calculators not having sys.
"""

crme="""
© 2023 StephenG1CMZ
"""
crid="ZSYS v0.1"+crme
impname="micropython" #unless sys exist
impversioninfo=None #version unknown
platform="" #sys.platform
#Note that detecting files from these
#does not guarantee which is running
isCasio=False
isHP=False
isNumworks=False
isPrime=False
isTI=False
isCalculator=False
calculators=""
isSys=False

try:
  import sys
  platform = sys.platform
  #sys.implementation
  #impname = sys.implementation.name
  #impmachine = sys.implementation.machine
  impversioninfo=sys.implementation.version_info
  isSys=True
  try:
    if sys.platform == "HP Prime":
      isPrime = True
    else:
      isPrime=False
  except:
    isPrime=False

except:  #only examine files if no sys
  #reason: exclude false positives from imposters
  try: #Casio
    import casioplot
    isCasio=True
    platform="Casio"
  except:
    isCasio=False 

  try: #Numworks
    import ion
    isNumworks=True
    platform="Numworks"
  except:
    isNumworks=False
  if isNumworks:
    try:
      import os
      fork="Omega" #alternative
    except:
      fork="Epsilon" #Main

  try: #TI
    import ti_system
    isTI=True
    platform="TI"
    hhdt=get_platform()
  except:
    IsTI=False

if isPrime:
  #identifiable calculator
  isHP=True

if isCasio or isHP or isNumworks or isTI:
  isCalculator=True
  calculators=" calculator"

def exit(exc=0): #mimic sys.exit
  raise SystemExit(exc)

def main():
  #micropython, cpython etc.
  print(impname,impversioninfo)
 #from sys, or Calculator maker
  print(platform,calculators)

  if showmore:
    if isNumworks:
      if fork=="Omega":
        print(fork,os.name)

    if isTI:
      #handheld/desktop
      print(get_platform()) #hh/dt=handheld/desktop

showme=True #customise
showmore=True #customise

if showme or __name__ == "__main__":
  print(crid)
  main()

Note: Since Python has yet to reach HP Prime Android, it is currently tested only on Numworks.
Update 2024: It fails to run on HP Prime!

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Python: ZSYS module (mimics SYS) - StephenG1CMZ - 05-21-2023 08:27 PM



User(s) browsing this thread: 2 Guest(s)