comparison upmana/mercurial/posix.py @ 121:496dbf12a6cb alpha

Traipse Alpha 'OpenRPG' {091030-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 (Cleaning up for Beta): Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree {091029} Changes made to server to start working with Element Tree. Changes made to Meta Server Lib. Prepping test work for a multi meta network page. Minor bug fixed with mini to gametree Zoom Mouse plugin added. {091030} Getting ready for Beta. Server needs debugging so Alpha remains bugged. Plugin UI code cleaned. Auto start works with a graphic, pop-up asks to enable or disable plugin. Update Manager now has a partially working Status Bar. Status Bar captures terminal text, so Merc out put is visible. Manifest.xml file, will be renamed, is now much cleaner. Debug Console has a clear button and a Report Bug button. Prep work for a Term2Win class in Debug Console. Known: Current Alpha fails in Windows.
author sirebral
date Fri, 30 Oct 2009 22:21:40 -0500
parents
children
comparison
equal deleted inserted replaced
120:d86e762a994f 121:496dbf12a6cb
1 # posix.py - Posix utility function implementations for Mercurial
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 from i18n import _
9 import osutil
10 import os, sys, errno, stat, getpass, pwd, grp
11
12 posixfile = file
13 nulldev = '/dev/null'
14 normpath = os.path.normpath
15 samestat = os.path.samestat
16 expandglobs = False
17
18 umask = os.umask(0)
19 os.umask(umask)
20
21 def openhardlinks():
22 '''return true if it is safe to hold open file handles to hardlinks'''
23 return True
24
25 def rcfiles(path):
26 rcs = [os.path.join(path, 'hgrc')]
27 rcdir = os.path.join(path, 'hgrc.d')
28 try:
29 rcs.extend([os.path.join(rcdir, f)
30 for f, kind in osutil.listdir(rcdir)
31 if f.endswith(".rc")])
32 except OSError:
33 pass
34 return rcs
35
36 def system_rcpath():
37 path = []
38 # old mod_python does not set sys.argv
39 if len(getattr(sys, 'argv', [])) > 0:
40 path.extend(rcfiles(os.path.dirname(sys.argv[0]) +
41 '/../etc/mercurial'))
42 path.extend(rcfiles('/etc/mercurial'))
43 return path
44
45 def user_rcpath():
46 return [os.path.expanduser('~/.hgrc')]
47
48 def parse_patch_output(output_line):
49 """parses the output produced by patch and returns the filename"""
50 pf = output_line[14:]
51 if os.sys.platform == 'OpenVMS':
52 if pf[0] == '`':
53 pf = pf[1:-1] # Remove the quotes
54 else:
55 if pf.startswith("'") and pf.endswith("'") and " " in pf:
56 pf = pf[1:-1] # Remove the quotes
57 return pf
58
59 def sshargs(sshcmd, host, user, port):
60 '''Build argument list for ssh'''
61 args = user and ("%s@%s" % (user, host)) or host
62 return port and ("%s -p %s" % (args, port)) or args
63
64 def is_exec(f):
65 """check whether a file is executable"""
66 return (os.lstat(f).st_mode & 0100 != 0)
67
68 def set_flags(f, l, x):
69 s = os.lstat(f).st_mode
70 if l:
71 if not stat.S_ISLNK(s):
72 # switch file to link
73 data = file(f).read()
74 os.unlink(f)
75 try:
76 os.symlink(data, f)
77 except:
78 # failed to make a link, rewrite file
79 file(f, "w").write(data)
80 # no chmod needed at this point
81 return
82 if stat.S_ISLNK(s):
83 # switch link to file
84 data = os.readlink(f)
85 os.unlink(f)
86 file(f, "w").write(data)
87 s = 0666 & ~umask # avoid restatting for chmod
88
89 sx = s & 0100
90 if x and not sx:
91 # Turn on +x for every +r bit when making a file executable
92 # and obey umask.
93 os.chmod(f, s | (s & 0444) >> 2 & ~umask)
94 elif not x and sx:
95 # Turn off all +x bits
96 os.chmod(f, s & 0666)
97
98 def set_binary(fd):
99 pass
100
101 def pconvert(path):
102 return path
103
104 def localpath(path):
105 return path
106
107 def shellquote(s):
108 if os.sys.platform == 'OpenVMS':
109 return '"%s"' % s
110 else:
111 return "'%s'" % s.replace("'", "'\\''")
112
113 def quotecommand(cmd):
114 return cmd
115
116 def popen(command, mode='r'):
117 return os.popen(command, mode)
118
119 def testpid(pid):
120 '''return False if pid dead, True if running or not sure'''
121 if os.sys.platform == 'OpenVMS':
122 return True
123 try:
124 os.kill(pid, 0)
125 return True
126 except OSError, inst:
127 return inst.errno != errno.ESRCH
128
129 def explain_exit(code):
130 """return a 2-tuple (desc, code) describing a process's status"""
131 if os.WIFEXITED(code):
132 val = os.WEXITSTATUS(code)
133 return _("exited with status %d") % val, val
134 elif os.WIFSIGNALED(code):
135 val = os.WTERMSIG(code)
136 return _("killed by signal %d") % val, val
137 elif os.WIFSTOPPED(code):
138 val = os.WSTOPSIG(code)
139 return _("stopped by signal %d") % val, val
140 raise ValueError(_("invalid exit code"))
141
142 def isowner(st):
143 """Return True if the stat object st is from the current user."""
144 return st.st_uid == os.getuid()
145
146 def find_exe(command):
147 '''Find executable for command searching like which does.
148 If command is a basename then PATH is searched for command.
149 PATH isn't searched if command is an absolute or relative path.
150 If command isn't found None is returned.'''
151 if sys.platform == 'OpenVMS':
152 return command
153
154 def findexisting(executable):
155 'Will return executable if existing file'
156 if os.path.exists(executable):
157 return executable
158 return None
159
160 if os.sep in command:
161 return findexisting(command)
162
163 for path in os.environ.get('PATH', '').split(os.pathsep):
164 executable = findexisting(os.path.join(path, command))
165 if executable is not None:
166 return executable
167 return None
168
169 def set_signal_handler():
170 pass
171
172 def statfiles(files):
173 'Stat each file in files and yield stat or None if file does not exist.'
174 lstat = os.lstat
175 for nf in files:
176 try:
177 st = lstat(nf)
178 except OSError, err:
179 if err.errno not in (errno.ENOENT, errno.ENOTDIR):
180 raise
181 st = None
182 yield st
183
184 def getuser():
185 '''return name of current user'''
186 return getpass.getuser()
187
188 def expand_glob(pats):
189 '''On Windows, expand the implicit globs in a list of patterns'''
190 return list(pats)
191
192 def username(uid=None):
193 """Return the name of the user with the given uid.
194
195 If uid is None, return the name of the current user."""
196
197 if uid is None:
198 uid = os.getuid()
199 try:
200 return pwd.getpwuid(uid)[0]
201 except KeyError:
202 return str(uid)
203
204 def groupname(gid=None):
205 """Return the name of the group with the given gid.
206
207 If gid is None, return the name of the current group."""
208
209 if gid is None:
210 gid = os.getgid()
211 try:
212 return grp.getgrgid(gid)[0]
213 except KeyError:
214 return str(gid)