home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2568 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.7 KB  |  79 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import string
  6. import win32ras
  7.  
  8. class ConnectionError(Exception):
  9.     pass
  10.  
  11.  
  12. def Connect(rasEntryName, numRetries = 5):
  13.     for info in win32ras.EnumConnections():
  14.         if string.lower(info[1]) == string.lower(rasEntryName):
  15.             print 'Already connected to', rasEntryName
  16.             return (0, info[0])
  17.     
  18.     (dial_params, have_pw) = win32ras.GetEntryDialParams(None, rasEntryName)
  19.     print 'Connecting to', rasEntryName, '...'
  20.     retryCount = numRetries
  21.     while retryCount > 0:
  22.         (rasHandle, errCode) = win32ras.Dial(None, None, dial_params, None)
  23.         if win32ras.IsHandleValid(rasHandle):
  24.             bValid = 1
  25.             break
  26.         
  27.         print 'Retrying...'
  28.         win32api.Sleep(5000)
  29.         retryCount = retryCount - 1
  30.     if errCode:
  31.         raise ConnectionError(errCode, win32ras.GetErrorString(errCode))
  32.     errCode
  33.     return (1, rasHandle)
  34.  
  35.  
  36. def Disconnect(handle):
  37.     if type(handle) == type(''):
  38.         for info in win32ras.EnumConnections():
  39.             if string.lower(info[1]) == string.lower(handle):
  40.                 handle = info[0]
  41.                 break
  42.                 continue
  43.         else:
  44.             raise ConnectionError(0, "Not connected to entry '%s'" % handle)
  45.     win32ras.HangUp(handle)
  46.  
  47. usage = 'rasutil.py - Utilities for using RAS\n\nUsage:\n  rasutil [-r retryCount] [-c rasname] [-d rasname]\n  \n  -r retryCount - Number of times to retry the RAS connection\n  -c rasname - Connect to the phonebook entry specified by rasname\n  -d rasname - Disconnect from the phonebook entry specified by rasname\n'
  48.  
  49. def Usage(why):
  50.     print why
  51.     print usage
  52.     sys.exit(1)
  53.  
  54. if __name__ == '__main__':
  55.     import getopt
  56.     
  57.     try:
  58.         (opts, args) = getopt.getopt(sys.argv[1:], 'r:c:d:')
  59.     except getopt.error:
  60.         why = None
  61.         Usage(why)
  62.  
  63.     retries = 5
  64.     if len(args) != 0:
  65.         Usage('Invalid argument')
  66.     
  67.     for opt, val in opts:
  68.         if opt == '-c':
  69.             Connect(val, retries)
  70.         
  71.         if opt == '-d':
  72.             Disconnect(val)
  73.         
  74.         if opt == '-r':
  75.             retries = int(val)
  76.             continue
  77.     
  78.  
  79.