/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: Robert Collins
  • Date: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Win32-specific helper functions
18
18
 
144
144
        trace.note('Cannot debug memory on win32 without ctypes'
145
145
                   ' or win32process')
146
146
        return
147
 
    trace.note('WorkingSize       %8d kB', info['WorkingSetSize'] / 1024)
148
 
    trace.note('PeakWorking       %8d kB', info['PeakWorkingSetSize'] / 1024)
149
147
    if short:
 
148
        trace.note('WorkingSize %7dKB'
 
149
                   '\tPeakWorking %7dKB\t%s',
 
150
                   info['WorkingSetSize'] / 1024,
 
151
                   info['PeakWorkingSetSize'] / 1024,
 
152
                   message)
150
153
        return
151
 
    trace.note('PagefileUsage     %8d kB', info.get('PagefileUsage', 0) / 1024)
152
 
    trace.note('PeakPagefileUsage %8d kB', info.get('PeakPagefileUsage', 0) / 1024)
153
 
    trace.note('PrivateUsage      %8d kB', info.get('PrivateUsage', 0) / 1024)
 
154
    if message:
 
155
        trace.note('%s', message)
 
156
    trace.note('WorkingSize       %8d KB', info['WorkingSetSize'] / 1024)
 
157
    trace.note('PeakWorking       %8d KB', info['PeakWorkingSetSize'] / 1024)
 
158
    trace.note('PagefileUsage     %8d KB', info.get('PagefileUsage', 0) / 1024)
 
159
    trace.note('PeakPagefileUsage %8d KB', info.get('PeakPagefileUsage', 0) / 1024)
 
160
    trace.note('PrivateUsage      %8d KB', info.get('PrivateUsage', 0) / 1024)
154
161
    trace.note('PageFaultCount    %8d', info.get('PageFaultCount', 0))
155
162
 
156
163
 
279
286
    If location cannot be obtained return system drive root,
280
287
    i.e. C:\
281
288
 
282
 
    Returned value can be unicode or plain sring.
 
289
    Returned value can be unicode or plain string.
283
290
    To convert plain string to unicode use
284
291
    s.decode(osutils.get_user_encoding())
285
292
    """
302
309
    """Return user name as login name.
303
310
    If name cannot be obtained return None.
304
311
 
305
 
    Returned value can be unicode or plain sring.
 
312
    Returned value can be unicode or plain string.
306
313
    To convert plain string to unicode use
307
314
    s.decode(osutils.get_user_encoding())
308
315
    """
426
433
    import glob
427
434
    expanded_file_list = []
428
435
    for possible_glob in file_list:
429
 
 
430
436
        # work around bugs in glob.glob()
431
437
        # - Python bug #1001604 ("glob doesn't return unicode with ...")
432
438
        # - failing expansion for */* with non-iso-8859-* chars
447
453
 
448
454
def get_app_path(appname):
449
455
    """Look up in Windows registry for full path to application executable.
450
 
    Typicaly, applications create subkey with their basename
 
456
    Typically, applications create subkey with their basename
451
457
    in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
452
458
 
453
459
    :param  appname:    name of application (if no filename extension
481
487
    """Set file attributes to hidden if possible"""
482
488
    if has_win32file:
483
489
        win32file.SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
 
490
 
 
491
 
 
492
if has_ctypes and winver != 'Windows 98':
 
493
    def get_unicode_argv():
 
494
        LPCWSTR = ctypes.c_wchar_p
 
495
        INT = ctypes.c_int
 
496
        POINTER = ctypes.POINTER
 
497
        prototype = ctypes.WINFUNCTYPE(LPCWSTR)
 
498
        GetCommandLine = prototype(("GetCommandLineW",
 
499
                                    ctypes.windll.kernel32))
 
500
        prototype = ctypes.WINFUNCTYPE(POINTER(LPCWSTR), LPCWSTR, POINTER(INT))
 
501
        CommandLineToArgv = prototype(("CommandLineToArgvW",
 
502
                                       ctypes.windll.shell32))
 
503
        c = INT(0)
 
504
        pargv = CommandLineToArgv(GetCommandLine(), ctypes.byref(c))
 
505
        # Skip the first argument, since we only care about parameters
 
506
        argv = [pargv[i] for i in range(1, c.value)]
 
507
        if getattr(sys, 'frozen', None) is None:
 
508
            # Invoked via 'python.exe' which takes the form:
 
509
            #   python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]
 
510
            # we need to get only BZR_OPTIONS part,
 
511
            # so let's using sys.argv[1:] as reference to get the tail
 
512
            # of unicode argv
 
513
            tail_len = len(sys.argv[1:])
 
514
            ix = len(argv) - tail_len
 
515
            argv = argv[ix:]
 
516
        return argv
 
517
else:
 
518
    get_unicode_argv = None