Changeset 5717

Show
Ignore:
Timestamp:
08/30/12 13:58:06 (7 years ago)
Author:
mkaplan
Message:

Fix for ticket 1041

Location:
seattle/branches/repy_v2
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • seattle/branches/repy_v2/nodemanager/daemon.py

    r3183 r5717  
    3232  """ 
    3333 
    34   if os.name == "nt" or os.name == "ce": 
     34  if os.name == "nt": 
    3535    # No way to fork or daemonize on windows. Just do nothing for now? 
    3636    return 
  • seattle/branches/repy_v2/repy/harshexit.py

    r3230 r5717  
    6363      pass 
    6464 
    65   elif ostype == 'Windows' or ostype == 'WindowsCE': 
     65  elif ostype == 'Windows': 
    6666    # Use new api 
    6767    windows_api.kill_process(pid) 
     
    121121  elif ostype == 'Darwin': 
    122122    os._exit(val) 
    123   elif ostype == 'Windows' or ostype == 'WindowsCE': 
     123  elif ostype == 'Windows': 
    124124    # stderr is not automatically flushed in Windows... 
    125125    sys.stderr.flush() 
     
    135135  global osrealtype 
    136136 
    137   # Detect whether or not it is Windows CE/Mobile 
    138   if os.name == 'ce': 
    139     ostype = 'WindowsCE' 
    140     return 
    141  
    142   # figure out what sort of witch we are... 
     137  # figure out what sort of system we are... 
    143138  osrealtype = platform.system() 
    144139 
  • seattle/branches/repy_v2/repy/nmstatusinterface.py

    r3216 r5717  
    112112def _stopfile_exit(exitcode, pid): 
    113113  # On Windows, we are in the Repy process, so we can just use harshexit 
    114   if harshexit.ostype in ["Windows", "WindowsCE"]: 
     114  if harshexit.ostype in ["Windows"]: 
    115115    # Harshexit will store the appriopriate status for us 
    116116    harshexit.harshexit(exitcode) 
     
    151151     
    152152    # On Windows elevate our priority above the user code. 
    153     if harshexit.ostype in ["Windows", "WindowsCE"]: 
     153    if harshexit.ostype in ["Windows"]: 
    154154      # Elevate our priority, above normal is higher than the usercode 
    155155      windows_api.set_current_thread_priority(windows_api.THREAD_PRIORITY_ABOVE_NORMAL) 
  • seattle/branches/repy_v2/repy/nonportable.py

    r4977 r5717  
    111111    # to let you send from a socket you're receiving on (why?) 
    112112    pass 
    113  
    114   elif ostype == "WindowsCE": 
    115     # No known issues, so just go 
    116     pass 
    117113         
    118114  else: 
     
    128124    do_forked_resource_monitor() 
    129125     
    130   elif ostype == 'Windows' or ostype == 'WindowsCE': 
     126  elif ostype == 'Windows': 
    131127    # Now we set up a cpu nanny... 
    132     # Use an external CPU monitor for WinCE 
    133     if ostype == 'WindowsCE': 
    134       nannypath = "\"" + repy_constants.PATH_SEATTLE_INSTALL + 'win_cpu_nanny.py' + "\"" 
    135       cmdline = str(os.getpid())+" "+str(nanny.get_resource_limit("cpu"))+" "+str(repy_constants.CPU_POLLING_FREQ_WINCE) 
    136       windows_api.launch_python_script(nannypath, cmdline) 
    137     else: 
    138       WinCPUNannyThread().start() 
     128    WinCPUNannyThread().start() 
    139129     
    140130    # Launch mem./disk resource nanny 
     
    219209 
    220210  # Check for windows   
    221   elif ostype in ["Windows", "WindowsCE"]:    
     211  elif ostype in ["Windows"]:    
    222212    # Release the lock 
    223213    runtimelock.release() 
     
    331321 
    332322    # Windows Specific versions 
    333     elif ostype in ["Windows","WindowsCE"]: 
     323    elif ostype in ["Windows"]: 
    334324     
    335325      # Get the CPU time 
     
    912902  global granularity 
    913903 
    914   if ostype in ["Windows", "WindowsCE"]: 
     904  if ostype in ["Windows"]: 
    915905    # The Granularity of getTickCount is 1 millisecond 
    916906    granularity = pow(10,-3) 
     
    955945elif osrealtype == "FreeBSD": 
    956946  import freebsd_api as os_api 
    957 elif ostype == "Windows" or ostype == "WindowsCE": 
     947elif ostype == "Windows": 
    958948  # There is no real reason to do this, since windows is imported separately 
    959949  import windows_api as os_api 
     
    966956 
    967957# For Windows, we need to initialize time.clock() 
    968 if ostype in ["Windows", "WindowsCE"]: 
     958if ostype in ["Windows"]: 
    969959  time.clock() 
    970960 
  • seattle/branches/repy_v2/repy/tests/run_tests.py

    r3550 r5717  
    606606       
    607607  # Windows  
    608   elif nonportable.ostype == 'Windows' or nonportable.ostype == 'WindowsCE': 
     608  elif nonportable.ostype == 'Windows': 
    609609    # this is much easier because we don't worry about the path or have  
    610610    # children to worry about. 
  • seattle/branches/repy_v2/repy/windows_api.py

    r3340 r5717  
    1818import textops 
    1919 
    20 # Detect whether or not it is Windows CE/Mobile 
    21 MobileCE = False 
    22 if os.name == 'ce': 
    23   MobileCE = True 
    24 else: 
    25   import portable_popen 
     20import portable_popen 
    2621 
    2722# Main Libraries 
    28 # Loaded depending on OS 
    29 if MobileCE: 
    30   # kerneldll links to the library that has Windows Kernel Calls 
    31   kerneldll = ctypes.cdll.coredll 
    32  
    33   # Toolhelp library 
    34   # Contains Tool helper functions 
    35   toolhelp = ctypes.cdll.toolhelp 
    36  
    37 else: 
    38   # kerneldll links to the library that has Windows Kernel Calls 
    39   kerneldll = ctypes.windll.kernel32  
    40   # memdll links to the library that has Windows Process/Thread Calls 
    41   memdll = ctypes.windll.psapi 
     23# kerneldll links to the library that has Windows Kernel Calls 
     24kerneldll = ctypes.windll.kernel32  
     25# memdll links to the library that has Windows Process/Thread Calls 
     26memdll = ctypes.windll.psapi 
    4227 
    4328# Types 
     
    138123_free_disk_space = kerneldll.GetDiskFreeSpaceExW # Determines free disk space 
    139124 
    140 # Load CE Specific function 
    141 if MobileCE: 
    142   # Uses kernel, but is slightly different on desktop 
    143   _global_memory_status = kerneldll.GlobalMemoryStatus 
    144    
    145   # Things using toolhelp 
    146   _create_snapshot = toolhelp.CreateToolhelp32Snapshot # Makes snapshot of threads  
    147   _close_snapshot = toolhelp.CloseToolhelp32Snapshot # destroys a snapshot  
    148   _first_thread = toolhelp.Thread32First # Reads from Thread from snapshot 
    149   _next_thread = toolhelp.Thread32Next # Reads next Thread from snapshot 
    150    
    151   # Things using kernel 
    152   # Windows CE uses thread identifiers and handles interchangably 
    153   # Use internal ce method to handle this 
    154   # _open_thread_ce 
    155    
    156   # Non-Supported functions: 
    157   # _process_times, there is no tracking of this on a process level 
    158   # _process_memory, CE does not track memory usage 
    159   # _current_thread_id, CE has this defined inline in a header file, so we need to do it 
    160   # These must be handled specifically 
    161   # We override this later 
    162   _current_thread_id = None  
    163    
    164   # Heap functions only needed on CE for getting memory info 
    165   _heap_list_first = toolhelp.Heap32ListFirst # Initializes Heap List 
    166   _heap_list_next = toolhelp.Heap32ListNext # Iterates through the heap list 
    167   _heap_first = toolhelp.Heap32First # Initializes Heap Entry 
    168   _heap_next = toolhelp.Heap32Next # Iterates through the Heaps 
    169    
    170   # Non-officially supported methods 
    171   _get_current_permissions = kerneldll.GetCurrentPermissions 
    172   _set_process_permissions = kerneldll.SetProcPermissions 
    173125# Load the Desktop Specific functions 
    174 else: 
    175   # These are in the kernel library on the desktop 
    176   _open_thread = kerneldll.OpenThread # Returns Thread Handle 
    177   _create_snapshot = kerneldll.CreateToolhelp32Snapshot # Makes snapshot of threads  
    178   _first_thread = kerneldll.Thread32First # Reads from Thread from snapshot 
    179   _next_thread = kerneldll.Thread32Next # Reads next Thread from snapshot 
    180   _global_memory_status = kerneldll.GlobalMemoryStatusEx # Gets global memory info 
    181   _current_thread_id = kerneldll.GetCurrentThreadId # Returns the thread_id of the current thread 
    182    
    183   # These process specific functions are only available on the desktop 
    184   _process_times = kerneldll.GetProcessTimes # Returns data about Process CPU use 
    185   _process_memory = memdll.GetProcessMemoryInfo # Returns data on Process mem use 
    186    
    187   # This is only available for desktop, sets the process wide priority 
    188   _set_process_priority = kerneldll.SetPriorityClass  
     126# These are in the kernel library on the desktop 
     127_open_thread = kerneldll.OpenThread # Returns Thread Handle 
     128_create_snapshot = kerneldll.CreateToolhelp32Snapshot # Makes snapshot of threads  
     129_first_thread = kerneldll.Thread32First # Reads from Thread from snapshot 
     130_next_thread = kerneldll.Thread32Next # Reads next Thread from snapshot 
     131_global_memory_status = kerneldll.GlobalMemoryStatusEx # Gets global memory info 
     132_current_thread_id = kerneldll.GetCurrentThreadId # Returns the thread_id of the current thread 
     133 
     134# These process specific functions are only available on the desktop 
     135_process_times = kerneldll.GetProcessTimes # Returns data about Process CPU use 
     136_process_memory = memdll.GetProcessMemoryInfo # Returns data on Process mem use 
     137 
     138# This is only available for desktop, sets the process wide priority 
     139_set_process_priority = kerneldll.SetPriorityClass  
    189140   
    190141 
     
    315266                ('ullAvailExtendedVirtual', DWORDLONG)]         
    316267  
    317 # Python Class which is converted to a C struct 
    318 # It encapsulates data about global memory 
    319 # This version is for WinCE (< 4gb ram) 
    320 # see http://msdn.microsoft.com/en-us/library/bb202730.aspx 
    321 class _MEMORYSTATUS(ctypes.Structure):  
    322    _fields_ = [('dwLength', DWORD),  
    323                ('dwMemoryLoad', DWORD),  
    324                ('dwTotalPhys', DWORD),  
    325                ('dwAvailPhys', DWORD), 
    326                ('dwTotalPageFile', DWORD), 
    327                ('dwAvailPageFile', DWORD), 
    328                ('dwTotalVirtual', DWORD), 
    329                ('dwAvailVirtual', DWORD)]           
    330                                  
    331268# Exceptions 
    332269 
     
    374311  global _system_thread_count 
    375312   
    376   # Mobile requires different structuer 
    377   if MobileCE: 
    378     thread_class = _THREADENTRY32CE 
    379   else: 
    380     thread_class = _THREADENTRY32 
     313  thread_class = _THREADENTRY32 
    381314     
    382315  threads = [] # List object for threads 
     
    412345   
    413346  # Cleanup snapshot 
    414   if MobileCE: 
    415     _close_snapshot(handle) 
    416347  _close_handle(handle) 
    417348     
     
    448379   
    449380   <Side Effects> 
    450      If running on a mobile CE platform, execution permissions will be elevated. 
    451381     close_thread_handle must be called before get_thread_handle is called again, 
    452382     or permissions will not be set to their original level. 
     
    458388      Thread Handle 
    459389    """ 
    460   # Check if it is CE 
    461   if MobileCE: 
    462     # Use the CE specific function 
    463     handle = _open_thread_ce(thread_id) 
    464   else: 
    465     # Open handle to thread 
    466     handle = _open_thread(THREAD_HANDLE_RIGHTS, 0, thread_id) 
     390  # Open handle to thread 
     391  handle = _open_thread(THREAD_HANDLE_RIGHTS, 0, thread_id) 
    467392   
    468393  # Check for a successful handle 
     
    484409    """ 
    485410     
    486   # Check if it is CE 
    487   if MobileCE: 
    488     # Opening a thread raises permissions, 
    489     # so we need to revert to default 
    490     _revert_permissions(); 
    491    
    492411  # Close thread handle 
    493412  _close_handle(thread_handle) 
     
    790709    cmdline_param = None 
    791710   
    792   # Adjust for CE 
    793   if MobileCE: 
    794     # Not Supported on CE 
    795     priority = 0 
    796     window_info_addr = 0 
    797     # Always use absolute path 
    798     application = unicode(os.path.abspath(application)) 
    799   else: 
    800     # For some reason, Windows Desktop uses the first part of the second parameter as the 
    801     # Application... This is documented on MSDN under CreateProcess in the user comments 
    802     # Create struct to hold window info 
    803     window_info = _STARTUPINFO() 
    804     window_info_addr = ctypes.pointer(window_info) 
    805     cmdline_param = unicode(application) + " " + cmdline_param 
    806     application = None 
     711  # For some reason, Windows Desktop uses the first part of the second parameter as the 
     712  # Application... This is documented on MSDN under CreateProcess in the user comments 
     713  # Create struct to hold window info 
     714  window_info = _STARTUPINFO() 
     715  window_info_addr = ctypes.pointer(window_info) 
     716  cmdline_param = unicode(application) + " " + cmdline_param 
     717  application = None 
    807718   
    808719  # Lauch process, and save status 
     
    878789    True on success, False on failure. 
    879790  """ 
    880   # This is not supported, just return True 
    881   if MobileCE: 
    882     return True 
    883791     
    884792  # Get our pid 
     
    995903  """ 
    996904   
    997   # Check if it is CE 
    998   if MobileCE: 
    999     # Use the CE specific function 
    1000     return _process_times_ce(pid) 
    1001905   
    1002906  # Open process handle 
     
    11431047  """ 
    11441048   
    1145   # Check if it is CE 
    1146   if MobileCE: 
    1147     # Use the CE specific function 
    1148     return _process_memory_info_ce(pid) 
    11491049     
    11501050  # Open process Handle 
     
    12981198    Determines if there exists a network socket with the specified unique tuple. 
    12991199    Assumes TCP. 
    1300     * Not supported on Windows Mobile. 
    13011200 
    13021201  <Arguments> 
     
    13091208    A Tuple, indicating the existence and state of the socket. E.g. (Exists (True/False), State (String or None)) 
    13101209  """ 
    1311   if MobileCE: 
    1312     return False  
    13131210   
    13141211  # This only works if all are not of the None type 
     
    13591256  <Purpose> 
    13601257    Determines if there exists a network socket with the specified ip and port which is the LISTEN state. 
    1361     *Note: Not currently supported on Windows CE. It will always return False on this platform. 
    13621258  <Arguments> 
    13631259    ip: The IP address of the listening socket 
     
    13681264    True or False. 
    13691265  """ 
    1370   if MobileCE: 
    1371     return False 
    13721266 
    13731267  # This only works if both are not of the None type 
     
    14031297  <Purpose> 
    14041298    Fetch's the information from ipconfig and stores it in a useful format. 
    1405     * Not Supported on Windows Mobile. 
    14061299  <Returns> 
    14071300    A dictionary object. 
     
    14721365  <Purpose> 
    14731366    Returns a list of available network interfaces. 
    1474     * Not Supported on Windows Mobile. 
    14751367  <Returns> 
    14761368    An array of string interfaces 
    14771369  """ 
    1478   if MobileCE: 
    1479     return [] 
    14801370     
    14811371  # Get the information from ipconfig 
     
    14981388  <Purpose> 
    14991389    Returns the IP address associated with the interface. 
    1500     * Not Supported on Windows Mobile. 
    15011390  <Arguments> 
    15021391    interfaceName: The string name of the interface, e.g. eth0 
     
    15051394    A list of IP addresses associated with the interface. 
    15061395  """ 
    1507   if MobileCE: 
    1508     return [] 
    15091396     
    15101397  # Get the information from ipconfig 
     
    15221409 
    15231410 
    1524 # Windows CE Stuff 
    1525 # Internal function, not public 
    1526  
    1527 # Get information about a process CPU use times 
    1528 # Windows CE does not have a GetProcessTimes function, so we will emulate it 
    1529 def _process_times_ce(pid): 
    1530   # Get List of threads related to Process 
    1531   threads = get_process_threads(pid) 
    1532    
    1533   # Create all the structures needed to make API Call 
    1534   creation_time = _FILETIME() 
    1535   exit_time = _FILETIME() 
    1536   kernel_time = _FILETIME() 
    1537   user_time = _FILETIME() 
    1538    
    1539   # Create counters for each category 
    1540   # Only adds the "low date time" (see _FILETIME()), since thats what we return 
    1541   creation_time_sum = 0 
    1542   exit_time_sum = 0 # We don't return this, but we keep it anyways 
    1543   kernel_time_sum = 0 
    1544   user_time_sum = 0 
    1545    
    1546   # Get the process times for each thread 
    1547   for t in threads: 
    1548     # Open handle to thread 
    1549     handle = get_thread_handle(t) 
    1550    
    1551     # Pass all the structures as pointers into threadTimes 
    1552     _thread_times(handle, ctypes.pointer(creation_time), ctypes.pointer(exit_time), ctypes.pointer(kernel_time), ctypes.pointer(user_time)) 
    1553    
    1554     # Close thread Handle 
    1555     close_thread_handle(handle) 
    1556      
    1557     # Update all the counters 
    1558     creation_time_sum += creation_time.dwLowDateTime 
    1559     exit_time_sum += exit_time.dwLowDateTime 
    1560     kernel_time_sum += kernel_time.dwLowDateTime 
    1561     user_time_sum += user_time.dwLowDateTime 
    1562    
    1563   # Return the proper values in a dictionaries 
    1564   return {"CreationTime":creation_time_sum,"KernelTime":kernel_time_sum,"UserTime":user_time_sum} 
    1565  
    1566  
    1567  
    1568 # Windows CE does not have a GetProcessMemoryInfo function, 
    1569 # so memory usage may be more inaccurate 
    1570 # We iterate over all of the process's heap spaces, and tally up the 
    1571 # total size, and return that value for all types of usage 
    1572 def _process_memory_info_ce(pid): 
    1573   heap_size = 0 # Keep track of heap size 
    1574   heap_list = _HEAPLIST32() # List of heaps 
    1575   heap_entry = _HEAPENTRY32() # Current Heap entry 
    1576    
    1577   heap_list.dwSize = ctypes.sizeof(_HEAPLIST32) 
    1578   heap_entry.dwSize = ctypes.sizeof(_HEAPENTRY32) 
    1579    
    1580   # Create Handle to snapshot of all system threads 
    1581   handle = _create_snapshot(TH32CS_SNAPHEAPLIST, pid) 
    1582    
    1583   # Check if handle was created successfully 
    1584   if handle == INVALID_HANDLE_VALUE: 
    1585     return {} 
    1586    
    1587   # Attempt to read snapshot 
    1588   if not _heap_list_first( handle, ctypes.pointer(heap_list)): 
    1589     _close_snapshot(handle) 
    1590     _close_handle(handle) 
    1591     return {} 
    1592    
    1593   # Loop through threads, check for threads associated with the right process 
    1594   more_heaps = True 
    1595   while (more_heaps): 
    1596      
    1597     # Check if there is a heap entry here 
    1598     if _heap_first(handle, ctypes.pointer(heap_entry), heap_list.th32ProcessID, heap_list.th32HeapID): 
    1599        
    1600       # Loop through available heaps 
    1601       more_entries = True 
    1602       while more_entries: 
    1603         # Increment the total heap size by the current heap size 
    1604         heap_size += heap_entry.dwBlockSize 
    1605          
    1606         heap_entry.dwSize = ctypes.sizeof(_HEAPENTRY32) 
    1607         more_entries = _heap_next(handle, ctypes.pointer(heap_entry)) # Go to next Heap entry 
    1608      
    1609     heap_list.dwSize = ctypes.sizeof(_HEAPLIST32) 
    1610     more_heaps = _heap_list_next(handle, ctypes.pointer(heap_list)) # Go to next Heap List 
    1611    
    1612   # Cleanup snapshot 
    1613   _close_snapshot(handle) 
    1614   _close_handle(handle) 
    1615    
    1616   # Since we only have one value, return that for all different possible sets 
    1617   return {'PageFaultCount':heap_size, 
    1618           'PeakWorkingSetSize':heap_size, 
    1619           'WorkingSetSize':heap_size, 
    1620           'QuotaPeakPagedPoolUsage':heap_size, 
    1621           'QuotaPagedPoolUsage':heap_size, 
    1622           'QuotaPeakNonPagedPoolUsage':heap_size, 
    1623           'QuotaNonPagedPoolUsage':heap_size, 
    1624           'PagefileUsage':heap_size, 
    1625           'PeakPagefileUsage':heap_size}   
    1626  
    1627  
    1628 # Windows CE does not have a separate handle for threads 
    1629 # Since handles and identifiers are interoperable, just return the ID 
    1630 # Set process permissions higher or else this will fail 
    1631 def _open_thread_ce(thread_id): 
    1632         # Save original permissions 
    1633         global _original_permissions_ce 
    1634         _original_permissions_ce = _get_process_permissions() 
    1635          
    1636         # Get full system control 
    1637         _set_current_proc_permissions(CE_FULL_PERMISSIONS) 
    1638          
    1639         return thread_id 
    1640  
    1641 # Sets the permission level of the current process 
    1642 def _set_current_proc_permissions(permission): 
    1643         _set_process_permissions(permission) 
    1644  
    1645 # Global variable to store permissions 
    1646 _original_permissions_ce = None 
    1647  
    1648 # Returns the permission level of the current process 
    1649 def _get_process_permissions(): 
    1650         return _get_current_permissions() 
    1651  
    1652 # Reverts permissions to original 
    1653 def _revert_permissions(): 
    1654         global _original_permissions_ce 
    1655         if not _original_permissions_ce == None: 
    1656                 _set_current_proc_permissions(_original_permissions_ce) 
    1657  
    1658 # Returns ID of current thread on WinCE 
    1659 def _current_thread_id_ce(): 
    1660   # We need to check this specific memory address 
    1661   loc = ctypes.cast(0xFFFFC808, ctypes.POINTER(ctypes.c_ulong)) 
    1662   # Then follow the pointer to get the value there 
    1663   return loc.contents.value 
    1664  
    1665 # Over ride this for CE 
    1666 if MobileCE: 
    1667   _current_thread_id = _current_thread_id_ce 
    1668    
    16691411## Resource Determining Functions 
    16701412# For number of CPU's check the %NUMBER_OF_PROCESSORS% Environment variable  
     
    17281470    availableVirtual: The amount of unreserved and uncommitted memory currently in the user-mode portion of the virtual address space of the calling process, in bytes. 
    17291471  """ 
    1730   # Check if it is CE 
    1731   if MobileCE: 
    1732     # Use the CE specific function 
    1733     return _global_memory_info_ce() 
    17341472     
    17351473  # Initialize the data structure 
     
    17531491  "availableVirtual":mem_info.ullAvailVirtual} 
    17541492     
    1755 def _global_memory_info_ce(): 
    1756   # Initialize the data structure 
    1757   mem_info = _MEMORYSTATUS() # Memory usage ints 
    1758   mem_info.dwLength = ctypes.sizeof(_MEMORYSTATUS) 
    1759    
    1760   # Make the call 
    1761   _global_memory_status(ctypes.pointer(mem_info)) 
    1762    
    1763   # Return Dictionary 
    1764   return {"load":mem_info.dwMemoryLoad, 
    1765   "totalPhysical":mem_info.dwTotalPhys, 
    1766   "availablePhysical":mem_info.dwAvailPhys, 
    1767   "totalPageFile":mem_info.dwTotalPageFile, 
    1768   "availablePageFile":mem_info.dwAvailPageFile, 
    1769   "totalVirtual":mem_info.dwTotalVirtual, 
    1770   "availableVirtual":mem_info.dwAvailVirtual} 
    1771    
    1772    
    1773