Skip to content

Commit

Permalink
Remove exit_code attribute from exceptions
Browse files Browse the repository at this point in the history
Unused.
  • Loading branch information
cdown committed Feb 2, 2016
1 parent 14fc8b6 commit f849dab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
5 changes: 4 additions & 1 deletion tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ def test_link_localtime_timezone_not_available(isfile_mock):
def test_link_localtime_permission_denied(isfile_mock, unlink_mock):
isfile_mock.return_value = True
unlink_mock.side_effect = OSError(errno.EACCES, 'Permission denied yo')
with assert_raises(tzupdate.LocaltimePermissionError):
with assert_raises(OSError) as raise_cm:
tzupdate.link_localtime(
FAKE_TIMEZONE,
tzupdate.DEFAULT_ZONEINFO_PATH, tzupdate.DEFAULT_LOCALTIME_PATH,
)

eq(raise_cm.exception.errno, errno.EACCES)


@mock.patch('tzupdate.os.unlink')
@mock.patch('tzupdate.os.path.isfile')
def test_link_localtime_oserror_not_permission(isfile_mock, unlink_mock):
Expand Down
38 changes: 30 additions & 8 deletions tzupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
DEFAULT_LOCALTIME_PATH = '/etc/localtime'


class TimezoneUpdateException(Exception): exit_code = None
class TimezoneNotLocallyAvailableError(TimezoneUpdateException): exit_code = 1
class NoTimezoneAvailableError(TimezoneUpdateException): exit_code = 2
class DirectoryTraversalError(TimezoneUpdateException): exit_code = 3
class IPAPIError(TimezoneUpdateException): exit_code = 4
class LocaltimePermissionError(TimezoneUpdateException): exit_code = 5


def get_timezone_for_ip(ip_addr=None):
Expand Down Expand Up @@ -95,10 +89,11 @@ def link_localtime(timezone, zoneinfo_path, localtime_path):
# If we don't have permission to unlink /etc/localtime, we probably
# need to be root.
if thrown_exc.errno == errno.EACCES:
raise LocaltimePermissionError(
raise OSError(
thrown_exc.errno,
'Could not link "%s" (%s). Are you root?' % (
localtime_path, thrown_exc,
)
),
)
else:
raise
Expand Down Expand Up @@ -164,5 +159,32 @@ def main(argv=None):
print('Linked %s to %s.' % (args.localtime_path, zoneinfo_tz_path))


class TimezoneUpdateException(Exception):
'''
Base class for exceptions raised by tzupdate.
'''


class TimezoneNotLocallyAvailableError(TimezoneUpdateException):
'''
Raised when the API returned a timezone, but we don't have it locally.
'''

class NoTimezoneAvailableError(TimezoneUpdateException):
'''
Raised when the API did not return a timezone.
'''

class DirectoryTraversalError(TimezoneUpdateException):
'''
Raised when the timezone path returned by the API would result in directory
traversal when concatenated with the zoneinfo path.
'''

class IPAPIError(TimezoneUpdateException):
'''
Raised when IP-API raises an internal error.
'''

if __name__ == '__main__':
main()

0 comments on commit f849dab

Please sign in to comment.