fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] multi line output messed up


From: Xinan Wu
Subject: Re: [Fab-user] multi line output messed up
Date: Sun, 12 Jul 2009 23:59:56 -0700

Jeff, Sorry I should have included examples... was in a hurry when I
sent my first email. So here's two cases:

expected (executed directly on server):
$ make -C xxxx alt
make: Entering directory `xxxx'
rm -rf build
python setup.py build --use-own-ensure-utf8
running build
running build_ext
building 'cxmlwriter' extension
creating build
creating build/temp.linux-x86_64-2.5
...


output by fab (not always, but sometimes, and line prefix [x.x.x.x]
out: are deleted so it's easier to compare)
make: Entering directory `xxxx'
rm -rf build
rm -rf buildpython setup.py build --use-own-ensure-utf8
rm -rf buildrunning build
rm -rf buildrunning build_ext
rm -rf buildbuilding 'cxmlwriter' extension
rm -rf buildcreating build
rm -rf buildcreating build/temp.linux-x86_64-2.5



2nd example:

expected:
stopping...
stopped

actual:
stopping...

The reason is .splitlines() does not put an empty str at the end of
array when the last char in out is \n, so the leftover logic is
incorrect. (I am using python 2.5, don't know if 2.6 changes this,
unlikely though)

The code in old 0.1.1 was in fact pretty solid except it didn't handle
\r case. The patch I included in my first email wasn't as solid.
Here's a probably better fix but still a bit ugly :)

diff -ur fabric-0.9b1-original/fabric/network.py fabric-0.9b1/fabric/network.py
--- fabric-0.9b1-original/fabric/network.py     2009-07-02 21:36:15.000000000 
-0700
+++ fabric-0.9b1/fabric/network.py      2009-07-12 23:56:45.000000000 -0700
@@ -319,9 +319,10 @@
             # leftovers, if any.
             if '\n' in out or '\r' in out:
                 parts = out.splitlines()
+                if out[len(out)-1] in '\r\n':
+                    parts.append('')
                 line = leftovers + parts.pop(0)
-                if parts:
-                    leftovers = parts.pop()
+                leftovers = parts.pop()
                 while parts or line:
                     # Write stderr to our own stderr.
                     out_stream = stderr and sys.stderr or sys.stdout



On Sun, Jul 12, 2009 at 9:53 AM, Jeff Forcier<address@hidden> wrote:
> Hi,
>
> Can you give me a specific example of your input/output/expected
> output? From what you've said, it sounds like you're having *blank*
> lines being eaten, not lines containing text -- is this true? Either
> way, detailed info would be helpful :)
>
> I note that str.splitlines() does break on both \r and \n, so the
> re.split() should not be necessary.
>
> Thanks,
> Jeff
>
>
> On Fri, Jul 10, 2009 at 11:43 PM, Xinan Wu<address@hidden> wrote:
>> swallows second line, etc. following is a possible fix.
>>
>> diff -ur fabric-0.9b1-original/fabric/network.py 
>> fabric-0.9b1/fabric/network.py
>> --- fabric-0.9b1-original/fabric/network.py     2009-07-02 
>> 21:36:15.000000000 -0700
>> +++ fabric-0.9b1/fabric/network.py      2009-07-10 20:35:10.000000000 -0700
>> @@ -318,7 +318,7 @@
>>             # Deal with line breaks, printing all lines and storing the
>>             # leftovers, if any.
>>             if '\n' in out or '\r' in out:
>> -                parts = out.splitlines()
>> +                parts = re.split(r'\r?\n', out)
>>                 line = leftovers + parts.pop(0)
>>                 if parts:
>>                     leftovers = parts.pop()
>>
>>
>>
>> in old fabric-0.1.1, this is used to be out.split('\n')
>>
>> "1\n2\n".split('\n') -> ['1','2','']
>> "1\n2\n".splitlines() -> ['1','2']
>>
>>
>> _______________________________________________
>> Fab-user mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/fab-user
>>
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]