comparison upmana/mercurial/win32.py @ 28:ff154cf3350c ornery-orc

Traipse 'OpenRPG' {100203-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Stable) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Wed, 03 Feb 2010 22:16:49 -0600
parents
children
comparison
equal deleted inserted replaced
27:51428d30c59e 28:ff154cf3350c
1 # win32.py - utility functions that use win32 API
2 #
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
7
8 """Utility functions that use win32 API.
9
10 Mark Hammond's win32all package allows better functionality on
11 Windows. This module overrides definitions in util.py. If not
12 available, import of this module will fail, and generic code will be
13 used.
14 """
15
16 import win32api
17
18 import errno, os, sys, pywintypes, win32con, win32file, win32process
19 import winerror
20 import osutil, encoding
21 from win32com.shell import shell,shellcon
22
23 def os_link(src, dst):
24 try:
25 win32file.CreateHardLink(dst, src)
26 # CreateHardLink sometimes succeeds on mapped drives but
27 # following nlinks() returns 1. Check it now and bail out.
28 if nlinks(src) < 2:
29 try:
30 win32file.DeleteFile(dst)
31 except:
32 pass
33 # Fake hardlinking error
34 raise OSError(errno.EINVAL, 'Hardlinking not supported')
35 except pywintypes.error, details:
36 raise OSError(errno.EINVAL, 'target implements hardlinks improperly')
37 except NotImplementedError: # Another fake error win Win98
38 raise OSError(errno.EINVAL, 'Hardlinking not supported')
39
40 def nlinks(pathname):
41 """Return number of hardlinks for the given file."""
42 try:
43 fh = win32file.CreateFile(pathname,
44 win32file.GENERIC_READ, win32file.FILE_SHARE_READ,
45 None, win32file.OPEN_EXISTING, 0, None)
46 res = win32file.GetFileInformationByHandle(fh)
47 fh.Close()
48 return res[7]
49 except pywintypes.error:
50 return os.lstat(pathname).st_nlink
51
52 def testpid(pid):
53 '''return True if pid is still running or unable to
54 determine, False otherwise'''
55 try:
56 handle = win32api.OpenProcess(
57 win32con.PROCESS_QUERY_INFORMATION, False, pid)
58 if handle:
59 status = win32process.GetExitCodeProcess(handle)
60 return status == win32con.STILL_ACTIVE
61 except pywintypes.error, details:
62 return details[0] != winerror.ERROR_INVALID_PARAMETER
63 return True
64
65 def lookup_reg(key, valname=None, scope=None):
66 ''' Look up a key/value name in the Windows registry.
67
68 valname: value name. If unspecified, the default value for the key
69 is used.
70 scope: optionally specify scope for registry lookup, this can be
71 a sequence of scopes to look up in order. Default (CURRENT_USER,
72 LOCAL_MACHINE).
73 '''
74 try:
75 from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, \
76 QueryValueEx, OpenKey
77 except ImportError:
78 return None
79
80 if scope is None:
81 scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE)
82 elif not isinstance(scope, (list, tuple)):
83 scope = (scope,)
84 for s in scope:
85 try:
86 val = QueryValueEx(OpenKey(s, key), valname)[0]
87 # never let a Unicode string escape into the wild
88 return encoding.tolocal(val.encode('UTF-8'))
89 except EnvironmentError:
90 pass
91
92 def system_rcpath_win32():
93 '''return default os-specific hgrc search path'''
94 proc = win32api.GetCurrentProcess()
95 try:
96 # This will fail on windows < NT
97 filename = win32process.GetModuleFileNameEx(proc, 0)
98 except:
99 filename = win32api.GetModuleFileName(0)
100 # Use mercurial.ini found in directory with hg.exe
101 progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
102 if os.path.isfile(progrc):
103 return [progrc]
104 # else look for a system rcpath in the registry
105 try:
106 value = win32api.RegQueryValue(
107 win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Mercurial')
108 rcpath = []
109 for p in value.split(os.pathsep):
110 if p.lower().endswith('mercurial.ini'):
111 rcpath.append(p)
112 elif os.path.isdir(p):
113 for f, kind in osutil.listdir(p):
114 if f.endswith('.rc'):
115 rcpath.append(os.path.join(p, f))
116 return rcpath
117 except pywintypes.error:
118 return []
119
120 def user_rcpath_win32():
121 '''return os-specific hgrc search path to the user dir'''
122 userdir = os.path.expanduser('~')
123 if sys.getwindowsversion()[3] != 2 and userdir == '~':
124 # We are on win < nt: fetch the APPDATA directory location and use
125 # the parent directory as the user home dir.
126 appdir = shell.SHGetPathFromIDList(
127 shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_APPDATA))
128 userdir = os.path.dirname(appdir)
129 return [os.path.join(userdir, 'mercurial.ini'),
130 os.path.join(userdir, '.hgrc')]
131
132 def getuser():
133 '''return name of current user'''
134 return win32api.GetUserName()
135
136 def set_signal_handler_win32():
137 """Register a termination handler for console events including
138 CTRL+C. python signal handlers do not work well with socket
139 operations.
140 """
141 def handler(event):
142 win32process.ExitProcess(1)
143 win32api.SetConsoleCtrlHandler(handler)
144