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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import wincerapi
  5. import win32event
  6. import win32api
  7. import win32con
  8. import os
  9. import sys
  10. import getopt
  11. from repr import repr
  12.  
  13. def DumpPythonRegistry():
  14.     
  15.     try:
  16.         h = wincerapi.CeRegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, 'Software\\Python\\PythonCore\\%s\\PythonPath' % sys.winver)
  17.     except win32api.error:
  18.         print 'The remote device does not appear to have Python installed'
  19.         return 0
  20.  
  21.     (path, typ) = wincerapi.CeRegQueryValueEx(h, None)
  22.     print "The remote PythonPath is '%s'" % (str(path),)
  23.     h.Close()
  24.     return 1
  25.  
  26.  
  27. def DumpRegistry(root, level = 0):
  28.     h = wincerapi.CeRegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, None)
  29.     level_prefix = ' ' * level
  30.     index = 0
  31.     while None:
  32.         
  33.         try:
  34.             (name, data, typ) = wincerapi.CeRegEnumValue(root, index)
  35.         except win32api.error:
  36.             break
  37.  
  38.         print '%s%s=%s' % (level_prefix, name, repr(str(data)))
  39.         index = index + 1
  40.         continue
  41.         index = 0
  42.         while None:
  43.             
  44.             try:
  45.                 (name, klass) = wincerapi.CeRegEnumKeyEx(root, index)
  46.             except win32api.error:
  47.                 break
  48.  
  49.             print '%s%s\\' % (level_prefix, name)
  50.             subkey = wincerapi.CeRegOpenKeyEx(root, name)
  51.             index = index + 1
  52.             continue
  53.             return None
  54.  
  55.  
  56. def DemoCopyFile():
  57.     cefile = wincerapi.CeCreateFile('TestPython', win32con.GENERIC_WRITE, 0, None, win32con.OPEN_ALWAYS, 0, None)
  58.     wincerapi.CeWriteFile(cefile, 'Hello from Python')
  59.     cefile.Close()
  60.     cefile = wincerapi.CeCreateFile('TestPython', win32con.GENERIC_READ, 0, None, win32con.OPEN_EXISTING, 0, None)
  61.     if wincerapi.CeReadFile(cefile, 100) != 'Hello from Python':
  62.         print 'Couldnt read the data from the device!'
  63.     
  64.     cefile.Close()
  65.     wincerapi.CeDeleteFile('TestPython')
  66.     print 'Created, wrote to, read from and deleted a test file!'
  67.  
  68.  
  69. def DemoCreateProcess():
  70.     
  71.     try:
  72.         (hp, ht, pid, tid) = wincerapi.CeCreateProcess('Windows\\Python.exe', '', None, None, 0, 0, None, '', None)
  73.         hp.Close()
  74.         ht.Close()
  75.         print 'Python is running on the remote device!'
  76.     except win32api.error:
  77.         (hr, fn, msg) = None
  78.         print 'Couldnt execute remote process -', msg
  79.  
  80.  
  81.  
  82. def DumpRemoteMachineStatus():
  83.     (ACLineStatus, BatteryFlag, BatteryLifePercent, BatteryLifeTime, BatteryFullLifeTime, BackupBatteryFlag, BackupBatteryLifePercent, BackupBatteryLifeTime, BackupBatteryLifeTime) = wincerapi.CeGetSystemPowerStatusEx()
  84.     if ACLineStatus:
  85.         power = 'AC'
  86.     else:
  87.         power = 'battery'
  88.     if BatteryLifePercent == 255:
  89.         batPerc = 'unknown'
  90.     else:
  91.         batPerc = BatteryLifePercent
  92.     print 'The batteries are at %s%%, and is currently being powered by %s' % (batPerc, power)
  93.     (memLoad, totalPhys, availPhys, totalPage, availPage, totalVirt, availVirt) = wincerapi.CeGlobalMemoryStatus()
  94.     print 'The memory is %d%% utilized.' % memLoad
  95.     print '%-20s%-10s%-10s' % ('', 'Total', 'Avail')
  96.     print '%-20s%-10s%-10s' % ('Physical Memory', totalPhys, availPhys)
  97.     print '%-20s%-10s%-10s' % ('Virtual Memory', totalVirt, availVirt)
  98.     print '%-20s%-10s%-10s' % ('Paging file', totalPage, availPage)
  99.     (storeSize, freeSize) = wincerapi.CeGetStoreInformation()
  100.     print '%-20s%-10s%-10s' % ('File store', storeSize, freeSize)
  101.     print 'The CE temp path is', wincerapi.CeGetTempPath()
  102.     print 'The system info for the device is', wincerapi.CeGetSystemInfo()
  103.  
  104.  
  105. def DumpRemoteFolders():
  106.     for name, val in wincerapi.__dict__.items():
  107.         if name[:6] == 'CSIDL_':
  108.             
  109.             try:
  110.                 loc = str(wincerapi.CeGetSpecialFolderPath(val))
  111.                 print 'Folder %s is at %s' % (name, loc)
  112.             except win32api.error:
  113.                 details = None
  114.             except:
  115.                 None<EXCEPTION MATCH>win32api.error
  116.             
  117.  
  118.         None<EXCEPTION MATCH>win32api.error
  119.     
  120.     print 'Dumping start menu shortcuts...'
  121.     
  122.     try:
  123.         startMenu = str(wincerapi.CeGetSpecialFolderPath(wincerapi.CSIDL_STARTMENU))
  124.     except win32api.error:
  125.         details = None
  126.         print 'This device has no start menu!', details
  127.         startMenu = None
  128.  
  129.     if startMenu:
  130.         for fileAttr in wincerapi.CeFindFiles(os.path.join(startMenu, '*')):
  131.             fileName = fileAttr[8]
  132.             fullPath = os.path.join(startMenu, str(fileName))
  133.             
  134.             try:
  135.                 resolved = wincerapi.CeSHGetShortcutTarget(fullPath)
  136.             except win32api.error:
  137.                 (rc, fn, msg) = None
  138.                 resolved = '#Error - %s' % msg
  139.  
  140.             print '%s->%s' % (fileName, resolved)
  141.         
  142.     
  143.  
  144.  
  145. def usage():
  146.     print 'Options:'
  147.     print '-a - Execute all demos'
  148.     print '-p - Execute Python process on remote device'
  149.     print '-r - Dump the remote registry'
  150.     print '-f - Dump all remote special folder locations'
  151.     print '-s - Dont dump machine status'
  152.     print '-y - Perform asynch init of CE connection'
  153.  
  154.  
  155. def main():
  156.     async_init = bStartPython = bDumpRegistry = bDumpFolders = 0
  157.     bDumpStatus = 1
  158.     
  159.     try:
  160.         (opts, args) = getopt.getopt(sys.argv[1:], 'apr')
  161.     except getopt.error:
  162.         why = None
  163.         print 'Invalid usage:', why
  164.         usage()
  165.         return None
  166.  
  167.     for o, v in opts:
  168.         if o == '-a':
  169.             bStartPython = bDumpRegistry = bDumpStatus = bDumpFolders = asynch_init = 1
  170.         
  171.         if o == '-p':
  172.             bStartPython = 1
  173.         
  174.         if o == '-r':
  175.             bDumpRegistry = 1
  176.         
  177.         if o == '-s':
  178.             bDumpStatus = 0
  179.         
  180.         if o == '-f':
  181.             bDumpFolders = 1
  182.         
  183.         if o == '-y':
  184.             print 'Doing asynch init of CE connection'
  185.             async_init = 1
  186.             continue
  187.     
  188.     if async_init:
  189.         (event, rc) = wincerapi.CeRapiInitEx()
  190.         while None:
  191.             rc = win32event.WaitForSingleObject(event, 500)
  192.             if rc == win32event.WAIT_OBJECT_0:
  193.                 break
  194.                 continue
  195.             print 'Waiting for Initialize to complete (picture a Cancel button here :)'
  196.             continue
  197.     async_init
  198.     wincerapi.CeRapiInit()
  199.     print 'Connected to remote CE device.'
  200.     
  201.     try:
  202.         verinfo = wincerapi.CeGetVersionEx()
  203.         print 'The device is running windows CE version %d.%d - %s' % (verinfo[0], verinfo[1], verinfo[4])
  204.         if bDumpStatus:
  205.             print 'Dumping remote machine status'
  206.             DumpRemoteMachineStatus()
  207.         
  208.         if bDumpRegistry:
  209.             print 'Dumping remote registry...'
  210.             DumpRegistry(win32con.HKEY_LOCAL_MACHINE)
  211.         
  212.         if bDumpFolders:
  213.             print 'Dumping remote folder information'
  214.             DumpRemoteFolders()
  215.         
  216.         DemoCopyFile()
  217.         if bStartPython:
  218.             print 'Starting remote Python process'
  219.             if DumpPythonRegistry():
  220.                 DemoCreateProcess()
  221.             else:
  222.                 print "Not trying to start Python, as it's not installed"
  223.     finally:
  224.         wincerapi.CeRapiUninit()
  225.         print 'Disconnected'
  226.  
  227.  
  228. if __name__ == '__main__':
  229.     main()
  230.  
  231.