153
152
' or win32process')
156
# using base-2 units (see HACKING.txt).
157
trace.note('WorkingSize %7dKiB'
158
'\tPeakWorking %7dKiB\t%s',
155
trace.note('WorkingSize %7dKB'
156
'\tPeakWorking %7dKB\t%s',
159
157
info['WorkingSetSize'] / 1024,
160
158
info['PeakWorkingSetSize'] / 1024,
164
162
trace.note('%s', message)
165
trace.note('WorkingSize %8d KiB', info['WorkingSetSize'] / 1024)
166
trace.note('PeakWorking %8d KiB', info['PeakWorkingSetSize'] / 1024)
167
trace.note('PagefileUsage %8d KiB', info.get('PagefileUsage', 0) / 1024)
168
trace.note('PeakPagefileUsage %8d KiB',
169
info.get('PeakPagefileUsage', 0) / 1024)
170
trace.note('PrivateUsage %8d KiB', info.get('PrivateUsage', 0) / 1024)
163
trace.note('WorkingSize %8d KB', info['WorkingSetSize'] / 1024)
164
trace.note('PeakWorking %8d KB', info['PeakWorkingSetSize'] / 1024)
165
trace.note('PagefileUsage %8d KB', info.get('PagefileUsage', 0) / 1024)
166
trace.note('PeakPagefileUsage %8d KB', info.get('PeakPagefileUsage', 0) / 1024)
167
trace.note('PrivateUsage %8d KB', info.get('PrivateUsage', 0) / 1024)
171
168
trace.note('PageFaultCount %8d', info.get('PageFaultCount', 0))
522
517
trace.mutter('Unable to set hidden attribute on %r: %s', path, e)
525
def _command_line_to_argv(command_line, single_quotes_allowed=False):
520
_whitespace_match = re.compile(u'\s').match
523
class _PushbackSequence(object):
524
def __init__(self, orig):
525
self._iter = iter(orig)
526
self._pushback_buffer = []
529
if len(self._pushback_buffer) > 0:
530
return self._pushback_buffer.pop()
532
return self._iter.next()
534
def pushback(self, char):
535
self._pushback_buffer.append(char)
541
class _Whitespace(object):
542
def process(self, next_char, seq, context):
543
if _whitespace_match(next_char):
544
if len(context.token) > 0:
548
elif (next_char == u'"'
549
or (context.single_quotes_allowed and next_char == u"'")):
550
context.quoted = True
551
return _Quotes(next_char, self)
552
elif next_char == u'\\':
553
return _Backslash(self)
555
context.token.append(next_char)
559
class _Quotes(object):
560
def __init__(self, quote_char, exit_state):
561
self.quote_char = quote_char
562
self.exit_state = exit_state
564
def process(self, next_char, seq, context):
565
if next_char == u'\\':
566
return _Backslash(self)
567
elif next_char == self.quote_char:
568
return self.exit_state
570
context.token.append(next_char)
574
class _Backslash(object):
575
# See http://msdn.microsoft.com/en-us/library/bb776391(VS.85).aspx
576
def __init__(self, exit_state):
577
self.exit_state = exit_state
580
def process(self, next_char, seq, context):
581
if next_char == u'\\':
584
elif next_char == u'"':
585
# 2N backslashes followed by '"' are N backslashes
586
context.token.append(u'\\' * (self.count/2))
587
# 2N+1 backslashes follwed by '"' are N backslashes followed by '"'
588
# which should not be processed as the start or end of quoted arg
589
if self.count % 2 == 1:
590
context.token.append(next_char) # odd number of '\' escapes the '"'
592
seq.pushback(next_char) # let exit_state handle next_char
594
return self.exit_state
596
# N backslashes not followed by '"' are just N backslashes
598
context.token.append(u'\\' * self.count)
600
seq.pushback(next_char) # let exit_state handle next_char
601
return self.exit_state
603
def finish(self, context):
605
context.token.append(u'\\' * self.count)
609
def process(self, next_char, seq, context):
610
if _whitespace_match(next_char):
612
elif (next_char == u'"'
613
or (context.single_quotes_allowed and next_char == u"'")):
614
return _Quotes(next_char, self)
615
elif next_char == u'\\':
616
return _Backslash(self)
618
context.token.append(next_char)
622
class UnicodeShlex(object):
623
def __init__(self, command_line, single_quotes_allowed=False):
624
self._seq = _PushbackSequence(command_line)
625
self.single_quotes_allowed = single_quotes_allowed
631
quoted, token = self._get_token()
636
def _get_token(self):
639
state = _Whitespace()
640
for next_char in self._seq:
641
state = state.process(next_char, self._seq, self)
644
if not state is None and not getattr(state, 'finish', None) is None:
646
result = u''.join(self.token)
647
if not self.quoted and result == '':
649
return self.quoted, result
652
def command_line_to_argv(command_line, wildcard_expansion=True,
653
single_quotes_allowed=False):
526
654
"""Convert a Unicode command line into a list of argv arguments.
528
It performs wildcard expansion to make wildcards act closer to how they
529
work in posix shells, versus how they work by default on Windows. Quoted
530
arguments are left untouched.
656
This optionally does wildcard expansion, etc. It is intended to make
657
wildcards act closer to how they work in posix shells, versus how they
658
work by default on Windows. Quoted arguments are left untouched.
532
660
:param command_line: The unicode string to split into an arg list.
661
:param wildcard_expansion: Whether wildcard expansion should be applied to
662
each argument. True by default.
533
663
:param single_quotes_allowed: Whether single quotes are accepted as quoting
534
664
characters like double quotes. False by
536
666
:return: A list of unicode strings.
538
s = cmdline.Splitter(command_line, single_quotes_allowed=single_quotes_allowed)
668
s = UnicodeShlex(command_line, single_quotes_allowed=single_quotes_allowed)
539
669
# Now that we've split the content, expand globs if necessary
540
670
# TODO: Use 'globbing' instead of 'glob.glob', this gives us stuff like
541
671
# '**/' style globs
543
673
for is_quoted, arg in s:
544
if is_quoted or not glob.has_magic(arg):
674
if is_quoted or not glob.has_magic(arg) or not wildcard_expansion:
547
677
args.extend(glob_one(arg))