Re: pyinstaller wrong classified as Windows virus

2021-11-29 Thread Ulli Horlacher
anthony.flury  wrote:
> 
> On 26/11/2021 07:13, Ulli Horlacher wrote
> >> But consider another possibility that your compiler software is compromised
> > Then https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe
> > is infected. I doubt this.
> 
> But you aren't using python3.10 to 'compile' the code to the executable 
> that windows complains about: you are using pyinstaller, which if memory 
> serves is a 3rd party application.
> 
> I assume that you have no problem running the script without pyinstaller ?
> 
> so Might pyinstaller be compromised in some way ?

Then is the pip repository compromised. I doubt this, too.
I have installed pyinstaller with: pip intall pyinstaller


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CERTIFICATE_VERIFY_FAILED Windows only?

2021-11-28 Thread Ulli Horlacher
Chris Angelico  wrote:
> On Sun, Nov 28, 2021 at 6:38 AM Ulli Horlacher
>  wrote:
> >
> > My program uses https and runs fine on Linux, but on Windows it crashes:
> >
> > Google chrome and firefox both say the certifacte is valid:
> >
> > https://fex.flupp.org/fop/U4xC4kz8/X-20211127192031.png
> >
> > https://fex.flupp.org/fop/mBabXKSz/X-20211127192416.png
> >
> > Why does Python complain (only on Windows!)?
> >
> 
> What version of Python is it, and where did you install it from?

https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe


> On some versions, Python will use Microsoft's provided certificate store.
> One solution may be to fetch Mozilla's root certs from PyPI:
> 
> https://pypi.org/project/certifi/

C:\Users\admin>pip install certifi
Collecting certifi
  Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
Installing collected packages: certifi
Successfully installed certifi-2021.10.8


Great!
Now my program runs without CERTIFICATE_VERIFY_FAILED


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


CERTIFICATE_VERIFY_FAILED Windows only?

2021-11-27 Thread Ulli Horlacher
My program uses https and runs fine on Linux, but on Windows it crashes:

W10dev:/cygdrive/p: python fextasy.py -D
DEBUG(fextasy.py): verbose=0
DEBUG(fextasy.py): User-Agent: fextasy-20211127_1806 Windows 10.0.19041
DEBUG(fextasy.py): TCPCONNECT to fex.flupp.org:443
Traceback (most recent call last):
  File "P:\fextasy.py", line 1351, in 
main()
  File "P:\fextasy.py", line 232, in main
file = fexget('')
  File "P:\fextasy.py", line 622, in fexget
if not http_connect(server,port):
  File "P:\fextasy.py", line 956, in http_connect
if not tcp_connect(server,port): return
  File "P:\fextasy.py", line 973, in tcp_connect
sock = context.wrap_socket(sock,server_hostname=host)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\ssl.py", 
line 512, in wrap_socket
return self.sslsocket_class._create(
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\ssl.py", 
line 1070, in _create
self.do_handshake()
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\ssl.py", 
line 1341, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate 
verify failed: certificate has expired (_s
sl.c:997)


The sourcecode here is:

def tcp_connect(host,port):
  global sock

  message(f"D:TCPCONNECT to {host}:{port}")
  try:
sock = socket.create_connection((host,port))
  except socket.error as e:
message("E:cannot connect to %s:%d - %s" % (host,port,e.strerror))
return False
  sock.settimeout(timeout)
  if port == 443:
context = ssl.create_default_context()
sock = context.wrap_socket(sock,server_hostname=host)
  return True



Google chrome and firefox both say the certifacte is valid:

https://fex.flupp.org/fop/U4xC4kz8/X-20211127192031.png

https://fex.flupp.org/fop/mBabXKSz/X-20211127192416.png

Why does Python complain (only on Windows!)?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller wrong classified as Windows virus

2021-11-26 Thread Ulli Horlacher
Edmondo Giovannozzi  wrote:

> You can try to download winpython: 
> https://github.com/winpython/winpython/releases
> It is an executable, but you don't need to execute it as it is a 7zip 
> compressed archive.
> You may run it or use directly 7zip to decompress it, the result will be the 
> same. 
>  
> Then you have a full python installation that don't need to be installed. 
> You may try to put your program there and give the users that directory.

I do not understand it quite...
(How) can I add PySimpleGUI (*) and my program to this (self-extracting?)
package? 


https://sourceforge.net/projects/winpython/files/WinPython_3.10/3.10.0.1/
633 MB! I have a lot of users with internet speed < 200 kB/s

With pyinstaller my program executables are are around 10 MB.


(*) My programs depend on:
https://pysimplegui.readthedocs.io/en/latest/

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller wrong classified as Windows virus

2021-11-26 Thread Ulli Horlacher
Avi Gross  wrote:

> I am not sure what your real problem is, Ulli, but many antivirus programs
> can be TEMPORARILY shut off.

Meanwhile I found this configuration option.
But this does not help me much, because my programs must run on other
Windows PCs of other users and they cannot disable the default Windows
virus scanner.

I for myself does not use Windows at all, I just use it to compile my
programs.


> If one recognizes your code a potentially having a virus, it may be for an
> assortment of reasons such as a table it contains to look at position N in
> the executable for an exact match with some bit-string. If so, one potential
> fix is a slight change in the code that compiles a bit differently like
> x=sin(30) or other filler. 

I do not know what and where the virus scanning is complaining about.
It simple says virus threat found and then it deletes my executables.
It is the default virus scanner of Windows 10, I have not installed any
additional software (besides Python and cygwin).


> But consider another possibility that your compiler software is compromised

Then https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe
is infected. I doubt this.

  
> Is this happening to only one set of code?

This is happening SOMETIMES, not always. With the SAME source code. When I
call pyinstaller often enough, then the virus scanner is quiet. In about 1
of 20 compile runs.



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller wrong classified as Windows virus

2021-11-26 Thread Ulli Horlacher
Richard Damon  wrote:

> On a somewhat locked down computer, the user does not have admin rights, 
> so needs to get 'IT' to run any installers that need admin permissions 
> to run.
> 
> And EXE that just needs to be copied to the computer and rhen just RUN, 
> doesn't need IT to 'install' it (they just can't put it into Program 
> Files, but that isn't really that important for programs that don't need 
> an installer.

That's the situation for many of my users.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller wrong classified as Windows virus

2021-11-25 Thread Ulli Horlacher
Chris Angelico  wrote:

> Unfortunately, if you're not going to go to the effort of getting your
> executables signed

I cannot sign my executables (how can I do it anyway?), because Windows
deletes my executable as soon as I have compiled them! They exist only
for a few seconds and then they are gone.


> another reason to just distribute .py files.

I cannot do that because my users do not have Python installed and they
are not allowed to do it.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller wrong classified as Windows virus

2021-11-25 Thread Ulli Horlacher
Barry Scott  wrote:
> 
> 
> > On 25 Nov 2021, at 09:20, Ulli Horlacher  
> > wrote:
> > 
> > When I compile my programs with pyinstaller, Windows classifies them as
> > virus and even deletes them!
> 
> Microsoft will fix the malware detection if you provide the info they need.
> 
> Submit false positive info to: 
> https://www.microsoft.com/security/portal/submission/submit.aspx 
> <https://www.microsoft.com/security/portal/submission/submit.aspx>

I cannot submit my executables, because the Windows Virus scannners
deletes them as soon as I compile my program!

And I need a Microsoft login to submit a file!
I do not have such a login.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller wrong classified as Windows virus

2021-11-25 Thread Ulli Horlacher
Ulli Horlacher  wrote:
> Dan Purgert  wrote:
> 
> > > When I compile my programs with pyinstaller, Windows classifies them as
> > > virus and even deletes them!
> > > [...]
> > 
> > Have you tried compiling from a different machine? Maybe there's
> > something broken on the one that's flagging them. 
> 
> I have only this Windows installation.
> 
> But meanwhile I can compile my program and Windows does not complain any
> more about Viruses, though I have not changed anything in my source code!

And now the bad virus reports are back. With the SAME sourcecode!
It is totally erratic.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


pyinstaller wrong classified as Windows virus

2021-11-25 Thread Ulli Horlacher
When I compile my programs with pyinstaller, Windows classifies them as
virus and even deletes them!

pyinstaller.exe --onefile --noconsole -i fex.ico fextasy.py
187 INFO: PyInstaller: 4.7
187 INFO: Python: 3.10.0
218 INFO: Platform: Windows-10-10.0.19041-SP0
218 INFO: wrote P:\W10\fextasy.spec
(...)
14392 INFO: Copying 0 resources to EXE
14392 INFO: Emedding manifest in EXE
14392 INFO: Updating manifest in P:\W10\dist\fextasy.exe
14533 INFO: Updating resource type 24 name 1 language 0
14579 INFO: Appending PKG archive to EXE
18836 INFO: Building EXE from EXE-00.toc completed successfully.

https://fex.flupp.org/fop/ylds7Y9d/X-20211125101112.png

What can I do?

Rebooting does not help :-}

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller wrong classified as Windows virus

2021-11-25 Thread Ulli Horlacher
Dan Purgert  wrote:

> > When I compile my programs with pyinstaller, Windows classifies them as
> > virus and even deletes them!
> > [...]
> 
> Have you tried compiling from a different machine? Maybe there's
> something broken on the one that's flagging them. 

I have only this Windows installation.

But meanwhile I can compile my program and Windows does not complain any
more about Viruses, though I have not changed anything in my source code!


> Alternatively, maybe run updates?

I have done this before without any success (in respect to the wrong virus
report).

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller: icon not visable on desktop?

2021-11-24 Thread Ulli Horlacher
Calvin Spealman  wrote:
> What version of Windows is this on? That's probably going to be a useful
> bit of information, because there could be differences there to how EXE
> icons are handled.
> 
> On Tue, Nov 23, 2021 at 4:18 PM Ulli Horlacher <
> frams...@rus.uni-stuttgart.de> wrote:
> 
> > When I compile a python program with pyinstaller, I get an executable:
> >
> > pyinstaller --onefile --icon fex.ico fextasy.py
> >
> > But the executables icon is only visable within the windows file browser,
> > not on the desktop:
> >
> > https://fex.flupp.org/fop/V2ioMZcl/X-20211123213712.png

Python says: Windows 10.0.19041


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


pyinstaller: icon not visable on desktop?

2021-11-23 Thread Ulli Horlacher
When I compile a python program with pyinstaller, I get an executable:

pyinstaller --onefile --icon fex.ico fextasy.py

But the executables icon is only visable within the windows file browser, 
not on the desktop:

https://fex.flupp.org/fop/V2ioMZcl/X-20211123213712.png

There is only the default pyinstaller icon.

Why?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting source code line of error?

2021-11-20 Thread Ulli Horlacher
Stefan Ram  wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
> >except Exception as inst:
> >print( traceback.format_exc() )
> 
>   More to the point of getting the line number:

As I wrote in my initial posting:
I already have the line number. I am looking for the source code line! 

So far I use:

  m = re.search(r'\n\s*(.+)\n.*\n$',traceback.format_exc())
  if m: print('%s %s' % (prefix,m.group(1)))

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


getting source code line of error?

2021-11-19 Thread Ulli Horlacher
I am trying to get the source code line of the last error.
I know traceback.format_exc() but this contains much more information, e.g.:

Traceback (most recent call last):
  File "./error.py", line 18, in main
x=1/0
ZeroDivisionError: division by zero

I could extract the source code line with re.search(), but is there an
easier way?


I have:

  exc_type,exc_str,exc_tb = sys.exc_info()
  fname = exc_tb.tb_frame.f_code.co_filename
  line = exc_tb.tb_lineno
  print('%s in %s line %d' % (exc_str,fname,line))

But I also want to output the line itself, not only its number.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


several issues with pyinstaller on Windows 10

2021-11-18 Thread Ulli Horlacher
On Windows 10 I have installed:

P:\W10>python --version
Python 3.10.0

P:\W10>pyinstaller --version
4.7

I can compile a VERY simple Python program:

P:\W10>type argv.pv
#!/usr/bin/python3

import sys

for a in sys.argv: print("["+a+"]")


P:\W10>pyinstaller.exe --onefile tcpbm.py

But I can run it only once:

P:\W10\dist>argv a b
[dist\argv]
[a]
[b]

P:\W10\dist>argv a b
The process cannot access the file because it is being used by another process.

P:\W10\dist>argv 1 2 zzz
The process cannot access the file because it is being used by another process.


Compiling a little more complex program (with net IO) fails:

P:\W10>pyinstaller.exe --onefile tcpbm.py
140 INFO: PyInstaller: 4.7
140 INFO: Python: 3.10.0
171 INFO: Platform: Windows-10-10.0.19041-SP0
171 INFO: wrote P:\W10\tcpbm.spec
171 INFO: UPX is not available.
203 INFO: Extending PYTHONPATH with paths
['P:\\W10']
531 INFO: checking Analysis
547 INFO: Building Analysis because Analysis-00.toc is non existent
547 INFO: Initializing module dependency graph...
562 INFO: Caching module graph hooks...
593 INFO: Analyzing base_library.zip ...
4656 INFO: Processing pre-find module path hook distutils from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
4656 INFO: distutils: retargeting to non-venv dir 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib'
5781 INFO: Caching module dependency graph...
6031 INFO: running Analysis Analysis-00.toc
6031 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of 
final executable
  required by C:\Users\admin\AppData\Local\Programs\Python\Python310\python.exe
6187 INFO: Analyzing P:\W10\tcpbm.py
6250 INFO: Processing module hooks...
6250 INFO: Loading module hook 'hook-difflib.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-distutils.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-distutils.util.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-encodings.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6390 INFO: Loading module hook 'hook-heapq.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6390 INFO: Loading module hook 'hook-lib2to3.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-multiprocessing.util.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-pickle.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-sysconfig.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6500 INFO: Loading module hook 'hook-xml.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6546 INFO: Loading module hook 'hook-_tkinter.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6734 INFO: checking Tree
6734 INFO: Building Tree because Tree-00.toc is non existent
6749 INFO: Building Tree Tree-00.toc
6890 INFO: checking Tree
6890 INFO: Building Tree because Tree-01.toc is non existent
6890 INFO: Building Tree Tree-01.toc
7031 INFO: checking Tree
7031 INFO: Building Tree because Tree-02.toc is non existent
7031 INFO: Building Tree Tree-02.toc
7062 INFO: Looking for ctypes DLLs
7078 INFO: Analyzing run-time hooks ...
7093 INFO: Including run-time hook 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
7093 INFO: Including run-time hook 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
7109 INFO: Including run-time hook 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
7109 INFO: Looking for dynamic libraries
7546 INFO: Looking for eggs
7546 INFO: Using Python library
C:\Users\admin\AppData\Local\Programs\Python\Python310\python310.dll
7562 INFO: Found binding redirects:
[]
7562 INFO: Warnings written to P:\W10\build\tcpbm\warn-tcpbm.txt
76

Linux/Windows GUI programming: tk or wx?

2017-08-04 Thread Ulli Horlacher
I have to transfer a python 2.7 CLI programm into one with a (simple) GUI.
The program must run on Linux and Windows and must be compilable with
pyinstall, because I have to ship a standalone windows.exe
Any kind of installer is not acceptable.

Reading https://github.com/pyinstaller/pyinstaller/wiki/Supported-Packages
supported GUI packages are PyGTK, PyQt4, PyQt5, wxPython
I have tested tkinter by myself and it works, too.
I do not like GTK and Qt, because they are too complex.

I want to do VERY simple things and I prefer a simple GUI toolkit :-)

Is there a recommendation for using tk or wx?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


advanced SimpleHTTPServer?

2016-11-02 Thread Ulli Horlacher
"python -m SimpleHTTPServer" is really cool :-)

But I need some more features:

- some kind of a chroot, to prevent file access higher then the base
  directory

- a directory listing mit date and size information

- an upload possibility

I could modify /usr/lib/python2.7/SimpleHTTPServer.py by myself, but maybe
someone already has implemented these features?

Use case: users with notebooks in a foreign (WiFi) LAN want to exchange
some files on-the-fly, quick-and-dirty. Using USB sticks is a no-go! :-)


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: manually sorting images?

2016-09-04 Thread Ulli Horlacher
Quivis  wrote:
> On Sun, 04 Sep 2016 21:32:47 +1000, Steve D'Aprano wrote:
> 
> >  What does it mean to sort images visually?
> 
> 1. A directory of images collected over say, five years.
> 
> 2. You want to sort them according to red houses, blue houses, green 
> trees, yellow trees (that's autumn leaves), cats, dogs, children, elderly 
> people, and so on, and rename them using some scheme you invented.
> 
> 3. AFAIK there are no algorithms to do that with any higher degree of 
> certainty, so you have to look through them and sort them manually. 
> Usually using thumbnails.

Exactly.
The purpose is to generate a list for llgal (a HTML gallery creating tool).
llgal makes a good job, but has no GUI for manually sorting.

Geeqie, you mentioned before, does nearly exactly what I want, but it does not
respect the locale when writing the filename collection. 
It always writes UTF8.

Ok, I can convert the filenames later by (python) script using the correct
locale.

The job is now:

call "geekie ."
user creates the collection and saves it
read the collection file (*)
convert the file names according to locale
prefix filenames with number (renaming)
call "llgal ..."

(*) Problem: how do I know which filename the user has choosen for the
 collection?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


manually sorting images?

2016-09-04 Thread Ulli Horlacher
I need to sort images (*.jpg), visually, not by file name.
It looks, there is no standard UNIX tool for this job?

So, I have to write one by myself, using Tkinter.

Are there any high-level widgets which can help me, for example a file
browser with thumbnails?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum TIK 
Universitaet Stuttgart E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30aTel:++49-711-68565868
70569 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-19 Thread Ulli Horlacher
pyotr filipivich  wrote:

> >   Windows (especially 7) search function is highly crippled. There is
> >some command sequence that will open it up to looking at other file types
> >and locations.
> >
> >http://answers.microsoft.com/en-us/windows/forum/windows_7-files/windows-7-search-does-not-find-files-that-it/61b88d5e-7df7-4427-8a2e-82b801a4a746?auth=1
> 
> 
> Thanks.  I've found it "simpler" to just open a command prompt, and
> use DOS.

How can one search for files with DOS?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-18 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> > but simpler still and more reliable to just call QueryValueEx.
> 
> I find it more complicated.

I have now (after long studying docs and examples)::

def get_winreg(key,subkey):
  try:
rkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,key,0,winreg.KEY_READ)
rvalue,rtype = winreg.QueryValueEx(rkey,subkey)
winreg.CloseKey(rkey)
  except WindowsError:
rvalue,rtype = None,None
  return rvalue


def set_winreg(key,subkey,value):
  winreg.CreateKey(winreg.HKEY_CURRENT_USER,key)
  rkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,key,0,winreg.KEY_WRITE)
  winreg.SetValueEx(rkey,subkey,0,winreg.REG_SZ,value)
  winreg.CloseKey(rkey)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-18 Thread Ulli Horlacher
eryk sun  wrote:


> https://hg.python.org/cpython/file/v2.7.11/Tools/scripts/win_add2path.py
> 
> But there are a few issues with this script.

(... lot of flaws ...)

> Here's a new version for Python 2. I generalized the shell-variable
> replacement to a list of well-known folders.

Great script, I will save it for later usage!

But in the meantime I came to another solution:
Instead of modifying PATH systemwide, I modify it only for cmd.exe.

To achieve this, I set the registry key
"HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun"
to "%USERPROFILE%\autorun.cmd" and write in this file:
set PATH=%PATH%;%USERPROFILE%\Desktop

If there was already an old value in
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
it will be saved to %USERPROFILE%\autorun.cmd, too

This autorun.cmd is like .bashrc on UNIX.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-18 Thread Ulli Horlacher
Dennis Lee Bieber  wrote:

> >I have 
> >"Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC
> >v.1500 32 bit (Intel)] on win32"
> >and there is no "win_add2path.py"
> >
> C:\Python_x64\Python27\Tools\scripts\win_add2path.py

Ok, It is here in C:\Python27\Tools\scripts\win_add2path.py
but windows "Search programs and files" was not able to find it.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-17 Thread Ulli Horlacher
eryk sun  wrote:

> >> The AutoRun command (it's a command line, not a script path)
> >
> > A script path is a legal command line, too.
> 
> If the registry value were just a script path, you'd have to modify
> your script to chain to the previous script, if any. Since it's a
> command line you can simply use the & operator to append another
> command.

This is the better way, no question. I will change it.


> Do you really intend for your batch file to be run every time cmd.exe
> is executed, including every time that every program on the machine
> calls the CRT system() function?

Yes. It just extends PATH, it should not do any harm.


> Why don't you just install a shortcut to a batch file that starts a
> command prompt with the extended PATH?

Hmm... how does a user starts this shortcut, when it is not found in PATH?


> system('reg...') won't be able to do that unless you export the key to
> a .reg file and parse the existing AutoRun value. It would be simpler
> to use subprocess.check_output('reg query ...')

I do it this way, already.


> but simpler still and more reliable to just call QueryValueEx.

I find it more complicated.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-17 Thread Ulli Horlacher
eryk sun  wrote:

> > At startup cmd.exe runs a script which is defined by the registry variable
> > AutoRun in "HKCU\Software\Microsoft\Command Processor"
> >
> > I set this variable with:
> >
> >   rc = "HKCU\Software\Microsoft\Command Processor"
> >   ar = "%USERPROFILE%\Desktop\autorun.cmd"
> >   system('reg add "%s" /v AutoRun /d "%s"' % (rc,ar))
> >
> > and write into autorun.cmd:
> >
> > set PATH=%PATH%;%USERPROFILE%\Desktop
> 
> The AutoRun command (it's a command line, not a script path)

A script path is a legal command line, too.


> gets run for every instance of cmd.exe

Yes, this is the intended trick!


> Your batch file needs to set a sentinel variable such as YOUR_APP_AUTORUN
> that, if set, makes the batch file exit without extending PATH if it was
> already done.

Having "%USERPROFILE%\Desktop" twice in PATH is not a problem.


> Also, you can't just overwrite a user's AutoRun command like that. If
> a command currently exists, you have to concatenate your command with
> the existing command using parentheses and the "&" operator, e.g.
> (previous_command) & (your_command).

Good hint, thanks!


> Use winreg for this.

system("reg ...") works for me and is easier :-)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-17 Thread Ulli Horlacher
Thorsten Kampe  wrote:

> By the way: there is a script called `win_add2path.py` in your Python 
> distribution

I have 
"Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC
v.1500 32 bit (Intel)] on win32"
and there is no "win_add2path.py"

But I found another solution:

I need the extended PATH only for cmd.exe: users shall run my program
(a compiled executable) without having to enter the full path.

At startup cmd.exe runs a script which is defined by the registry variable
AutoRun in "HKCU\Software\Microsoft\Command Processor"

I set this variable with:

  rc = "HKCU\Software\Microsoft\Command Processor"
  ar = "%USERPROFILE%\Desktop\autorun.cmd"
  system('reg add "%s" /v AutoRun /d "%s"' % (rc,ar))

and write into autorun.cmd:

set PATH=%PATH%;%USERPROFILE%\Desktop


This command extends PATH only for this cmd.exe instance.
This is all I need!


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-16 Thread Ulli Horlacher
Thorsten Kampe  wrote:
> * Ulli Horlacher (Tue, 16 Feb 2016 08:30:59 + (UTC))
> > I need to extend the PATH environment variable on Windows.
> 
> 1. Add the path component yourself into HKEY_CURRENT_USER and make 
> sure it's not there already (pure Python).

Preferred!
What is HKEY_CURRENT_USER? Another environment variable?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


extending PATH on Windows?

2016-02-16 Thread Ulli Horlacher
I need to extend the PATH environment variable on Windows.

So far, I use:

   system('setx PATH "%PATH%;'+bindir+'"')

The problem: In a new process (cmd.exe) PATH contains a lot of double
elements. As far as I have understood, Windows builds the PATH
environment variable from a system component and a user component. With
the setx command from above I have copied the system PATH into the user
PATH component.

Is there a better way to extend the PATH environment variable for the user?
It must be persistent, not only for the current process.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: modifying a standard module?

2016-02-12 Thread Ulli Horlacher
Matt Wheeler  wrote:

> > How can I substitute the standard module function tarfile.extractall() with
> > my own function?
> 
> import tarfile
> def new_extractall(self, *args, **kwargs):
> print("I am a function. Woohoo!")
> 
> tarfile.TarFile.extractall = new_extractall

This is more easy than I could imagined :-)
It is in my Python notes, now.


> But bear in mind that that will change tarfile.extractall for every
> single module that imports it within the same python process. Is that
> really what you want?

Yes. I have no own modules. Just one program file.


> Is there a reason you can't subclass TarFile as others have suggested?

The reason: I have no ideas on classes :-}

Of course, I should have to learn about, but until now it was not necessary.
The other solutions in this thread are sufficent for me.

Meanwhile I have implemented the iterator function:

taro.extractall(members=itar(taro),path=edir)

def itar(tar):
  for ti in tar:
# minimal protection against dangerous file names
# see http://bugs.python.org/issue21109#msg215656
ti.name = subst(r'^(?i)([a-z]:)?(\.\.)?[/\\]','',ti.name)
print('untar "%s"' % ti.name)
yield ti


Perfekt solution for me :-)
Thanks to all.


> If you must patch the standard library tarfile module then I would
> suggest patching it to have an extra, default False, argument to
> enable your printing behaviour, so you don't risk messing up anyone
> else's use of it.

Yes, a good idea.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile : secure extract?

2016-02-12 Thread Ulli Horlacher
Random832  wrote:
> On Thu, Feb 11, 2016, at 18:24, Ulli Horlacher wrote:
> > A better approach would be to rename such files while extracting.
> > Is this possible?
> 
> What happens if you change member.name before extracting?

Ohh... such an easy solution! :-)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile : read from a socket?

2016-02-12 Thread Ulli Horlacher
Lars Gustäbel  wrote:
> On Fri, Feb 12, 2016 at 09:35:40AM +0100, Antoon Pardon wrote:
> > On 02/11/2016 06:27 PM, Lars Gustäbel wrote:
> > > What about using an iterator?
> > >
> > > def myiter(tar):
> > > for t in tar:
> > > print "extracting", t.name
> > > yield t
> > >
> > > sfo = sock.makefile('r')
> > > taro = tarfile.open(fileobj=sfo,mode='r|')
> > > taro.extractall(members=myiter(taro),path=edir)
> > >
> > The tarfile is already an iterator. Just do the following: for ti in
> > taro: print "extracting", ti.name taro.extract(ti)
> 
> The extractall() method does a little bit more than just extract(), i.e.
> setting directory mtimes, see
> https://docs.python.org/3.5/library/tarfile.html#tarfile.TarFile.extractall

This is an important hint!
Thanks!


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


tarfile : secure extract?

2016-02-11 Thread Ulli Horlacher
In https://docs.python.org/2/library/tarfile.html there is a warning:

  Never extract archives from untrusted sources without prior inspection.
  It is possible that files are created outside of path, e.g. members that
  have absolute filenames starting with "/" or filenames with two dots
  "..". 


My program has to extract tar archives from untrusted sources :-}

So far, I ignore files with dangerous pathnames:

  for member in taro.getmembers():
file = member.name
if match(r'^(?i)([a-z]:)?(\.\.)?[/\\]',file):
  print('ignoring "%s"' % file)
else:
  print('extracting "%s"' % file)
  taro.extract(member)


A better approach would be to rename such files while extracting.
Is this possible?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


modifying a standard module? (was: Re: tarfile : read from a socket?)

2016-02-11 Thread Ulli Horlacher

Ulli Horlacher  wrote:

> This code works so far:
> 
>   sfo = sock.makefile('r')
>   taro = tarfile.open(fileobj=sfo,mode='r|')
>   taro.extractall(path=edir)
> 
> But it does not writes anything to the terminal to inform the user.
> 
> When I use:
> 
>   for member in taro.getmembers():
>   print('extracting "%s"' % member.name)
>   taro.extract(member)
> 
> I get the error:
> 
>   File "/usr/lib/python2.7/tarfile.py", line 556, in seek
> raise StreamError("seeking backwards is not allowed")
> 
> Of course, a stream is not seekable.
> 
> Any ideas?

As a hack, I modified the standard library module tarfile.py:

root@diaspora:/usr/lib/python2.7# vv -d
--- ./.versions/tarfile.py~1~   2015-06-22 21:59:27.0 +0200
+++ tarfile.py  2016-02-11 18:01:50.18952 +0100
@@ -2045,6 +2045,7 @@
 directories.append(tarinfo)
 tarinfo = copy.copy(tarinfo)
 tarinfo.mode = 0700
+print('untar "%s"' % tarinfo.name)
 self.extract(tarinfo, path)
 
 # Reverse sort directories.


This gives me exact the output I want :-)

BUT I want to distribute my program and all others will not see the tar
extracting information.

Now my question:

How can I substitute the standard module function tarfile.extractall() with
my own function?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> With 
> 
>   taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w|')
> 
> I get no more error.

Of course, this is the writing client.

Now I have a small problem with the reading client.

This code works so far:

  sfo = sock.makefile('r')
  taro = tarfile.open(fileobj=sfo,mode='r|')
  taro.extractall(path=edir)

But it does not writes anything to the terminal to inform the user.

When I use:

  for member in taro.getmembers():
  print('extracting "%s"' % member.name)
  taro.extract(member)

I get the error:

  File "/usr/lib/python2.7/tarfile.py", line 556, in seek
raise StreamError("seeking backwards is not allowed")

Of course, a stream is not seekable.

Any ideas?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
Chris Angelico  wrote:

> Sounds like tarfile needs a seekable file. How big is this file you're
> reading?

No limits. It can be many TBs...

The use case is:

http://fex.rus.uni-stuttgart.de:8080/


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> I have:
> 
>   sock = socket.create_connection((server,port))
>   bs = kB64
>   taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
>   
>   
> 
> Traceback (most recent call last):
>   (...)
>   File "./fexit.py", line 1838, in sex_send
> taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
>   File "/usr/lib/python2.7/tarfile.py", line 1695, in open
> return cls.taropen(name, mode, fileobj, **kwargs)
>   File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
> return cls(name, mode, fileobj, **kwargs)
>   File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
> self.offset = self.fileobj.tell()
> AttributeError: '_fileobject' object has no attribute 'tell'

Reading the doc helps :-)

https://docs.python.org/2/library/tarfile.html

  For special purposes, there is a second format for mode:
  'filemode|[compression]'. tarfile.open() will return a TarFile object
  that processes its data as a stream of blocks.

With 

  taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w|')

I get no more error.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
Antoon Pardon  wrote:

> > (How) can I read a tar file from a (tcp) socket?
> > I do not have a pathname but a socket object from socket.create_connection
> 
> # First you construct a file object with makefile.
> 
> fo = socket.makefile()
> 
> # Then you use the fileobj argument with tarfile.open.
> 
> tarfile.open(mode='r', fileobj = fo)


I have:

  sock = socket.create_connection((server,port))
  bs = kB64
  taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
  
  

Traceback (most recent call last):
  (...)
  File "./fexit.py", line 1838, in sex_send
taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
  File "/usr/lib/python2.7/tarfile.py", line 1695, in open
return cls.taropen(name, mode, fileobj, **kwargs)
  File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
return cls(name, mode, fileobj, **kwargs)
  File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
self.offset = self.fileobj.tell()
AttributeError: '_fileobject' object has no attribute 'tell'

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
https://docs.python.org/2/library/tarfile.html says:

 tarfile.open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)

Return a TarFile object for the pathname name.


(How) can I read a tar file from a (tcp) socket?
I do not have a pathname but a socket object from socket.create_connection() 



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Ulli Horlacher
James Harris  wrote:

> I nearly gave up with Python at the very beginning before I realised not 
> to mix tabs and spaces.

I nearly gave up with Python at the very beginning before I realised that
OO-programming is optional in Python! :-)

Most tutorials I found so far makes OO mandatory.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psss...I want to move from Perl to Python

2016-01-29 Thread Ulli Horlacher
Steven D'Aprano  wrote:

> Every time I make a half-hearted attempt to learn enough Perl syntax to get
> started, I keep running into the differences between $foo, %foo and @foo
> and dire warnings about what happens if you use the wrong sigil

I have started learning Python several times and surrendered because my
brain was too Perl hardcoded after 30 years, but NOW I was successful :-)
(I still find Perl syntax better...)

About the variables in short:

$foo is a scalar (number, string, reference, file handle)
@foo is an array
%foo is a hash (dictionary in Python slang)

and yes, you can use them all together in same code, they are different.

For more discussion about Perl syntax one should better go to
comp.lang.perl

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT The fiction section

2016-01-17 Thread Ulli Horlacher
Marko Rauhamaa  wrote:
> Steven D'Aprano :
> 
> > https://pbs.twimg.com/media/CWgV0ruUsAAcUD7.jpg
> 
> Not bad.

$ python
Python 2.7.3 (default, Jun 22 2015, 19:33:41) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> bad=False
>>> not bad
True


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "x == None" vs "x is None"

2016-01-17 Thread Ulli Horlacher
Chris Angelico  wrote:
> On Sun, Jan 17, 2016 at 8:51 PM, Ulli Horlacher
>  wrote:
> > I have seen at several places "x == None" and "x is None" within
> > if-statements.
> > What is the difference?
> > Which term should I prefer and why?
> 
> tl;dr: Prefer "x is None" as a check.

And for the negation?
"if not x is None" or "if x is not None"

I have seen the last one several times, but i do not understand it, because:

>>> x=0
>>> x is not None
True
>>> not None
True
>>> x is True
False


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


"x == None" vs "x is None"

2016-01-17 Thread Ulli Horlacher
I have seen at several places "x == None" and "x is None" within
if-statements.
What is the difference? 
Which term should I prefer and why?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getkey

2016-01-16 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> The first byte of an escape sequence (example: ^[[21~ for F10) is
> recognized, but the trailing bytes then are not discarded by
> clear_keyboard_buffer() and get_key() returns the second byte of the
> escape sequence.

I have found a solution:

def clear_keyboard_buffer():
  try:
while msvcrt.kbhit(): msvcrt.getwch()
  except:
fd = sys.stdin.fileno()
fcntl_flags = fcntl.fcntl(fd,fcntl.F_GETFL)
fcntl.fcntl(fd,fcntl.F_SETFL,fcntl_flags|os.O_NONBLOCK)
try:
  while sys.stdin.read(1): pass
except:
  pass
fcntl.fcntl(fd,fcntl.F_SETFL,fcntl_flags)


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


getkey

2016-01-16 Thread Ulli Horlacher
I have an application which runs on Windows and UNIX where I need to get
one keypress from the user (without ENTER). 
Keys which sends escape sequences (e.g. cursor or function keys) should be
ignored. 

I have a solution for Windows, but not for UNIX:
The first byte of an escape sequence (example: ^[[21~ for F10) is
recognized, but the trailing bytes then are not discarded by
clear_keyboard_buffer() and get_key() returns the second byte of the
escape sequence.

My code:

try:
  import msvcrt
except ImportError:
  import tty
  import select
  import termios


def get_key():
  try:
k = msvcrt.getch()
  except:
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
  tty.setraw(fd)
  k = sys.stdin.read(1)
finally:
  termios.tcsetattr(fd,termios.TCSADRAIN,old_settings)

  if k == '\033': 
clear_keyboard_buffer()
return get_key()
  else:
return k


def clear_keyboard_buffer():
  try:
while msvcrt.kbhit(): msvcrt.getwch()
  except:
fd = sys.stdin.fileno()
while len(select.select([fd],[],[],0.0)[0]) > 0: os.read(fd,1)
termios.tcflush(sys.stdin,termios.TCIOFLUSH)


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Powerful perl paradigm I don't find in python

2016-01-15 Thread Ulli Horlacher
Charles T. Smith  wrote:
> while ($str != $tail) {
> $str ~= s/^(head-pattern)//;
> use ($1);
> }

use() is illegal syntax in Perl.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


looking for windows testers

2016-01-11 Thread Ulli Horlacher
I have written a Python client for F*EX(*). It is designed for Windows
users, though it runs on UNIX, too. I am now looking for testers. If you
are interested, I will give you an account on my server.


(*) Frams' Fast File EXchange is a service to send files of any size to
any user anywhere in the internet: 
http://fex.rus.uni-stuttgart.de:8080/index.html

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When I need classes?

2016-01-10 Thread Ulli Horlacher
Cameron Simpson  wrote:

> I always structure this aspect as:
> 
>  ... at or near top of script ...
> 
>  def main(argv):
>... do main logic here ...
> 
>  ... at bottom ...
>  if __name__ == '__main__':
>sys.exit(main(sys.argv))

I, as a Python beginner, came to the same solution!
It seems, it was a good idea :-)


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extract script from executable made by pyinstaller?

2016-01-08 Thread Ulli Horlacher
Oscar Benjamin  wrote:
> On 8 January 2016 at 07:44, Ulli Horlacher
>  wrote:
> > Is it possible to extract (and view) the Python script from the Windows
> > executable which was made by pyinstller?
> 
> I may be misremembering but I though that pyinstaller actually stores
> the main script uncompressed so that it's just in the raw .exe.

No. I tested it already with "strings".


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


extract script from executable made by pyinstaller?

2016-01-07 Thread Ulli Horlacher
Is it possible to extract (and view) the Python script from the Windows
executable which was made by pyinstller?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tk alternative to askopenfilename and askdirectory?

2015-12-18 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> Tk calls out into the native file manager to perform the file/open 
> operation (on Win&Mac, on Unix it brings it's own).

This means, on Windows the user gets a "well known" file/directory browser?
Then this is an important feature!
Anything new and unknown is bad for a standard Windows user. 


> scratch, however - Schelte Bron has created a very nice dialog as a 
> replacement for the (oldfashioned, dull) standard dialog in Tk:
> 
>http://wiki.tcl.tk/15897
> 
> It would be feasible to tweak it a bit to allow for directory and file 
> selection. It is written in Tcl

Oh boy, last time, I hacked with Tcl was in 1993 :-}
I remember Tcl as a horrible programming language.


> Concerning your drag&drop problem, it is only possible if you go for a 
> Tk main window, then you could use TkDND. It is not in the standard 
> install, but it can be bundled *without installation*, because Tcl 
> extensions use a mechanism called stubs, which ensures broad binary 
> compatibility. The only drawback: you will not have a single .py file, 
> but since on Windows you deliver using pyinstaller, that should not be 
> an issue.

Ok, I put it on my TODO-List :-)
IF I have some day some spare time...

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tk alternative to askopenfilename and askdirectory?

2015-12-17 Thread Ulli Horlacher
Rick Johnson  wrote:

> Oh i understand. What you opine for is something like: askOpenFileOrDir()
> -- which displays a dialog from which a file or directory can be selected
> by the user. 

Yes, exactly!
Now: how?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How does one distribute Tkinter or Qt GUI apps Developed in Python

2015-12-17 Thread Ulli Horlacher
Rick Johnson  wrote:

> Unlike a true "applications language", like say, um, *JAVA*, one cannot
> simply compile an executable and distribute it in a teeny tiny binary
> form, no, with Python

Of course you can!
If have done this with pyinstaller. This creates a standalone Windows
executable you can distribute.
Example:
http://fex.rus.uni-stuttgart.de:8080/fexit.html




-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tk alternative to askopenfilename and askdirectory?

2015-12-16 Thread Ulli Horlacher
Lorenzo Sutton  wrote:

> On 16/12/2015 14:18, Ulli Horlacher wrote:
> > Is there an alternative to Tk's askopenfilename() and askdirectory()?
> >
> > I want to select a files and directories within one widget, but
> > askopenfilename() let me only select files and askdirectory() let me only
> > select directories.
> >
> >
> 
> I guess it would help if you could provide some information on your use 
> case and what you want to achieve ;)

A (Windows) user shall upload files and/or directories.
For this, he needs to select them.
In the current implementation, the user has to decide first whether he
wants to upload a file or a directory. I want to eliminate this step.

http://fex.rus.uni-stuttgart.de/fop/rC2meOrd/X-20151216180501.png

drag&drop works only for files with ASCII filenames.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Tk alternative to askopenfilename and askdirectory?

2015-12-16 Thread Ulli Horlacher
Is there an alternative to Tk's askopenfilename() and askdirectory()?

I want to select a files and directories within one widget, but
askopenfilename() let me only select files and askdirectory() let me only
select directories.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess.call with non-ASCII arguments?

2015-12-16 Thread Ulli Horlacher
Dennis Lee Bieber  wrote:

> >I want to create a zip file within a Python 2.7 program on windows.
> >
> >My code:
> >
> >  cmd = ['7za.exe','a','-tzip',archive] + files
> >  status = subprocess.call(cmd)
> >
> My first thought would be...
> 
> WHY spawn an OS dependent subprocess...
> 
> Python has a zipfile library that is portable between OS. Along with
> libraries for gzip, bzip2, and tarfiles...

Great hint!

With the python modules zipfile and tarfile I have no more problems with
non-ASCII filenames! It needed a little bit more programming with
os.walk(), because zipfile cannot add directories recursivly.

S:\>python fexit.py * framstag
Container name: test
creating C:\Users\admin\AppData\Local\Temp\fex\test.zip
zip dist\fexit.exe
zip mf.cmd
zip fex.ico
zip fexit.spec
zip build\fexit\fexit.exe.manifest
zip build\fexit\out00-Analysis.toc
zip build\fexit\out00-EXE.toc
zip build\fexit\out00-PKG.pkg
zip build\fexit\out00-PKG.toc
zip build\fexit\out00-PYZ.pyz
zip build\fexit\out00-PYZ.toc
zip build\fexit\out00-Tree.toc
zip build\fexit\out01-Tree.toc
zip build\fexit\warnfexit.txt
zip fexit.py
zip tar.py
zip zip.py

Recipient: frams...@rus.uni-stuttgart.de
test.zip: 13 MB of 13 MB (100%) 28540 kB/s

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess.call with non-ASCII arguments?

2015-12-15 Thread Ulli Horlacher
Dennis Lee Bieber  wrote:

> Python has a zipfile library that is portable between OS. Along with
> libraries for gzip, bzip2, and tarfiles...

Ohh.. this is new to me!

https://docs.python.org/2/library/tarfile.html
https://docs.python.org/2/library/zipfile.html

What is missing in the documentation:
Is the tar/zip file generation done in memory or will it be written
directly to disk?

My program creates zip or tar files up to TB size. This cannot be done in
memory.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cannot open file with non-ASCII filename

2015-12-15 Thread Ulli Horlacher
eryk sun  wrote:

> pyreadline looked promising for its extensive ctypes implementation of
> the Windows console API [1], wrapped by high-level methods such as
> peek, getchar, and getkeypress. It turns out it ignores the event
> sequences you need for alt+numpad input (used when a file is dragged
> into the console). You'd have to modify its console and keysyms
> modules to make it work. It would be a useful enhancement, so probably
> your patches would be accepted upstream.

Ehhh... I started Python programming some weeks ago and I know nearly
nothing about Windows. I am a UNIX and VMS guy :-)

I am far away from delivering patches for Windows system programming.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess.call with non-ASCII arguments?

2015-12-15 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> Instead of calling a 7z subprocess with non-ASCII arguments I tried to
> call it with a listfile: it starts with a "@" and contains the names of
> the files to be packed into the arcive. It is a special 7z feature.
> 
> New code:
> 
>   fileslist = archive + '.list'
>   flo = open(fileslist,'w')
>   for file in files: print(file,file=flo)
>   flo.close()
>   cmd = ['7za.exe','a','-tzip',archive,'@'+fileslist]
>   status = subprocess.call(cmd)
> 
> 
> But with that I get a new error:
> 
>   File "fexit.py", line 959, in sendfile_retry
> for file in files: print(file,file=flo)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 
> 8:
>   ordinal not in range(128)

I found a partial solution:

for file in files: print(file.encode('utf8'),file=flo)

But this works only for files I get from Tk askopenfilename(), not for
files from sys.argv[]
Then I see:

S:\>python fexit.py -a x.zip C:\Users\admin\_XöX.exe .
files selected:

"C:\Users\admin\_X÷X.exe"
2015-12-07 16:17:15
114 kB

Traceback (most recent call last):
  File "fexit.py", line 2166, in 
wexit(main())
  File "fexit.py", line 260, in main
status = sendfile_retry(files,recipient,comment)
  File "fexit.py", line 959, in sendfile_retry
for file in files: print(file.encode('utf8'),file=flo)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 17:
 ordinal not in range(128)


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


subprocess.call with non-ASCII arguments?

2015-12-15 Thread Ulli Horlacher
(My first posting seems to got lost)

I want to create a zip file within a Python 2.7 program on windows.

My code:

  cmd = ['7za.exe','a','-tzip',archive] + files
  status = subprocess.call(cmd)

leads to:

  File "fexit.py", line 971, in sendfile_retry
status = subprocess.call(cmd)
  File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 87:
 ordinal not in range(128)


This is because the array "files" contains filenames with non-ASCII
characters.

So, the problem is in subprocess.py, which I cannot modify.


Instead of calling a 7z subprocess with non-ASCII arguments I tried to
call it with a listfile: it starts with a "@" and contains the names of
the files to be packed into the arcive. It is a special 7z feature.

New code:

  fileslist = archive + '.list'
  flo = open(fileslist,'w')
  for file in files: print(file,file=flo)
  flo.close()
  cmd = ['7za.exe','a','-tzip',archive,'@'+fileslist]
  status = subprocess.call(cmd)


But with that I get a new error:

  File "fexit.py", line 959, in sendfile_retry
for file in files: print(file,file=flo)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 8:
  ordinal not in range(128)


I get the same error message, when i use:
  flo = open(fileslist,'wb')
  

How can I tell open() or print() that I want to write non-ASCII ?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


subprocess.call with non-ASCII arguments?

2015-12-15 Thread Ulli Horlacher
I want to create a zip file within a Python 2.7 program on windows.

My code:

  cmd = ['7za.exe','a','-tzip',archive] + files
  status = subprocess.call(cmd)

leads to:

  File "fexit.py", line 971, in sendfile_retry
status = subprocess.call(cmd)
  File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 87:
 ordinal not in range(128)


This is because the array "files" contains filenames with non-ASCII
characters.

So, the problem is in subprocess.py, which I cannot modify.

What can I do?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cannot open file with non-ASCII filename

2015-12-15 Thread Ulli Horlacher
Laura Creighton  wrote:

> PyPy wrote its own pyreadline.
> You can get it here. https://bitbucket.org/pypy/pyrepl

As far as I can see, it has no getkey function.
My users do not hit ENTER after drag&drop or copy&paste files.
I need an input function with a timeout.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cannot open file with non-ASCII filename

2015-12-14 Thread Ulli Horlacher
Laura Creighton  wrote:

> Given that Ulli is in Germany, latin-1 is likely to work fine for him. 

For me, but not for my users. We have people from about 100 nations at our
university. 


> And you do it like this:
> 
> # -*- coding: latin-1 -*-
> from Tkinter import *
> root = Tk()
> s = 'Välkommen till Göteborg'  # Welcome to Gothenburg (where I live)
> u = unicode(s, 'iso8859-1')
> Label(root, text=u).pack()

The problem is the input of these filenames.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


cannot open file with non-ASCII filename

2015-12-14 Thread Ulli Horlacher
With Python 2.7.11 on Windows 7 my users cannot open/read files with
non-ASCII filenames. They use the Windows explorer to drag&drop files into
a console window running the Python program.
os.path.exists() does not detect such a file and an open() fails, too.

My code:


  print("\nDrag&drop files or directories into this window.")
  system('explorer "%s"' % HOME)
  file = get_paste()
  if not(os.path.exists(file)): die('"%s" does not exist' % file)


def get_paste():
  import msvcrt
  while True:
c = msvcrt.getch()
if c == '\t': return ''
if c == '\003' or c == '\004': return None
if not (c == '\n' or c == '\r'): break
  paste = c
  while msvcrt.kbhit():
c = msvcrt.getch()
if c == '\n' or c == '\r': break
paste += c
  if match(r'\s',paste): paste = subst('^"(.+)"$',r'\1',paste)
  return paste


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


pyinstaller ignores icon

2015-12-14 Thread Ulli Horlacher
pyinstaller ignores a specified icon file: the resulting executable shows
the default icon on the desktop.

I compile with:

S:\python>pyinstaller.exe --onefile --icon=fex.ico fexit.py
31 INFO: PyInstaller: 3.0
31 INFO: Python: 2.7.11
31 INFO: Platform: Windows-7-6.1.7601-SP1
31 INFO: wrote S:\python\fexit.spec
47 INFO: UPX is not available.
47 INFO: Extending PYTHONPATH with S:\python
47 INFO: checking Analysis
920 INFO: checking PYZ
1014 INFO: checking PKG
1092 INFO: Building because S:\python\build\fexit\fexit.exe.manifest changed
1092 INFO: Building PKG (CArchive) out00-PKG.pkg
1497 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 
30729, 4940)
5366 INFO: Bootloader 
c:\python27\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
5366 INFO: checking EXE
5444 INFO: Building because out00-EXE.toc is bad
5475 INFO: Building EXE from out00-EXE.toc
5522 INFO: SRCPATH [('fex.ico', None)]
5522 INFO: Updating icons from ['fex.ico'] to 
c:\users\admin\appdata\local\temp\tmpoingb4
5522 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
5522 INFO: Writing RT_ICON 1 resource with 18488 bytes
5538 INFO: Appending archive to EXE S:\python\dist\fexit.exe


http://fex.rus.uni-stuttgart.de/fop/SsmdcBLk/X-20151214111803.png

Where is the error?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-12-10 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> My idea now is: instead of raw_input() I use a get_paste() function, which
> reads input character for input character and after a (say) 1 s timeout it
> returns the string. Pasting a string with the mouse is rather fast, there
> should be no big delay between the characters.
> 
> How can I implement such a get_paste() function?
> I need a non-blocking getkey() function.

I found a solution for Windows:

  print("\nCopy&paste a filename or drag&drop a file into this window")
  file = get_paste()
  print('\n"%s"' % file)


def get_paste():
  import msvcrt
  c = msvcrt.getch()
  if c == '\n' or c == '\r': return ''
  paste = c
  while msvcrt.kbhit():
c = msvcrt.getch()
if c == '\n' or c == '\r': break
paste += c
  return paste

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-12-10 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> Another cheap solution comes to mind: On windows, dropping files onto an 
> icon on the desktop is interpreted as "launch the program with 
> additional arguments", where the arguments are the file names.

Ohhh... great! This helps me a lot!


> Maybe you could try interpreting the cmdline args first?

I have implemented this since the beginning of the project :-)


> I'm not so sure how it will work with non-ASCII characters, 

My users have to test it. I do not have non-ASCII filenames.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-12-10 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> > My users do not like it :-(
> > They want to drag&drop files.
> > Therefore I have added it as another option to enter files:
> >
> >   [f] select a file
> >   [d] select a directory
> >   [e] enter a file or directory (with drag&drop or copy&paste)
> 
> 
> Well I know that you won't take my advice but.
> 
> There are standard protocols for drag'n'drop of files and folders on all 
> three major platforms. Tk supports this using the optional TkDND module, 
> which unfortunately isn't installed with a standard Python distribution. 

Then this is no-go.
My users cannot install any additional software.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-12-10 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> > But... is there a windows program with which one can select files and the
> > result is written to STDOUT?
> 
> Found it:
> 
> from Tkinter import Tk
> from tkFileDialog import askopenfilename
> 
> Tk().withdraw()
> file = askopenfilename()

My users do not like it :-(
They want to drag&drop files.
Therefore I have added it as another option to enter files:

[f] select a file
[d] select a directory
[e] enter a file or directory (with drag&drop or copy&paste)

With [f] starts askopenfilename and [d] starts askdirectory

The problem with [e] is: my users do not press ENTER after pasting.

My idea now is: instead of raw_input() I use a get_paste() function, which
reads input character for input character and after a (say) 1 s timeout it
returns the string. Pasting a string with the mouse is rather fast, there
should be no big delay between the characters.

How can I implement such a get_paste() function?
I need a non-blocking getkey() function.

It must work on Windows and Linux.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: urllib2.urlopen() crashes on Windows 2008 Server

2015-12-06 Thread Ulli Horlacher
Dennis Lee Bieber  wrote:

> >> Connection reset by peer.
> >> 
> >> An existing connection was forcibly closed by the remote host. 
> >
> >This is not true.
> >The server is under my control. Die client has terminated the connection
> >(or a router between).

> The odds are still good that something on the server is configured to
> not make a clean shutdown of TCP connections (a router should not be
> involved as the TCP connection is from client IP to server IP, regardless
> of intervening MAC Ethernet routing). The RST is coming from the server.

No.
The server does not reset the connection.
It is the router/firewall.


> >How can I trap this within the python program?
> >I see no exception.
> 
> It's a socket error
> 
> https://docs.python.org/2/library/socket.html
> """
> 
> exception socket.error

Ok, I have now:

   try:
 req = urllib.Request(szurl)
 req.add_header('User-Agent',useragent)
 u = urllib.urlopen(req)
   except urllib.URLError as e:
 die('cannot get %s - %s' % (szurl,e.reason))
   except urllib.HTTPError as e:
 die('cannot get %s - server reply: %d %s' % (szurl,e.code,e.reason))
   except (IOError,httplib.BadStatusLine,httplib.HTTPException):
 die('cannot get %s - connection reset by router or firewall' % szurl)
   except socket.error as msg:
 die('cannot get %s - %s' % (szurl,msg))


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: urllib2.urlopen() crashes on Windows 2008 Server

2015-12-04 Thread Ulli Horlacher
Dennis Lee Bieber  wrote:

> >I have a Python2 program which runs fine on Windows 7, but
> >crashes on Windows 2008 Server R2 64 bit:
> >
> >downloading http://fex.belwue.de/download/7za.exe
> >Traceback (most recent call last):
> >  File "", line 1992, in 
> >  File "", line 180, in main
> >  File "", line 329, in get_ID
> >  File "", line 1627, in check_7z
> >  File "C:\Software\Python\lib\urllib2.py", line 154, in urlopen
> >  File "C:\Software\Python\lib\urllib2.py", line 431, in open
> >  File "C:\Software\Python\lib\urllib2.py", line 449, in _open
> >  File "C:\Software\Python\lib\urllib2.py", line 409, in _call_chain
> >  File "C:\Software\Python\lib\urllib2.py", line 1227, in http_open
> >  File "C:\Software\Python\lib\urllib2.py", line 1200, in do_open
> >  File "C:\Software\Python\lib\httplib.py", line 1132, in getresponse
> >  File "C:\Software\Python\lib\httplib.py", line 485, in begin
> >  File "C:\Software\Python\lib\mimetools.py", line 25, in __init__
> >  File "C:\Software\Python\lib\rfc822.py", line 108, in __init__
> >  File "C:\Software\Python\lib\httplib.py", line 319, in readheaders
> >  File "C:\Software\Python\lib\socket.py", line 480, in readline
> >error: [Errno 10054] Eine vorhandene Verbindung wurde vom Remotehost 
> >geschlossen
> >
> 
> Per MSDN:
> """
> WSAECONNRESET
> 10054
> 
> 
> 
> Connection reset by peer.
> 
> An existing connection was forcibly closed by the remote host. 

This is not true.
The server is under my control. Die client has terminated the connection
(or a router between).


How can I trap this within the python program?
I see no exception.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


urllib2.urlopen() crashes on Windows 2008 Server

2015-12-03 Thread Ulli Horlacher
I have a Python2 program which runs fine on Windows 7, but
crashes on Windows 2008 Server R2 64 bit:

downloading http://fex.belwue.de/download/7za.exe
Traceback (most recent call last):
  File "", line 1992, in 
  File "", line 180, in main
  File "", line 329, in get_ID
  File "", line 1627, in check_7z
  File "C:\Software\Python\lib\urllib2.py", line 154, in urlopen
  File "C:\Software\Python\lib\urllib2.py", line 431, in open
  File "C:\Software\Python\lib\urllib2.py", line 449, in _open
  File "C:\Software\Python\lib\urllib2.py", line 409, in _call_chain
  File "C:\Software\Python\lib\urllib2.py", line 1227, in http_open
  File "C:\Software\Python\lib\urllib2.py", line 1200, in do_open
  File "C:\Software\Python\lib\httplib.py", line 1132, in getresponse
  File "C:\Software\Python\lib\httplib.py", line 485, in begin
  File "C:\Software\Python\lib\mimetools.py", line 25, in __init__
  File "C:\Software\Python\lib\rfc822.py", line 108, in __init__
  File "C:\Software\Python\lib\httplib.py", line 319, in readheaders
  File "C:\Software\Python\lib\socket.py", line 480, in readline
error: [Errno 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen

This is the function where the error happens:

if python2: import urllib2 as urllib
if python3: import urllib.request as urllib

def check_7z():
  global sz

  sz = path.join(fexhome,'7za.exe')
  szurl = "http://fex.belwue.de/download/7za.exe";

  if not path.exists(sz) or path.getsize(sz) < :
try:
  szo = open(sz,'wb')
except (IOError,OSError) as e:
  die('cannot write %s - %s' % (sz,e.strerror))
printf("\ndownloading %s\n",szurl)
try:
  req = urllib.Request(szurl)
  req.add_header('User-Agent',useragent)
  u = urllib.urlopen(req) # line 1627 #
except urllib.URLError as e:
  die('cannot get %s - %s' % (szurl,e.reason))
except urllib.HTTPError as e:
  die('cannot get %s - server reply: %d %s' % (szurl,e.code,e.reason))
if u.getcode() == 200:
  copy_file_obj(u,szo)
  szo.close()
else:
  die('cannot get %s - server reply: %d' % (szurl,u.getcode()))


The curious thing is: the download was successful, the file 7za.exe is
there in the local directory!

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: static variables

2015-12-01 Thread Ulli Horlacher
Wolfgang Maier  wrote:

> I'm wondering whether you have a good reason to stick with a function. 

Easy handling, no programming overhead. Clean, orthogonal code.


> What you are trying to achieve seems to be easier and cleaner to 
> implement as a class:
> 
> class Counter (object):
> def __init__ (self, start_value=0):
> self.x = start_value
> 
> def __call__ (self):
> self.x += 1
> 
> 1) solves the renaming problem
> 2) allows you to have several counters around:
> 
> counter1 = Counter()
> counter2 = Counter()
> counter3 = Counter(35)
> counter1()
> counter2()
> counter1()
> print (counter1.x, counter2.x, counter3.x)

Implementing a counter was only an example for a static variable, not the
primary goal.

With a class, I find it irritating the first function call have to be
different than the subsequent ones:


def main():
  a=A(1)
  a(1)
  a(5)
  a(0)
  print(a.n)

class A(object):
  def __init__ (self,*arg):
self.n = 0

  def __call__(self,x):
self.n += 1
print('%d:' % self.n,x)

main()



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: static variables

2015-12-01 Thread Ulli Horlacher
Steven D'Aprano  wrote:

> A better and more general test is:
> 
> if hasattr(a, 'x'): print('attribute of a')

Fine!

I have now:

def a(x=None):
  if not hasattr(a,'x'): a.x = 0
  a.x += 1
  print('%d:' % a.x,x)

This simply counts the calls of a()

But, when I rename the function I have to rename the attribute also.
Is it possible to refer the attribute automatically to its function?
Something like:

def a(x=None):
  if not hasattr(_function_,'x'): _function_.x = 0
  _function_.x += 1
  print('%d:' % _function_.x,x)


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


static variables

2015-11-30 Thread Ulli Horlacher

I try to to implement a "static variable" inside a function:

def main():
  a(1)
  a(2)
  a()
  print(a.x)
  if 'a.x' in globals(): print('global variable')
  if 'a.x' in locals():  print('local variable')

def a(x=None):
  if not x is None: a.x = x
  print(':',a.x)

main()

When I run this code, I get:

: 1
: 2
: 2
2

This is exactly what I expect.
But what is a.x?
It is neither a variable in globals() nor in locals()


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: askopenfilename()

2015-11-28 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> Am 28.11.15 um 13:48 schrieb Ulli Horlacher:
> > Christian Gollwitzer  wrote:
> >> Many problems would simply go away if you wrote the whole thing as a GUI
> >> program.
> >
> > Too much hassle.
> > The predecessor was a Perl/Tk program and I have had to invest 90% of the
> > programming work into the GUI handling. No fun at all.
> 
> As I see it, the program consists only of user interface - or is there 
> any "algorithm" working behinds the scenes?

There is a lot of "algorithms", about 50 kB of code:
- resuming upload and download after link failures
- sending multiple files as zip or tar containers
- deleting files
- configuring login
- handling HTTP proxy
- many other things...


> Maybe you could pass the task on to somebody who enjoys GUI programming?

No, I then have to maintain it. I do not like to support foreign code. I
was in this situation already. The client was written in Java, which I do
not know. I have had to throw it away some day, because I was not able to
fix the bugs.

Therefore I started to write the new client fexit in Python.
Here we are :-)


> > This is only one of the tasks. The main menu looks:
> >
> > [s]  send a file or directory
> > [g]  get a file
> > [c]  change login data (user, server, auth-ID)
> > [l]  login with webbrowser
> > [u]  update fexit
> > [h]  help
> > [q]  quit
> 
> All of this is easily integrated into a GUI like the one I posted (have 
> you tried it?)

As I wrote: I have done this already with Perl/Tk and it was HASSLE.
No fun at all.


> IMO the most common GUI pattern for this kind of thing is a side-by-side
> view of the directories on the server and on the client

There is no directory view on server side.


> For an experienced GUI script writer it'll take a weekend to get the
> basics running.

I am not even a beginner GUI script writer and I do not want to become one.
GUIs are most superfluous and delay the work flow.


> for guided user input, an interface which prompts the user for input has
> never been a good solution. You have to work very hard to make that
> convenient. 

This is easy, because they have no alternative :-)


> Have a look at lftp, for instance. 

Yes. Horrible user interface and even more horrible to program :-}


> A (still) alternative solution would be an interface to the OS to make 
> it a remote mounted folder 

There are no remote folders.


> (works for WebDAV on any modern OS, for instance) or a daemon, which
> watches and synchronizes a directory (this is how Dropbox works).

A VERY bad idea, if you have to send TB files.


> This way it feels much more integrated to the user 

It shall not look integrated. The user should think before using it.


> they can use whatever file manager they like to do the transfer

There are no file manager which supports the F*EX protocol.
Therefore I am forced to write my own clients.
I am a lazy guy: if there is already a program, I will happily use it.
Only if there is none, I program it by myself.


> or even "save" from any application (like Word, Firefox, ...) into the
> remote folder.

There are no remote folders.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: askopenfilename()

2015-11-28 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> One of my Windows test users reports, that the file dialog window of
> askopenfilename() starts behind the console window and has no focus.

I have got a followup: this happens only with Windows XP, not with Windows
7. Therefore I will ignore this problem :-)


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: askopenfilename()

2015-11-28 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> Am 28.11.15 um 11:29 schrieb Ulli Horlacher:
> > One of my Windows test users reports, that the file dialog window of
> > askopenfilename() starts behind the console window and has no focus.
> > On Linux (XFCE) I do not have this problem.
> >
> > I start it with:
> >
> >Tk().withdraw()
> >file = askopenfilename(title='select a file',initialdir=HOME)
> >set_window_focus() # give focus back to console window
> >
> > Can one force askopenfilename() to start in foreground with focus?
> 
> I can't test it right now, but I think it /should/ go into the 
> foreground by itself. 

This is what I think, too :-)
But my test user reports me, it is not so.


> I see two thingd:
> 
> 1) Tk().withdraw()
> 
> - this seems odd to me, because you don't keep a reference to the Tk 
> object around. 

I thought, I need it for Tk initialization.
But true, it is superfluous


> I think that you are curing a lot of symptoms with the focus setting to 
> the console etc.

This is done after the file selection window is closed. This works.


> Many problems would simply go away if you wrote the whole thing as a GUI
> program.

Too much hassle.
The predecessor was a Perl/Tk program and I have had to invest 90% of the 
programming work into the GUI handling. No fun at all.
Now, with fexit in Python, I skipped most of these problems.
The only GUI part is the file selection.


> If I understand correctly, what you want - a program to select files and
> folders to upload to your server 

This is only one of the tasks. The main menu looks:

[s]  send a file or directory
[g]  get a file
[c]  change login data (user, server, auth-ID)
[l]  login with webbrowser
[u]  update fexit
[h]  help
[q]  quit

(with more features to come in the future)

And the CLI:

framstag@juhu:~: ./fexit.py -h
usage: fexit [-C "comment"] [-a container] file(s) recipient[,...]
example: fexit flupp.avi frams...@rus.uni-stuttgart.de
example: fexit -C "more data" -a labdata *.png x...@flupp.org,x...@flupp.org

usage: fexit FEX-download-URL
example: fexit http://fex.rus.uni-stuttgart.de/fop/jHn34yp7/flupp.avi


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


askopenfilename() (was: Re: non-blocking getkey?)

2015-11-28 Thread Ulli Horlacher
Ulli Horlacher  wrote:
> eryksun  wrote:
> > On Thu, Nov 19, 2015 at 10:31 AM, Michael Torrie  wrote:
> > > One windows it might be possible to use the win32 api to enumerate the
> > > windows, find your console window and switch to it.
> > 
> > You can call GetConsoleWindow [1] and then SetForegroundWindow [2].
> (...)
> 
> great, this works! Thanks!

One of my Windows test users reports, that the file dialog window of
askopenfilename() starts behind the console window and has no focus.
On Linux (XFCE) I do not have this problem.

I start it with:

  Tk().withdraw()
  file = askopenfilename(title='select a file',initialdir=HOME)
  set_window_focus() # give focus back to console window

Can one force askopenfilename() to start in foreground with focus?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: fexit: file transfer of ANY size

2015-11-27 Thread Ulli Horlacher
paul.hermeneu...@gmail.com wrote:

> > I am now looking for beta testers. If you are interested, send me a mail.
> 
> Can you tell us a git or svn repository from which the kit is available?

Available via email request.


> Or, is this a proprietary product?

No.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


fexit: file transfer of ANY size

2015-11-26 Thread Ulli Horlacher
In the last weeks I have asked here some beginners questions and got great
response. I was able to solve all my problems.

Now, my first real Python program is ready: fexit, a F*EX client.

And what is F*EX?
==> Frams' Fast File EXchange, a service for transfering files of ANY size
from any user A to any user B in the internet.
For details see: http://fex.rus.uni-stuttgart.de/

I am now looking for beta testers. If you are interested, send me a mail.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: readline and TAB-completion?

2015-11-25 Thread Ulli Horlacher
Peter Otten <__pete...@web.de> wrote:

> > Is there a way to make TAB-completion work for other directories, too?
> 
> Remove "/" from the set of delimiters:
> 
> readline.set_completer_delims(
> "".join(c for c in readline.get_completer_delims() if c != "/"))

Great!


> > murksigkeiten
> 
> I wonder what's in there ;)
 
Fexed to you :-)

 
-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


readline and TAB-completion?

2015-11-24 Thread Ulli Horlacher
I need an input function with GNU readline support. So far I have:

import readline
readline.parse_and_bind("tab: complete")

file = raw_input('File to send: ')


Cursor keys are working, but TAB-completion works only in the current
directory. Example:


File to send: [TAB][TAB]
argv.py  error.py md5b64.pyx.py
Python_Cookbook.pdf  bookmarksfexit.py murksigkeiten
_.py compile.py   https.py wcp

File to send: /tmp/[TAB][TAB]
argv.py  error.py md5b64.pyx.py
Python_Cookbook.pdf  bookmarksfexit.py murksigkeiten
_.py compile.py   https.py wcp


Is there a way to make TAB-completion work for other directories, too?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-23 Thread Ulli Horlacher
eryksun  wrote:
> On Thu, Nov 19, 2015 at 10:31 AM, Michael Torrie  wrote:
> > One windows it might be possible to use the win32 api to enumerate the
> > windows, find your console window and switch to it.
> 
> You can call GetConsoleWindow [1] and then SetForegroundWindow [2].
(...)

Sorry, for the late feedback: 
great, this works! Thanks!
 

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-19 Thread Ulli Horlacher
Terry Reedy  wrote:
> On 11/18/2015 11:50 AM, Ulli Horlacher wrote:
> > Ulli Horlacher  wrote:
> >
> >>  from Tkinter import Tk
> >>  from tkFileDialog import askopenfilename
> >>
> >>  Tk().withdraw()
> >>  file = askopenfilename()
> >
> > I found another glitch:
> >
> > After termination of askopenfilename() the window focus is not returned to
> > the calling window (xterm on Linux, cmd on Windows). I have to click it
> > again, to regain the focus and continue typing. Is there a workaround?
> 
> What happens with
> 
> root = Tk()
> root.withdraw()
> fiel = ...
> root.destroy()
> 
> Focus cannot stay with destroyed window.

The focus is moved to another, unrelated window, but not back to the
window in which the python scripts run. 
Same behaviour on Linux (XFCE) and windows 7.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller and Python 3.5 on Windows?

2015-11-19 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> C:\Users\admin>pip install pypiwin32
> Collecting pypiwin32
>   Downloading pypiwin32-219-cp35-none-win32.whl (7.9MB)
> 100% || 7.9MB 61kB/s
> Installing collected packages: pypiwin32
> Exception:
(...)
> PermissionError: [Errno 13] Permission denied: 'c:\\program files 
> (x86)\\python
> 3.5\\Lib\\site-packages\\PyWin32.chm'
> 
> 
> Why "Permission denied"? I am logged in as administrator! Stupid Windows...

I found, I have to deactivate Windows UAC with 
C:\Windows\System32\UserAccountControlSettings.exe

Then I was able to run

pip install pypiwin32
pip install pyinstaller

without errors.

BUT pyinstaller does not work:

S:\python>pyinstaller.exe --onefile tk.py
failed to create process.

S:\python>pyinstaller --version
failed to create process.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller and Python 3.5 on Windows?

2015-11-19 Thread Ulli Horlacher
Kevin Walzer  wrote:

> I understand that Python 3.5 has shipped how the MS dll's from Visual 
> Studio are shipped, and perhaps the freezing tools (pyinstaller, py2exe) 
> haven't yet caught up. Consider filing a bug with the pyinstaller 
> developers.

http://pythonhosted.org/PyInstaller/#windows

  Installing in Windows

  For Windows, PyWin32 or the more recent pypiwin32, is a prerequisite.
  The latter is installed automatically when you install PyInstaller using
  pip or easy_install. If necessary, follow the pypiwin32 link to install
  it manually.

I have installed PyInstaller using "pip install pyinstaller".

Ok, then:

C:\Users\admin>pip install pywin32
Collecting pywin32
  Could not find a version that satisfies the requirement pywin32 (from 
versions: )
  Some externally hosted files were ignored as access to them may be unreliable
(use --allow-external pywin32 to allow).
No matching distribution found for pywin32


C:\Users\admin>pip install pypiwin32
Collecting pypiwin32
  Downloading pypiwin32-219-cp35-none-win32.whl (7.9MB)
100% || 7.9MB 61kB/s
Installing collected packages: pypiwin32
Exception:
Traceback (most recent call last):
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\basecommand.py",
 line 211, in main
status = self.run(options, args)
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\commands\install
.py", line 311, in run
root=options.root_path,
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\req\req_set.py",
 line 646, in install
**kwargs
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\req\req_install.
py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\req\req_install.
py", line 998, in move_wheel_files
isolated=self.isolated,
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\wheel.py", line
339, in move_wheel_files
clobber(source, lib_dir, True)
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\wheel.py", line
317, in clobber
shutil.copyfile(srcfile, destfile)
  File "c:\program files (x86)\python 3.5\lib\shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'c:\\program files (x86)\\python
3.5\\Lib\\site-packages\\PyWin32.chm'


Why "Permission denied"? I am logged in as administrator! Stupid Windows...


Then https://pypi.python.org/pypi/pypiwin32/219 :

pypiwin32-219-cp35-none-win32.whl  Python Wheelcp35 2015-01-09 7MB

"Python Wheel"?!

http://python-packaging-user-guide.readthedocs.org/en/latest/installing/#install-pip-setuptools-and-wheel

C:\Users\admin>pip install wheel
Collecting wheel
  Downloading wheel-0.26.0-py2.py3-none-any.whl (63kB)
100% || 65kB 1.3MB/s
Installing collected packages: wheel
  Failed to write executable - trying to use .deleteme logic
Exception:
Traceback (most recent call last):
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\_vendor\distlib\
scripts.py", line 209, in _write_script
self._fileop.write_binary_file(outname, script_bytes)
  File "c:\program files (x86)\python 3.5\lib\site-packages\pip\_vendor\distlib\
util.py", line 388, in write_binary_file
with open(path, 'wb') as f:
PermissionError: [Errno 13] Permission denied: 'c:\\program files (x86)\\python
3.5\\Scripts\\wheel.exe'


Looks like I have a broken Windows :-(

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: handling of non-ASCII filenames?

2015-11-19 Thread Ulli Horlacher
Christian Gollwitzer  wrote:
> Am 18.11.15 um 17:45 schrieb Ulli Horlacher:
> > This is my encoding function:
> >
> > def url_encode(s):
> >u = ''
> >for c in list(s):
> >  if match(r'[_=:,;<>()+.\w\-]',c):
> >u += c
> >  else:
> >u += '%' + c.encode("hex").upper()
> >return u
> >
> >
> 
> The quoting is applied to a UTF8 string.

encode("hex") works only with binary strings?
How do I convert a UTF8 string to binary?



> But I think you shouldn't do it yourself, use a library function:
> 
> import urllib
> urllib.quote(yourstring.encode('utf8'))

It does not encode exactly the same way I need it.
Besides this, I want to understand how Python handles strings and
character encoding. 


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyinstaller and Python 3.5 on Windows?

2015-11-18 Thread Ulli Horlacher
Christian Gollwitzer  wrote:
> Am 18.11.15 um 23:46 schrieb Ulli Horlacher:
> > To run my Python programs on other Windows systems without a Python
> > installation I must create standalone Windows executables.
> >
> > pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but
> > with Python 3.5 I get:
> >  [stack trace]
> 
> Are you using the newest version?

Yes. Yesterday installed.


> According to http://www.pyinstaller.org/ they claim support for Python3.

Therefore my try :-)


> Does a hello world script work?

No. 
My test-program I tried to compile was:

#!/usr/bin/python

from tkinter import Tk,filedialog

askopenfilename = filedialog.askopenfilename

Tk().withdraw()
file = filedialog.askopenfilename()
print('File selected: "%s"\n' % file)


It runs directly, but I cannot compile it with pyinstaller.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


pyinstaller and Python 3.5 on Windows?

2015-11-18 Thread Ulli Horlacher
To run my Python programs on other Windows systems without a Python
installation I must create standalone Windows executables.

pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but
with Python 3.5 I get:

S:\python>pyinstaller.exe --onefile tk.py
Traceback (most recent call last):
  File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in 
load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, in l
oad_entry_point
return get_distribution(dist).load_entry_point(group, name)
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2682, in
load_entry_point
return ep.load()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2355, in
load
return self.resolve()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2361, in
resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "c:\python35\lib\site-packages\PyInstaller\__main__.py", line 21, in 
import PyInstaller.building.build_main
  File "c:\python35\lib\site-packages\PyInstaller\building\build_main.py", line
31, in 
from ..depend import bindepend
  File "c:\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 40,
 in 
from ..utils.win32.winmanifest import RT_MANIFEST
  File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
ine 97, in 
from PyInstaller.utils.win32 import winresource
  File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", l
ine 20, in 
import pywintypes
  File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in 
__import_pywin32_system_module__("pywintypes", globals())
  File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in __im
port_pywin32_system_module__
import _win32sysloader
ImportError: DLL load failed: The specified module could not be found.


Is there a solution available?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: handling of non-ASCII filenames?

2015-11-18 Thread Ulli Horlacher
Chris Angelico  wrote:

> >> If you can use Python 3
> >
> > I cannot use it, because the Python compiler pyinstaller does not work
> > with it on Windows:
> >
> > S:\python>pyinstaller.exe --onefile tk.py
> > Traceback (most recent call last):
> >   File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in 
> > load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')()
> >   File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, 
> > in l
> > oad_entry_point
(...)
> >
> > With python 2.7, pyinstaller runs without problems.
> 
> Hmm. That's a separate consideration. If you take a step back and ask
> the broader question "How can I package my Python 3.5 script into a
> .exe file?", I'm pretty sure there is an answer; maybe pyinstaller
> isn't the way to do it. (I'm not an expert on exe file production.)

pyinstaller works without any problems with Python 2.7.10


> Does your script run happily in 3.5 if it isn't packaged into an exe?

Yes.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: handling of non-ASCII filenames?

2015-11-18 Thread Ulli Horlacher
Chris Angelico  wrote:

> > As I am Python newbie I have not quite understood the Python character
> > encoding scheme :-}
> >
> > Where can I find a good introduction of this topic?
> 
> Here are a couple of articles on the basics of Unicode:
> 
> http://www.joelonsoftware.com/articles/Unicode.html

I do Unicode programming for over 20 years. So, I do have a basic
understanding of it. I am just new to Python.


> http://nedbatchelder.com/text/unipain.html

Thanks. I will read it.


> If you can use Python 3

I cannot use it, because the Python compiler pyinstaller does not work
with it on Windows:

S:\python>pyinstaller.exe --onefile tk.py
Traceback (most recent call last):
  File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in 
load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, in l
oad_entry_point
return get_distribution(dist).load_entry_point(group, name)
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2682, in
load_entry_point
return ep.load()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2355, in
load
return self.resolve()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2361, in
resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "c:\python35\lib\site-packages\PyInstaller\__main__.py", line 21, in 
import PyInstaller.building.build_main
  File "c:\python35\lib\site-packages\PyInstaller\building\build_main.py", line
31, in 
from ..depend import bindepend
  File "c:\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 40,
 in 
from ..utils.win32.winmanifest import RT_MANIFEST
  File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
ine 97, in 
from PyInstaller.utils.win32 import winresource
  File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", l
ine 20, in 
import pywintypes
  File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in 
__import_pywin32_system_module__("pywintypes", globals())
  File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in __im
port_pywin32_system_module__
import _win32sysloader
ImportError: DLL load failed: The specified module could not be found.


With python 2.7, pyinstaller runs without problems.



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> from Tkinter import Tk
> from tkFileDialog import askopenfilename
> 
> Tk().withdraw()
> file = askopenfilename()

I found another glitch:

After termination of askopenfilename() the window focus is not returned to
the calling window (xterm on Linux, cmd on Windows). I have to click it
again, to regain the focus and continue typing. Is there a workaround?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


handling of non-ASCII filenames?

2015-11-18 Thread Ulli Horlacher
I have written a program (Python 2.7) which reads a filename via
tkFileDialog.askopenfilename() (was a good hint here, other thread).

This filename may contain non-ASCII characters (German Umlauts).

In this case my program crashes with:

  File "S:\python\fexit.py", line 1177, in url_encode
  u += '%' + c.encode("hex").upper()
  File "C:\Python27\lib\encodings\hex_codec.py", line 24, in hex_encode
output = binascii.b2a_hex(input)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 0: 
ordinal not in range(128)


This is my encoding function:

def url_encode(s):
  u = ''
  for c in list(s):
if match(r'[_=:,;<>()+.\w\-]',c): 
  u += c
else:
  u += '%' + c.encode("hex").upper()
  return u



As I am Python newbie I have not quite understood the Python character
encoding scheme :-}

Where can I find a good introduction of this topic?

I would also appreciate a concrete solution for my problem :-)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Chris Angelico  wrote:

> > In my application the user MUST select files and directories (in one go).
> 
> It's extremely uncommon to be able to select a combination of files
> and directories. 

I have an uncommon application :-)
Filetransfer of ANY size: http://fex.rus.uni-stuttgart.de:8080/


> The UI for this would be quite annoying, I think. You may find it easier
> to have your own wrapper; for example, have a list of selected
> files/directories, with buttons "Add File" and "Add Directory"
> underneath.

I came (independantly) to the same solution!
So it must be a good idea :-)

http://fex.rus.uni-stuttgart.de:8080/fop/3yxsCacS/X-20151118145221.png


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Steven D'Aprano  wrote:

> >> The limitation is that this will not work if any of the file names
> >> contain astral (non-BMP) chars because tk cannot handle such characters.
> > 
> > What are "astral chars"?
> 
> Unicode characters beyond U+.

I see, for very exotic character sets, like Klingon, etc :-)
In my case, I can simple ignore them.


> Unicode covers the entire range of code points (informally characters, don't
> worry about the technical difference) from U+ to U+10. The part
> following the "U+" is the numeric ordinal value, written in hexadecimal.

That was my knowledge so far.


> Some older versions of Unicode only included 2**16 == 65536 distinct
> characters, but many years ago Unicode was extended far beyond that number.
> But the first 65536 characters are called the "Basic Multilingual Plane".
> All the rest are in the "Supplementary Multilingual Planes", which being a
> mouthful to say and write, often gets abbreviated as "astral planes". Hence
> the characters themselves are called "astral characters".

And this was new to me. Learned :-)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Terry Reedy  wrote:

> >   from Tkinter import Tk
> >   from tkFileDialog import askopenfilename
> >
> >   Tk().withdraw()
> >   file = askopenfilename()
> 
> To get multiple names, add 's'. 

I have found it already, thanks.


> The limitation is that this will not work if any of the file names 
> contain astral (non-BMP) chars because tk cannot handle such characters.

What are "astral chars"?

But anyway, askopenfilename() is a dead end for me: one cannot select
directories with it, just plain files.
In my application the user MUST select files and directories (in one go).


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> it is too complicated to rewrite my application from CLI to GUI.
> But... is there a windows program with which one can select files and the
> result is written to STDOUT?

Found it:

from Tkinter import Tk
from tkFileDialog import askopenfilename

Tk().withdraw()
file = askopenfilename()


Hey, easy! :-)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> > How can I implement such a get_paste() function?
> > I need a non-blocking getkey() function.
> > It must work on Windows and Linux.
> 
> Non-blocking I/O from the commandline is OS specific. There are 
> different solutions, and it's usually hacky (stty on Linux, Console API 
> on Windows)

A "if windows (...) else linux (...)" solution is ok, I have such
distinction already at several places in my code.

Do you have example code for non-blocking I/O?


> Why do you not use a proper GUI toolkit to do this? 

it is too complicated to rewrite my application from CLI to GUI.
But... is there a windows program with which one can select files and the
result is written to STDOUT?
Then I could use pipe open in my Python program.


> The standard terminal on Windows is very ugly, can't resize the width,
> and pasting works only if you right-click -> paste.

You can also use drag&drop. This is ok for my users.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   >