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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32wnet
  5. import sys
  6. from winnetwk import *
  7. import os
  8. possible_shares = []
  9.  
  10. def _doDumpHandle(handle, level = 0):
  11.     indent = ' ' * level
  12.     while None:
  13.         items = win32wnet.WNetEnumResource(handle, 0)
  14.         if len(items) == 0:
  15.             break
  16.         
  17.         for item in items:
  18.             
  19.             try:
  20.                 if item.dwDisplayType == RESOURCEDISPLAYTYPE_SHARE:
  21.                     print indent + 'Have share with name:', item.lpRemoteName
  22.                     possible_shares.append(item)
  23.                 elif item.dwDisplayType == RESOURCEDISPLAYTYPE_GENERIC:
  24.                     print indent + 'Have generic resource with name:', item.lpRemoteName
  25.                 else:
  26.                     print indent + 'Enumerating ' + item.lpRemoteName,
  27.                     k = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, item)
  28.                     print 
  29.                     _doDumpHandle(k, level + 1)
  30.                     win32wnet.WNetCloseEnum(k)
  31.             continue
  32.             except win32wnet.error:
  33.                 details = None
  34.                 print indent + "Couldn't enumerate this resource: " + details[2]
  35.                 continue
  36.             
  37.  
  38.         
  39.         continue
  40.         return None
  41.  
  42.  
  43. def TestOpenEnum():
  44.     print 'Enumerating all resources on the network - this may take some time...'
  45.     handle = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, None)
  46.     
  47.     try:
  48.         _doDumpHandle(handle)
  49.     finally:
  50.         handle.Close()
  51.  
  52.     print 'Finished dumping all resources.'
  53.  
  54.  
  55. def TestConnection():
  56.     if len(possible_shares) == 0:
  57.         print "Couldn't find any potential shares to connect to"
  58.         return None
  59.     localName = 'Z:'
  60.     for share in possible_shares:
  61.         print 'Attempting connection of', localName, 'to', share.lpRemoteName
  62.         
  63.         try:
  64.             win32wnet.WNetAddConnection2(share.dwType, localName, share.lpRemoteName)
  65.         except win32wnet.error:
  66.             details = None
  67.             print "Couldn't connect: " + details[2]
  68.             continue
  69.  
  70.         
  71.         try:
  72.             fname = os.path.join(localName + '\\', os.listdir(localName + '\\')[0])
  73.             
  74.             try:
  75.                 print "Universal name of '%s' is '%s'" % (fname, win32wnet.WNetGetUniversalName(fname))
  76.             except win32wnet.error:
  77.                 details = None
  78.                 print "Couldn't get universal name of '%s': %s" % (fname, details[2])
  79.  
  80.             print 'User name for this connection is', win32wnet.WNetGetUser(localName)
  81.         finally:
  82.             win32wnet.WNetCancelConnection2(localName, 0, 0)
  83.             break
  84.  
  85.     
  86.  
  87.  
  88. def TestGetUser():
  89.     u = win32wnet.WNetGetUser()
  90.     print 'Current global user is', `u`
  91.     if u != win32wnet.WNetGetUser(None):
  92.         raise RuntimeError, 'Default value didnt seem to work!'
  93.     u != win32wnet.WNetGetUser(None)
  94.  
  95. TestGetUser()
  96. TestOpenEnum()
  97. TestConnection()
  98.