Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions source/buildVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2006-2017 NV Access Limited
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest some module level doc string to indicate that "this module is for non-localised version information. It should not contain UI strings or translatable strings. The versionInfo module is the correct place for that"

import os

"""
This module contains non-localizable version information for NVDA such as the version string and major and minor numbers etc.
Any localizable version information should be placed in the versionInfo module, not this one.
This module exists separately so that it can be imported for version checks before localization is initialized.
"""

def _updateVersionFromVCS():
"""Update the version from version control system metadata if possible.
"""
global version
# The root of the Git working tree will be the parent of this module's directory.
gitDir = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".git")
try:
head = file(os.path.join(gitDir, "HEAD"), "r").read().rstrip()
if not head.startswith("ref: "):
# Detached head.
version = "source-DETACHED-%s" % head[:7]
return
# Strip the "ref: " prefix to get the ref.
ref = head[5:]
commit = file(os.path.join(gitDir, ref), "r").read().rstrip()
version = "source-%s-%s" % (
os.path.basename(ref),
commit[:7])
except:
pass

# ticket:3763#comment:19: name must be str, not unicode.
# Otherwise, py2exe will break.
name="NVDA"
version_year=2017
version_major=4
version_minor=0
version_build=0
version="%s.%s.%sdev"%(version_year,version_major,version_minor)
publisher="unknown"
updateVersionType=None
try:
from _buildVersion import version, publisher, updateVersionType, version_build
except ImportError:
_updateVersionFromVCS()

# A test version is anything other than a final or rc release.
isTestVersion = not version[0].isdigit() or "alpha" in version or "beta" in version or "dev" in version
9 changes: 3 additions & 6 deletions source/logHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import traceback
from types import MethodType, FunctionType
import globalVars
import versionInfo
import buildVersion

ERROR_INVALID_WINDOW_HANDLE = 1400
ERROR_TIMEOUT = 1460
Expand Down Expand Up @@ -190,7 +190,7 @@ class RemoteHandler(logging.Handler):

def __init__(self):
#Load nvdaHelperRemote.dll but with an altered search path so it can pick up other dlls in lib
path=os.path.abspath(os.path.join(u"lib",versionInfo.version,u"nvdaHelperRemote.dll"))
path=os.path.abspath(os.path.join(u"lib",buildVersion.version,u"nvdaHelperRemote.dll"))
h=ctypes.windll.kernel32.LoadLibraryExW(path,0,LOAD_WITH_ALTERED_SEARCH_PATH)
if not h:
raise OSError("Could not load %s"%path)
Expand Down Expand Up @@ -218,11 +218,8 @@ def close(self):
logging.StreamHandler.close(self)

def handle(self,record):
# versionInfo must be imported after the language is set. Otherwise, strings won't be in the correct language.
# Therefore, don't import versionInfo if it hasn't already been imported.
versionInfo = sys.modules.get("versionInfo")
# Only play the error sound if this is a test version.
shouldPlayErrorSound = versionInfo and versionInfo.isTestVersion
shouldPlayErrorSound = buildVersion.isTestVersion
if record.levelno>=logging.CRITICAL:
try:
winsound.PlaySound("SystemHand",winsound.SND_ALIAS)
Expand Down
44 changes: 7 additions & 37 deletions source/versionInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,16 @@
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a module level doc string to say "This module is for UI specific / translatable version information. The source of this information should come from the non-translated buildVersion module so that it can be used in parts of nvda that are executed pre-translation system initialisation."

"""
This module contains localizable version information such as description, copyright and About messages etc.
As there are localizable strings at module level, this can only be imported once localization is set up via languageHandler.initialize.
To access version information for programmatic version checks before languageHandler.initialize, use the buildVersion module which contains all the non-localizable version information such as major and minor version, and version string etc.
"""

import os
from buildVersion import *

def _updateVersionFromVCS():
"""Update the version from version control system metadata if possible.
"""
global version
# The root of the Git working tree will be the parent of this module's directory.
gitDir = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".git")
try:
head = file(os.path.join(gitDir, "HEAD"), "r").read().rstrip()
if not head.startswith("ref: "):
# Detached head.
version = "source-DETACHED-%s" % head[:7]
return
# Strip the "ref: " prefix to get the ref.
ref = head[5:]
commit = file(os.path.join(gitDir, ref), "r").read().rstrip()
version = "source-%s-%s" % (
os.path.basename(ref),
commit[:7])
except:
pass

# ticket:3763#comment:19: name must be str, not unicode.
# Otherwise, py2exe will break.
name="NVDA"
longName=_("NonVisual Desktop Access")
version_year=2017
version_major=4
version_minor=0
version_build=0
version="%s.%s.%sdev"%(version_year,version_major,version_minor)
publisher="unknown"
updateVersionType=None
try:
from _buildVersion import version, publisher, updateVersionType, version_build
except ImportError:
_updateVersionFromVCS()
description=_("A free and open source screen reader for Microsoft Windows")
url="http://www.nvaccess.org/"
copyrightYears="2006-2017"
Expand All @@ -59,5 +31,3 @@ def _updateVersionFromVCS():
{name} is developed by NV Access, a non-profit organisation committed to helping and promoting free and open source solutions for blind and vision impaired people.
If you find NVDA useful and want it to continue to improve, please consider donating to NV Access. You can do this by selecting Donate from the NVDA menu.""").format(**globals())

# A test version is anything other than a final or rc release.
isTestVersion = not version[0].isdigit() or "alpha" in version or "beta" in version or "dev" in version