Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class for windows version checking #210

Merged
merged 9 commits into from Mar 10, 2017

Conversation

topic2k
Copy link
Contributor

@topic2k topic2k commented Mar 5, 2017

replaces #208
based on the idea from @kdschlosser, extended to a class with compare functions.

Check for a specific Windows version:
eg.WindowsVersion.IsVista() or eg.WindowsVersion == "Vista"

Check for a minimum Windows version:
eg.WindowsVersion >= "Vista"

Notice for plugin developers: eg.Utils.IsXP() and eg.Utils.IsVista() are now deprecated.


Functions:

IsXP()
IsVista()
Is7()
Is8()
Is80()
Is81()
Is10()

Comparison:

eg.WindowsVersion [<|<=|==|!=|>=|>] "[XP|Vista|7|8|80|81|10]"

XP:    Windows XP
       Windows Server 2003
       Windows 2003 R2
       Windows Tablet PC
       Windows Media Center Edition 2002
       Windows Media Center Edition 2004
       Windows Media Center Edition 2005
Vista: Windows Vista
       Windows Server 2008
7:     Windows 7
       Windows Server 2008 R2
8:     (80 and 81)
80:    Windows 8
       Windows Server 2012
       Windows RT
81:    Windows 8.1
       Windows 2012 R2
       Windows RT 8.1
10:    Windows 10
       Windows Server 2016

Adds a simple way to grab the windows version. 

eg.WindowsVersion.IsXp()
eg.WindowsVersion.IsVista()
eg.WindowsVersion.Is7()
eg.WindowsVersion.is8()
eg.WindowsVersion.Is10()

This is going to be used by the Systemn.PowerBroadcastNotifier and also System.DeviceChangeNotifier (if the PR for the latter gets accepted)
Copy link
Member

@kdschlosser kdschlosser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of formatting changes. And constructing the WindowsVersion object. But it runs perfect as far as i can tell. sweet upgrade 👍 👏


def __eq__(self, other):
self.check_os_value(other)
return getattr(self, 'Is'+other)()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

return getattr(self, 'Is' + other)()

def __gt__(self, other):
self.check_os_value(other)
if other == 'XP':
return self.THIS >self. WIN_XP32 and self.THIS >self. WIN_XP64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

return self.THIS > self.WIN_XP32 and self.THIS > self.WIN_XP64

if other == 'XP':
return self.THIS >self. WIN_XP32 and self.THIS >self. WIN_XP64
if other == '8':
return self.THIS >self. WIN_80 and self.THIS >self. WIN_81
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

 return self.THIS > self.WIN_80 and self.THIS > self.WIN_81

def __lt__(self, other):
self.check_os_value(other)
if other == 'XP':
return self.THIS <self. WIN_XP32 and self.THIS <self. WIN_XP64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

return self.THIS < self.WIN_XP32 and self.THIS < self.WIN_XP64

if other == 'XP':
return self.THIS <self. WIN_XP32 and self.THIS <self. WIN_XP64
if other == '8':
return self.THIS <self. WIN_80 and self.THIS <self. WIN_81
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

return self.THIS < self.WIN_80 and self.THIS < self.WIN_81

:return: Bool
"""
return (
self.THIS == self. WIN_80 or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

self.THIS == self.WIN_80 or

"""
return (
self.THIS == self. WIN_80 or
self.THIS == self. WIN_81
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

self.THIS == self.WIN_81


:return: Bool
"""
return self.THIS == self. WIN_80
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

return self.THIS == self.WIN_80


:return: Bool
"""
return self.THIS == self. WIN_81
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

return self.THIS == self.WIN_81


:return: Bool
"""
return self.THIS == self. WIN_10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting:

return self.THIS == self.WIN_10

Construct WindowsVersion

WindowsVersion = WindowsVersion()

@kdschlosser
Copy link
Member

kdschlosser commented Mar 5, 2017

I made some changes and and did a commit to my PR of this. it only has one issue with a docstring. and not sure as to how to clean that up to make it green. but take a look see if it's something you like then keep it. if not no worries.. the one i did also doesn't care if you do

eg.WindowsVersion >= 'xp'

instead of

eg.WindowsVersion >= 'XP'

@topic2k topic2k force-pushed the enhancement-windows-version branch 2 times, most recently from b7a572d to da362de Compare March 8, 2017 19:16
@topic2k topic2k added the notice label Mar 8, 2017
@kdschlosser
Copy link
Member

the only thing i see which i do not understand is this

setattr(eg, "WindowsVersion", eg.WindowsVersion)

But i am thinking it has something to do with the build process and the docs.

you could do from Classes.WindowsVersion import WindowsVersion and this can be placed in the eg_init_.py file at the top. only if you aren't using

import eg

at the module level

but i am thinking that maybe some adjustment to the doc creation in the build process is really what is needed,

| | Windows Media Center Edition 2004, |
| | Windows Media Center Edition 2005 |
+-----------+------------------------------------+
| ``XP64`` | Windows Server 2003, |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add a line in here

|           | Windows XP Professional                  |

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not sure how you want to handle the Windows 2003 R2

you can Either change it to read Windows Server 2003 R2
or remove it since all R2 is, is a repackaged Server 2003 with SP1 slip streamed..
so technically it is Server 2003 SP1

@kdschlosser
Copy link
Member

does doing the import in the init take care of satisfying the building of the docs?? It's a step in the right direction for getting rid of the dynamic module. and it will also make IDE's happy

@topic2k
Copy link
Contributor Author

topic2k commented Mar 10, 2017

Yes, it works. At the first steps i wasn't able to get class docs into the help file. I used ActionBase as an example. That's why i had that setattr() there. So if, you have nothing more to comment, i will merge it in a few minutes. 😃

@kdschlosser
Copy link
Member

i'm good to go.. it looks great! I know it was something simple turned into an animal LOL but it helped us to get a system together for what i think should be a model for new additions to EG.

@kdschlosser
Copy link
Member

and i personally do not understand the eg.ActionClass eg.ActionBase thing.. I believe that was done for backwards compatibility with an earlier version of EG and eg.ActionClass was supposed to be depreciated.. but it didn't happen same goes for eg.PluginClass

@topic2k topic2k force-pushed the enhancement-windows-version branch from b4f061a to e6668da Compare March 10, 2017 15:35
@topic2k topic2k merged commit d9a817e into EventGhost:master Mar 10, 2017
@topic2k topic2k deleted the enhancement-windows-version branch March 10, 2017 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants