This patch makes End_Of_Line LF on web2py at Windows

28 views
Skip to first unread message

Keishi Ooshio

unread,
Apr 24, 2011, 1:40:59 AM4/24/11
to web2py-users
I use web2py-1.94.6 at WindowsXp sp3.
I make application "foo" with "New simple application" on "http://
127.0.0.1:8000/admin/default/site".
I clicked "edit" under "foo" and "edit" under "Controllers".
Doing nothing,I pushed save button.Then, End_Of_Line is changed from
LF(\n) to CRLF(\r\n).

---- print out with od -c(cygwin) ----
keishi@kotori /cygdrive/c/web2py/web2py-1.94.6/applications/foo/
controllers
$ head -n 1 default.py|od -c
0000000 # - * - c o d i n g : u
t
0000020 f - 8 - * - \r \n
0000031

---- end ----

I think this makes confusion between Windows user and Liunx user.
So I propose that we use open([file],"wb") in opening file for writing
on all platform because "b" is ignored

except Windows and in reading no ploblem is found.
There is a patch with "hg export" below.(Repository is cloned with "hg
clone https://web2py.googlecode.com/hg/

web2py" on April 20 2011.)

---- start ----

# HG changeset patch
# User Keishi Ooshio <keishi...@gmail.com>
# Date 1303271041 -32400
# Node ID 4eb4d5ed36842c0cfde337c43709c970bfb99418
# Parent 9c0bfc66640443cb58db7854b3e9f1eaa0d0c23e
In Editting on Windows ,Make End_Of_Line LF

diff -r 9c0bfc666404 -r 4eb4d5ed3684 applications/admin/controllers/
default.py
--- a/applications/admin/controllers/default.py Wed Apr 20 11:51:41
2011 +0900
+++ b/applications/admin/controllers/default.py Wed Apr 20 12:44:01
2011 +0900
@@ -5,6 +5,7 @@
from glob import glob
import shutil
import platform
+import re

if DEMO_MODE and request.function in

['change_password','pack','pack_plugin','upgrade_web2py','uninstall','cleanup','compile_app','remove_compiled_app

','delete','delete_plugin','create_file','upload_file','update_languages','reload_routes']:
session.flash = T('disabled in demo mode')
@@ -23,6 +24,8 @@
class tmp:
def write(self,data): pass
return tmp()
+ if platform.system() == 'Windows':
+ b = re.sub(r"wb?","wb",b)
return open(a,b)

def get_app(name=None):
diff -r 9c0bfc666404 -r 4eb4d5ed3684 applications/admin/controllers/
gae.py
--- a/applications/admin/controllers/gae.py Wed Apr 20 11:51:41 2011
+0900
+++ b/applications/admin/controllers/gae.py Wed Apr 20 12:44:01 2011
+0900
@@ -55,7 +55,7 @@
data=open(yaml,'r').read()
data = re.sub('application:.*','application: %s' %
form.vars.google_application_id,data)
data = regex.sub('(applications/(%s)/.*)|' %
'|'.join(ignore_apps),data)
- open(yaml,'w').write(data)
+ open(yaml,'wb').write(data)

path = request.env.applications_parent
cmd = '%s --email=%s --passin update %s' % \
diff -r 9c0bfc666404 -r 4eb4d5ed3684 applications/admin/controllers/
mercurial.py
--- a/applications/admin/controllers/mercurial.py Wed Apr 20 11:51:41
2011 +0900
+++ b/applications/admin/controllers/mercurial.py Wed Apr 20 12:44:01
2011 +0900
@@ -29,7 +29,7 @@
repo = hg.repository(ui=uio, path=path, create=True)
hgignore = os.path.join(path, '.hgignore')
if not os.path.exists(hgignore):
- open(hgignore, 'w').write(_hgignore_content)
+ open(hgignore, 'wb').write(_hgignore_content)
return repo

def commit():

---- end ----

Massimo Di Pierro

unread,
Apr 24, 2011, 9:30:29 AM4/24/11
to web2py-users
Hello Keishi, thanks for the patch.
This has pros and cons. Let's discuss it on web2py-developers and feel
free to join.

Other windows users, what do you think?

Massimo

On Apr 24, 12:40 am, Keishi Ooshio <keishi.oos...@gmail.com> wrote:
> I use web2py-1.94.6 at WindowsXp sp3.
> I make application "foo" with "New simple application" on "http://
> 127.0.0.1:8000/admin/default/site".
> I clicked "edit" under "foo" and "edit" under "Controllers".
> Doing nothing,I pushed save button.Then, End_Of_Line is changed from
> LF(\n) to CRLF(\r\n).
>
> ---- print out with od -c(cygwin) ----
> keishi@kotori /cygdrive/c/web2py/web2py-1.94.6/applications/foo/
> controllers
> $ head -n 1 default.py|od -c
> 0000000   #       -   *   -       c   o   d   i   n   g   :       u
> t
> 0000020   f   -   8       -   *   -  \r  \n
> 0000031
>
> ---- end ----
>
> I think this makes confusion between Windows user and Liunx user.
> So I propose that we use open([file],"wb") in opening file for writing
> on all platform because "b" is ignored
>
> except Windows and in reading no ploblem is found.
> There is a patch with "hg export" below.(Repository is cloned with "hg
> clonehttps://web2py.googlecode.com/hg/
>
> web2py" on April 20 2011.)
>
> ---- start  ----
>
> # HG changeset patch
> # User Keishi Ooshio <keishi.oos...@gmail.com>
> # Date 1303271041 -32400
> # Node ID 4eb4d5ed36842c0cfde337c43709c970bfb99418
> # Parent  9c0bfc66640443cb58db7854b3e9f1eaa0d0c23e
> In Editting on Windows ,Make End_Of_Line LF
>
> diff -r 9c0bfc666404 -r 4eb4d5ed3684 applications/admin/controllers/
> default.py
> --- a/applications/admin/controllers/default.py Wed Apr 20 11:51:41
> 2011 +0900
> +++ b/applications/admin/controllers/default.py Wed Apr 20 12:44:01
> 2011 +0900
> @@ -5,6 +5,7 @@
>  from glob import glob
>  import shutil
>  import platform
> +import re
>
>  if DEMO_MODE and request.function in
>
> ['change_password','pack','pack_plugin','upgrade_web2py','uninstall','clean up','compile_app','remove_compiled_app

villas

unread,
Apr 24, 2011, 7:38:40 PM4/24/11
to web2py-users
If we wish to maintain consistent line-endings, it seems clear that
we should use this patch.

Having said that, this has not caused any problems for me in the
past.


On Apr 24, 2:30 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:

Massimo Di Pierro

unread,
Apr 24, 2011, 8:22:52 PM4/24/11
to web2py-users
The problem is that with the patch if you try open the files with a
windows editor, the line-endings will not have the CR and may not be
indented as expected.

Anthony

unread,
Apr 24, 2011, 8:58:30 PM4/24/11
to web...@googlegroups.com
On Sunday, April 24, 2011 8:22:52 PM UTC-4, Massimo Di Pierro wrote:
The problem is that with the patch if you try open the files with a
windows editor, the line-endings will not have the CR and may not be
indented as expected.
 
I think most Windows editors can handle text files that only use LF for ending lines. I'm using Windows 7, and for me, Notepad++, Komodo Edit, and Aptana/Eclipse all handle the web2py source files (which use LF without CR to end lines) just fine. The only Windows editor that appears to require CR/LF is Notepad.
 
It probably makes sense to have the admin editor save with LF's only just to maintain consistency with the standard web2py files. For example, all the 'welcome' app files have LF's. If you happen to save one of the 'welcome' app files via the admin editor, it converts all the LF's to CR/LF's -- then some of your app's files have LF's, and some have CR/LF's. It's probably better to be consistent.
 
Anthony

Massimo Di Pierro

unread,
Apr 24, 2011, 9:23:51 PM4/24/11
to web2py-users
Let's give this a day. Are there any windows users who strongly oppose
this change?
Reply all
Reply to author
Forward
0 new messages