How do you detect operating systems from within IronPython?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How do you detect operating systems from within IronPython?

Vernon D. Cole
I received a reminder today on a module I modified:
v v v
dsblank wrote Today at 8:01 AM
Remember that IronPython runs on many different operating systems. It isn't clear from the patch if this works on Mac and Linux under Mono.
^ ^ ^
Which brings up a really good point....

How do I tell what operating system IronPython is running on?

The original module (webbrowser.py) has lots of operating systems specific code, all separated by:
if os.platform[:3] == 'win'
which I have modified to:
if os.platform[:3] in ['win','cli']

but that assumes that mono emulates Windows to a high degree, which thing I doubt.

The best guess I can make as to more correct code would be:

if os.platform[:3] == 'win' or (os.platform[:3] == 'cli' and os.linesep == '\r\n')

Yeeach!

How should I really be doing it?
--
Vernon Cole


_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: How do you detect operating systems from within IronPython?

Jeff Hardy-4
On Mon, Feb 21, 2011 at 11:05 AM, Vernon Cole <[hidden email]> wrote:
> How should I really be doing it?

os.name usually has the actual underlying OS, but depending on what
you need to do it may be better to have a block that is just for 'cli'
that calls into a .NET API, and let .NET/Mono smooth over the platform
differences.

- Jeff
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: How do you detect operating systems from within IronPython?

Vernon D. Cole
This is probably almost a confession on this group, but I don't USE the .NET API very often.
My reason for mucking with IronPython is left handed.  I have this great module which works on CPython 2.n and CPyton 3.n and I want it to work on IronPython, too.  I feel that the .NET API is almost as ungodly as the Java API, and not quite as well documented. That's why I am working on cross-platform tools, so the application programmer does not need to learn the gnarly details of the API's. So I learn just barely enough .NET to make my module work. The app programmer calls webbrowser.open('http://digvil.info') and the magic happens. Then I go searching for another tool that application programmers need. I don't really have a life.

So I wrote (okay, modified) a tool which calls into the .NET API and let .NET/Mono smooth out the difference.
Next morning, I get a note from a Mono user that I may have screwed up.  So now I get to spend several more days thrashing around in an IDE that I don't know and will probably never use again so that I can build a current copy of Mono/IronPython to test against.  [puff -- puff -- whew!  Thanks, I feel better now.]

Thanks for the hint about os.name.  I was hoping for something a little more definitive than 'nt', but it will suffice for the time being. What I was originally looking for was an answer to the question "does this operating system use/require UAC elevation."   Is there a .NET call which will answer that question? Mono people -- can you tell me whether I need to use 'sudo' in Ubuntu?
--
Vernon

On Mon, Feb 21, 2011 at 11:19 AM, Jeff Hardy <[hidden email]> wrote:
On Mon, Feb 21, 2011 at 11:05 AM, Vernon Cole <[hidden email]> wrote:
> How should I really be doing it?

os.name usually has the actual underlying OS, but depending on what
you need to do it may be better to have a block that is just for 'cli'
that calls into a .NET API, and let .NET/Mono smooth over the platform
differences.

- Jeff


_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com