revisiting the "What am I running on?" question

songbird songbird at anthive.com
Sun Feb 17 21:46:02 EST 2019


  having worked on some other things for a while i 
didn't put much emphasis on working on this until i
had the other bugs taken care of.

  so now back into it we can go...  :)

  what i came up with (sorry, i hate yet another not
invented here thing, but this is just where i ended up
after some pondering).

  simply put.  if i'm running on a computer and i 
don't easily know why kind of computer how can i
answer this in a quick way without getting overly
complicated that also will cover most of the easy
cases?

  i came up with this:

  comments?  additions?  clarifications?

  i don't have a windows system to test this on,
does it work?

  thanks  :)


=====
import re
import tempfile


def sysprobe ():

    sysprobetmp = tempfile.gettempdir()

    print ("Temp directory : -->" + sysprobetmp + "<--\n")

    result = re.search("^/(tmp)|(var)|(usr)|(opt)|(home)", sysprobetmp)
    try:
        print ("Result : -->" + result.group(0) + "<--\n")

        return ("posix")
    except:
        pass
    
    result = re.search("^[A-Za-z]:", sysprobetmp)
    try:
        print ("Result : -->" + result.group(0) + "<--\n")
        return ("windows")
    except:
        pass

    return ("unknown")


def main ():

  print (sysprobe())


if __name__ == "__main__":
    main()


=====


  on my system i get:

=====

(env) me at ant(39)~/src/salsa/bits/sysprobe$ python3 sysprobe.py 
Temp directory : -->/tmp<--

Result : -->/tmp<--

posix

=====


  songbird



More information about the Python-list mailing list