-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.1.6 error reports less ambiguous errors
- Loading branch information
WraithWireless
authored and
WraithWireless
committed
Aug 17, 2016
1 parent
2a0015c
commit e811e72
Showing
7 changed files
with
99 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,11 @@ | |
contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
Defines the Pyric error class and constants for some errors. All pyric errors | ||
will follow the 2-tuple form of EnvironmentError | ||
Defines the PyRIC error class and constants for some errors. All pyric errors | ||
will follow the 2-tuple form of EnvironmentError. Also defines constansts for | ||
PyPI packaging. | ||
WARNING: DO NOT import * | ||
Requires: | ||
linux (3.x or 4.x kernel) | ||
|
@@ -32,9 +35,6 @@ | |
includes: /nlhelp /lib /net /utils pyw.py | ||
changes: | ||
See CHANGES in top-level directory | ||
WARNING: DO NOT import * | ||
""" | ||
|
||
__name__ = 'pyric' | ||
|
@@ -46,27 +46,33 @@ | |
__email__ = '[email protected]' | ||
__status__ = 'Production' | ||
|
||
# define pyric exceptions | ||
# all exceptions are tuples t=(error code,error message) | ||
# we use error codes defined in errno, adding -1 to define the undefined error | ||
# EUNDEF. I don't like importing all from errno but it provides conformity in | ||
# error handling i.e modules using pyric.error do not need to call pyric.EUNDEF | ||
# and errno.EINVAL but can call pyric.EUNDEF and pyric.EINVAL | ||
""" | ||
define pyric exceptions | ||
all exceptions are tuples t=(error code,error message) | ||
we use error codes defined in errno, using EUNDEF = -1 to define an undefined | ||
error I don't like importing all from errno but it provides conformity in | ||
error handling i.e modules using pyric.error do not need to call pyric.EUNDEF | ||
and errno.EINVAL but can call pyric.EUNDEF and pyric.EINVAL | ||
""" | ||
EUNDEF = -1 # undefined error | ||
from errno import * # make all errno errors pyric errors | ||
errorcode[EUNDEF] = "EUNDEF" # add ours to errorcode dicts | ||
class error(EnvironmentError): pass | ||
|
||
# BELOW IS STILL A WORK IN PRGORESS | ||
#def strerror(errno): | ||
# import os | ||
# if errno < 0: return "Undefined error" | ||
# elif errno == EPERM: return "Superuser privileges required" | ||
# elif errno == EINVAL: return "Invalid parameter" | ||
# else: | ||
# return os.strerror(errno) | ||
# device busy if setting channel when card is down | ||
# no open files if attempt to create a virtual card with same name as orginal | ||
class error(EnvironmentError): | ||
def __init__(self,errno,errmsg=None): | ||
if not errmsg: errmsg = strerror(errno) | ||
EnvironmentError.__init__(self,errno,errmsg) | ||
|
||
def strerror(errno): | ||
import os | ||
if errno < 0: return "Undefined error" | ||
elif errno == EPERM: return "Superuser privileges required" | ||
elif errno == EINVAL: return "Invalid parameter" | ||
elif errno == EBUSY: | ||
msg = "{0}. Make sure Card is up and no other devices share the same phy" | ||
return msg.format(os.strerror(EBUSY)) | ||
elif errno == ENFILE: return "There are no available netlink sockets" | ||
else: | ||
return os.strerror(errno) | ||
|
||
# for setup.py use | ||
# redefine version for easier access | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.