/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Martin Pool
  • Date: 2007-09-14 06:31:28 UTC
  • mfrom: (2822 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2823.
  • Revision ID: mbp@sourcefrog.net-20070914063128-0p7mh6zfb4pzdg9p
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
240
240
    return _ensure_unicode(get_host_name())
241
241
 
242
242
 
 
243
def _ensure_with_dir(path):
 
244
    if not os.path.split(path)[0] or path.startswith(u'*') or path.startswith(u'?'):
 
245
        return u'./' + path, True
 
246
    else:
 
247
        return path, False
 
248
    
 
249
def _undo_ensure_with_dir(path, corrected):
 
250
    if corrected:
 
251
        return path[2:]
 
252
    else:
 
253
        return path
 
254
 
 
255
 
 
256
 
243
257
def glob_expand(file_list):
244
258
    """Replacement for glob expansion by the shell.
245
259
 
256
270
    import glob
257
271
    expanded_file_list = []
258
272
    for possible_glob in file_list:
 
273
        
 
274
        # work around bugs in glob.glob()
 
275
        # - Python bug #1001604 ("glob doesn't return unicode with ...")
 
276
        # - failing expansion for */* with non-iso-8859-* chars
 
277
        possible_glob, corrected = _ensure_with_dir(possible_glob)
259
278
        glob_files = glob.glob(possible_glob)
260
279
 
261
280
        if glob_files == []:
262
281
            # special case to let the normal code path handle
263
282
            # files that do not exists
264
 
            expanded_file_list.append(possible_glob)
 
283
            expanded_file_list.append(
 
284
                _undo_ensure_with_dir(possible_glob, corrected))
265
285
        else:
 
286
            glob_files = [_undo_ensure_with_dir(elem, corrected) for elem in glob_files]
266
287
            expanded_file_list += glob_files
267
 
    return expanded_file_list
268
 
 
269
 
 
 
288
            
 
289
    return [elem.replace(u'\\', u'/') for elem in expanded_file_list] 
 
290
 
 
291
 
 
292
def get_app_path(appname):
 
293
    """Look up in Windows registry for full path to application executable.
 
294
    Typicaly, applications create subkey with their basename
 
295
    in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
 
296
 
 
297
    :param  appname:    name of application (if no filename extension
 
298
                        is specified, .exe used)
 
299
    :return:    full path to aplication executable from registry,
 
300
                or appname itself if nothing found.
 
301
    """
 
302
    import _winreg
 
303
    try:
 
304
        hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
 
305
                               r'SOFTWARE\Microsoft\Windows'
 
306
                               r'\CurrentVersion\App Paths')
 
307
    except EnvironmentError:
 
308
        return appname
 
309
 
 
310
    basename = appname
 
311
    if not os.path.splitext(basename)[1]:
 
312
        basename = appname + '.exe'
 
313
    try:
 
314
        try:
 
315
            fullpath = _winreg.QueryValue(hkey, basename)
 
316
        except WindowsError:
 
317
            fullpath = appname
 
318
    finally:
 
319
        _winreg.CloseKey(hkey)
 
320
 
 
321
    return fullpath