Skip to content

Commit

Permalink
tolerate broken uid/gui configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
etingof committed May 17, 2018
1 parent d701cd6 commit c132a40
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

Revision 0.3.1, XX-0X-2018
--------------------------

- Fixed compiler crash when building comments at a platform which
has broken users/groups databases

Revision 0.3.0, 29-04-2018
--------------------------

Expand Down
2 changes: 1 addition & 1 deletion pysmi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# http://www.python.org/dev/peps/pep-0396/
__version__ = '0.3.0'
__version__ = '0.3.1'

import sys

Expand Down
32 changes: 25 additions & 7 deletions pysmi/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ def addBorrowers(self, *borrowers):

return self

def _get_system_info(self):

try:
platform_info = os.uname()

except AttributeError:
platform_info = ('?',) * 6

try:
user_info = getpwuid(os.getuid())

except Exception:
user_info = ('?',) * 7

return platform_info, user_info

def compile(self, *mibnames, **options):
"""Transform requested and possibly referred MIBs.
Expand Down Expand Up @@ -322,13 +338,13 @@ class instances (values)

debug.logger & debug.flagCompiler and debug.logger('compiling %s read from %s' % (mibname, fileInfo.path))

platform_info, user_info = self._get_system_info()

comments = [
'ASN.1 source %s' % fileInfo.path,
'Produced by %s-%s at %s' % (packageName, packageVersion, time.asctime()),
'On host %s platform %s version %s by user %s' % (
hasattr(os, 'uname') and os.uname()[1] or '?', hasattr(os, 'uname') and os.uname()[0] or '?',
hasattr(os, 'uname') and os.uname()[2] or '?',
hasattr(os, 'getuid') and getpwuid(os.getuid())[0] or '?'),
'On host %s platform %s version %s by user %s' % (platform_info[1], platform_info[0],
platform_info[2], user_info[0]),
'Using Python version %s' % sys.version.split('\n')[0]
]

Expand Down Expand Up @@ -513,13 +529,15 @@ class instances (values)
return processed

def buildIndex(self, processedMibs, **options):
platform_info, user_info = self._get_system_info()

comments = [
'Produced by %s-%s at %s' % (packageName, packageVersion, time.asctime()),
'On host %s platform %s version %s by user %s' % (
hasattr(os, 'uname') and os.uname()[1] or '?', hasattr(os, 'uname') and os.uname()[0] or '?',
hasattr(os, 'uname') and os.uname()[2] or '?', hasattr(os, 'getuid') and getpwuid(os.getuid())[0]) or '?',
'On host %s platform %s version %s by user %s' % (platform_info[1], platform_info[0],
platform_info[2], user_info[0]),
'Using Python version %s' % sys.version.split('\n')[0]
]

try:
self._writer.putData(
self.indexFile,
Expand Down

0 comments on commit c132a40

Please sign in to comment.