get output of cmd-line command under MS windows

2006-02-08 Thread calmar
Hi all,

unfotunately, 'commands.getstatusoutput(command)' does not work under
windows.

Would there be any alternative?

os.system also just provides the exit number I think.

thanks a lot, 
and cheers
marco


-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get output of cmd-line command under MS windows

2006-02-10 Thread calmar
On 2006-02-08, Bernard Lebel <[EMAIL PROTECTED]> wrote:

Hi Bernhard and all,

> oPipe = os.popen( "run C:/program files/my app/executable.exe" )
>
> while 1:
>   sLine = oPipe.read()
>   print sLine
>   if sLine == '':
>   print 'No more line from pipe, exit.'
>   break
>

I see. I saw also os.popen("").read() or so.

Anyway, not sure if that would also catch stderr?

But doesn't matter. It seems, imagemagick (binaries) won't provide
proper error-codes, but at least when it prints something, something was
not ok probably. 

I will check the resulting file, to see if everything went ok, and try
to catch the output like you mentioned.

thanks a lot
marco

-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get output of cmd-line command under MS windows

2006-02-14 Thread calmar
On 2006-02-08, Bernard Lebel <[EMAIL PROTECTED]> wrote:

Hi Bernhard,

> You should give a go to os.popen(  ). Article
> 6.1.2 and 6.1.3 in the Python Library doc.
>

that was good, but on python2.4

subprocess is GREAT! e.g.:

pipe = subprocess.Popen(tot, stdout=subprocess.PIPE,\
stderr=subprocess.PIPE, shell=False)
message = pipe.stdout.read()
error = pipe.stderr.read()

thanks all,
calmar

-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


text encodings -> subprocess.Popen or -> labelmarkup (pygtk)

2006-02-16 Thread calmar
Hi all,

first of all, I have to say I have hardly no knowledge about that
issue.

on the program there, I have it like that:


,---
| obj = unicode(newcomment, 'utf-8')
| newcomment = obj.encode('latin-1')
|
| pipe = subprocess.Popen(tot, stdout=subprocess.PIPE,\
|stderr=subprocess.PIPE, shell=False)
`---

that seems to work with that construction above.

Then I think, 'what' kind of encoding I can send to an external program,
depends also on that program? Or on the environment? If, then how could
I get that environemnt? (the programs runs also under MS windows)

Well, maybe someone has some hints about encodings issues like that, and
what I can send to external commands?

thanks a lot
calmar



-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


general coding issues - coding style...

2006-02-18 Thread calmar
Hi all,

since I'm just a 'handicraft'/beginner or so,

could anybody provide me with some (rough) hints, about how to enhance the code
here:

http://calmar.ws/tmp/cal.html

Cheers and thanks a lot
calmar


-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-18 Thread calmar
On 2006-02-18, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

Hi Diez,

>   - why are these {{{ thingies there?

markers for folding for vim
http://www.calmar.ws/tmp/sc.png

>   - use string interpolation like "Foo %s %i" % ("bar", 1) instead of 
> concatenating strings.

I see, get's shorter and so, and I can break lines.
(seems to me, after  ( or [ or so, I can use a new line without
to worry)

>   - it seems that you could benefit from a class instead of a bunch of 
> functions & few globals. No need to go too crazy about OO, but it has 
> its merits

I see. Maybe I could then build some classes for that prog,
especially since I use only one file, it probably would make
some sense for getting a better structure.

>
>   - try using something like glade - creating GUIs by hand sucks 
> big-timer :)

I should (seriously) check out probably.

>   - read up about unicode and encodings, what they mean and why and when 
> to use what. Really. Most problems in that field stem from people being 
> sort of ignorant on that topic and just wiggling themselves through all 
> the time - in the end, messing up stuff. It really _isn't_ that complicated.

I read up. In fact, basically it does not seem to be that complicate.
Unicode just a 'numbered' list of all available character, and
e.g. uft-8 a organized way to 'store' those 'numbers' wisely
into bytes.

I still have some problems with that (and gave up), but since I begin to
now understand it somebit more, I should try/check again.

>   - when creating string-keyed dicts, the idiom
>
> dict(foo="bar",
>  baz="pillepalle")

I see, I changed too.

Thanks a lot,
marco

-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-19 Thread calmar
On 2006-02-18, Justin  Azoff <[EMAIL PROTECTED]> wrote:

Hi all,

> Dylan Moreland wrote:
>> I would look into one of the many Vim scripts which automatically fold
>> most large blocks without the ugly {{{.
>
> Who needs a script?
> "set foldmethod=indent"
> works pretty well for most python programs.
>

Well, foldmethod=marker does not bother me, because the folds are
normally closed. With markers, it takes one line per function, with
indent I see 2, so I prefer markers.

..and since I can easily get rid of them, and add them again, I will at
least remove them before e.g. putting to the web or so.


Cheers and thanks,
calmar



-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-19 Thread calmar
On 2006-02-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Hi,

> 1585 if sys.path[0][-12:] == "\library.zip":  #for py2exe
> if sys.path[0].endswith( "\\library.zip" ):

cool, thx,

> (did you really mean one back-slash there?)

(yeah, one backslash)

> 499 tuple = os.path.split(filename)
> bad variable name... tuple(x) converts a sequence to a tuple.

I see, I changed that to
path, filen = os.path.split(filename)

> You have a number of places where you check for len(x)==0:
> 674 if len(files) == 0:
> --> if not files:

I see. thx

> you should run your code through pychecker (it had a lot to say...).

I see, cool tool that pychecker!
I can't do something against the 'not used variable' so probably?
(since pygtk just sends those items anyway)

> You use global alot... that should be a red flag.  Like the poster
> above mentioned,  you have things that are telling you they want to
> be objects.

I will try to get some order (classes) and maybe remove them.

thanks a lot!!

cheers,
calmar

-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-20 Thread calmar
On 2006-02-19, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:

Bonjour,

>
> 1/ learn OO and get rid of globals.

Well I created two classes now. I put some things global (your point 6).
e.g. if it's on Windows or not, and other things.

> 2/ use dict or list based dispatch instead of long if/elif/elif... clauses

when I find out what you mean, I will. Probably something lika a 'case'
thing? #python meant a list containing functions or so. So that the
values represent the functions to call, isn 'it?

> 3/ stdout is meant for *normal* program outputs. Errors and verbosity go 
> to stderr

yeah, changed (somebit)

> 4/ triple quoted strings are fine for multiline text

yeah. I have lot of triple prints...

> 5/ os.path is fine for portable filepath operations

I don't really understant what you mean here, sorry

> 6/ things that dont change during program execution (ie : constants) 
> should not be defined inside a function

As I mentioned above, these I placed globally:

main gtkwindows, 
smwin or not, 
pyexe or not,  
preferred encoging

according to your statement?


Anyway, since I did lot of changes, I'm myself confused actually.
http://calmar.ws/tmp/cal.html

Will try to cleanup and  implement even further all good
advices from all in some days.

Thanks a lot!!
calmar



-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-21 Thread calmar
On 2006-02-20, JW <[EMAIL PROTECTED]> wrote:

Hi JW,

> About this line:
> 1585 if sys.path[0][-12:] == "\library.zip":  #for py2exe
>
> pl... suggested:
> if sys.path[0].endswith( "\\library.zip" ):
>
>
> print "\\library.zip"
>

Yeah, I have two backslashes, but thaks for pointing out.

> If you don't use the double backslash, you'll eventually have a
> problem, especially in Windows, which unfortunately uses the backslash
> as a directory seperator.  You might also want to look at os.sep and
> the os.path.* functions, if you are interested in making your code work
> on different platforms.  

Yeah, I will use the os.sep variable, that's a good idea

thanks a lot,
calmar


-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list