strftime in python 2.2

2007-08-13 Thread Flyzone
I'm trying to make work this code in python 2.2.3:

check=datetime.datetime.today().strftime("%H%M")

but datetime is not supported in that version but just in the later.
I can't upgrade python, too many dependencies in a critical system.
How can i convert that string to have the same result?

Hope someone can help me,
Thanks in advance

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem on waiting exit thread and write on file

2007-06-15 Thread Flyzone
Marc 'BlackJack' Rintsch ha scritto:
> for thread in threads:
> thread.join()
>
> Much shorter, isn't it!?  :-)

If i do like you tell, all thread will run together right? So i'll get
troubles!
I have a list of hostname, i run a network program and then i need to
write some of the output that give me this command to a file.
If i run the thread together, they can get problems writing on the
same file.
So I have splitted the list in 5 groups, the group 1 have filetmp 1,
group 2 have filetmp 2 and so on...
Then I start one thread for all groups, so 5 threads running together,
the other waiting the end of one of them.

-- 
http://mail.python.org/mailman/listinfo/python-list


problem on waiting exit thread and write on file

2007-06-13 Thread Flyzone
I have a list of parameters.
I need to run in thread a command, one thread for one parameter.
So i made a for loop, creating 5 threads and waiting their stop with:
for parameter in parameters

Thread{

write on BW2

}

Main {
   open file BW2 for write
   . (creating list of thread with a counter)
   Stopped=False
   while (Stopped == False):
  if not thread5.isAlive():
  if not thread4.isAlive():
  if not thread3.isAlive():
  if not thread2.isAlive():
  if not thread1.isAlive():
Stopped=True
  if (Stopped == False):
 time.sleep(0.3)
   ..
   close file BW2
}

Somethimes i get however the error that i can't write on a file
already closed
There is a way more easy to wait that all children exit and to run a
queue of threads?
I tried also this:
   a=0
   while (a == 0):
   try:
   os.waitpid(-2, 0)
   except OSError, exc:
   # all CHILD finished
   a=1
but the same problem persist. The only way to don't have error is to
had a time.sleep(4) before closing the file from the main program.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen e pclose on python 2.3 question

2007-06-12 Thread Flyzone
> i need to kill the child if the program take more than 300 ms, but i
> need also to wait this 300 ms to have the reply.

I reply by myself:

from popen2 import Popen3
cmd = Popen3('command','r')
waiting=0
while (cmd.poll()==-1):
   time.sleep(0.1)
   waiting+=1
   if (waiting>3): os.kill(RESULT.pid,0)

-- 
http://mail.python.org/mailman/listinfo/python-list


popen e pclose on python 2.3 question

2007-06-12 Thread Flyzone
I need to run a network program and return output in a variable name
without use temporany file.
So i tought to use popen (i'm using python 2.3, i can't upgrade).
RESULT = os.popen('command'+HOST, 'r')
I have a problem about it:
i need to kill the child if the program take more than 300 ms, but i
need also to wait this 300 ms to have the reply.
os.pclose(RESULT) give me:
AttributeError: 'module' object has no attribute 'pclose'
cause pclose doens't exist in 2.3.and a time.wait(0.3) is not a so
clean code.
Someone can give me some tricks? I would like a script portable on
python 2.3, i would not like
to compile on 2.5.

-- 
http://mail.python.org/mailman/listinfo/python-list


checking if hour is between two hours

2007-05-11 Thread Flyzone
Hi all, i'm again working on my script of parsing logfiles :)
I putted a new function to disable the rule of error between a certain
hours, cause i want to use it as a monitoring script that run every 5
minutes and to disable error in hours of maintenance.
But i have some "problems" to check it.
In the rule-file i have HHMM(start) and HHMM(stop) - 0 0 to
disable hours check (i can't check the timestamp in logfile cause not
all the logfiles that i need to check have a timestamp in it).
In the script i wrote:

Actualtime=datetime.datetime.today().strftime("%H%M")
if (start>end):
 if (Actualtime>start):
  end=int(Hcheck)+1
 else:
  if (int(Actualtime)int(end)) or
((start=="0") and (end=="0")) ):
   rule=error
   ...blablabla
else:
   rule=skip
   blablabla
Why i don't use the complete date with YYMMDDHHMM?
Think about a rule that need to be disabled from hours 20:00 to
04:00.
If i use also yymmdd, in the rule file i need to write a 2000 and
0400+1, the +1 to tell the script that the end
is in the day after, to add a day. But it will work just till the
, hour in witch the day will change.

The script work, but is not so "clean"i just would like some
advice to make it more clean, if possible.

Like always, thanks in advance for the helps :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regexp match string with word1 and not word2

2007-05-02 Thread Flyzone
On 30 Apr, 20:00, Steven Bethard <[EMAIL PROTECTED]> wrote:
> Well then it seems like you might want to rethink this rule-file
> approach since your problem is clearly not amenable to regular expressions.
[cut]
> That said, here's a regexp that might work::
>  ((?!two:).)*one((?!two:).)*
> That makes a negative lookahead assertion at each character in the string.

But match again something so don't work like i wanted.

Maybe a right approach will be another if after the first one? Like:
   for y in range(0, len(skip_lst) ):
 if (re.search(skip_lst[y], line)):
 if
(re.search(skip_lst_negative[y], line)):
   skip=1
   break
and in the rule-file, i could add a new column and check to do the if
just if the second column is not empty.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regexp match string with word1 and not word2

2007-04-30 Thread Flyzone
On 30 Apr, 17:11, Steven Bethard <[EMAIL PROTECTED]> wrote:

> You don't need a regexp:;

I need a regexp.i'm parsing a file with a rule-file that contains
also regexp and strings too
Read my post to James Stroud.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regexp match string with word1 and not word2

2007-04-30 Thread Flyzone
James Stroud ha scritto:

> The P.S: suggests homework, but this can't be homework because python
> regex won't do this, so your teacher gets an F if its homework. You

Not a homework, but a "workwork" :-)
I'm writing a script to parse logfiles, and I have began to study
python for this (bash was too much slow).
When i'll finishi it, I'll post a link here if someone think that
could be helpful.

> require a negative look-behind assertion of variable length--not
> possible in python regex. You will have to use something else--or maybe
> you don't understand the homework problem.

I was asking that cause in the code i wrote this:
  for y in range(0, len(skip_lst) ):
 if (re.search(skip_lst[y], line)):
  skip=1
   break

In skip_lst there are the regexp and strings (on one line) to match
with "line".
But rarely the rules to be matched need to have also a logical And.
What could be the solution? Add another array with a "not" regexp?

-- 
http://mail.python.org/mailman/listinfo/python-list


regexp match string with word1 and not word2

2007-04-30 Thread Flyzone
Hello,
i have again problem with regexp :-P
I need to match all lines that contain one word but not contain
another.
Like to do "grep one | grep -v two:"
The syntax of the string is:
(any printable char)two:(any printable char)one(any printable char)
Example:
Apr 30 00:00:09 v890neg0 two: [ID 702911 daemon.one] findings:
blablabla

I tried with:
.*[^t][^w][^o].*one.*
but is not working, the string is always match and in other tries
using "less logic" i get always some different match :-(

P.S: i can't have more re.search, so i just need ONE regexp

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: freeze and problem with static libraries

2007-04-25 Thread Flyzone
On 24 Apr, 17:23, Flyzone <[EMAIL PROTECTED]> wrote:
> I get this warning on freezing my source:

I use the command:
./Python-2.3.6/Tools/freeze/freeze.py /path/to/my/file.py

-- 
http://mail.python.org/mailman/listinfo/python-list


freeze and problem with static libraries

2007-04-24 Thread Flyzone
Hi, i need to "compile" a python source (2.3.6) to make it standalone
on Solaris 9.
I get this warning on freezing my source:

"Warning: unknown modules remain: _locale _random _socket array
binascii cStringIO datetime fcntl math pwd select strop termios time"

in the source i have: "import os, stat, re, datetime, time, glob"
and running the frozen application I get: "ImportError: No module
named datetime"

like i have read in the old post in this newgroup i tried to recompile
python to avoid shared libraries (i used ./configure --disable-
shared), and to reinstall python of course (recompiling my source) but
the same problem occour. In Modules/Setup i don't have shared
libraries and the line "*shared*" is commented.

I have tried also other freeze application (Gordon MacMillan,
cx_freeze), but i get a fatal error importing zlib also if i have
installed right.

Someone have some tips?
Thanks in advance

-- 
http://mail.python.org/mailman/listinfo/python-list


exception just to avoid output error (newbie)

2007-04-18 Thread Flyzone
Hi
I'm trying to delete some files, but i get an exception error if the
file don't exist.
I can use an {if fileexist(file) then delete}, but it will get cpu
time.
So i catch the exception with:
   try: os.remove(filename)
   except EnvironmentError: error=1
If i just want to avoid the output error, is this the right way to
write the code?
I don't care of get if is in error, but an "except EvironmetError"
without the ":" will give me a sytax error.
Am I too much complicated? :-)

Thanks in advance

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: split and regexp on textfile

2007-04-13 Thread Flyzone
On 13 Apr, 11:30, "Flyzone" <[EMAIL PROTECTED]> wrote:

> all together :(

Damn was wrong mine regexp:
pat = re.compile("[A-Z][a-z][a-z][ ][A-Z][a-z][a-z][ ][0-9| ][0-9][ ]
[0-9][0-9][:][0-9][0-9]",re.M|re.DOTALL)

now is working! :)
Great! really thanks for the helps!

A little question: the pat.split can split without delete the date?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: split and regexp on textfile

2007-04-13 Thread Flyzone
On 13 Apr, 11:14, [EMAIL PROTECTED] wrote:
> change to pat.split(data) then.

next what i have tried originally..but is not working, my result is
here:

["Mon Feb 26 11:25:04 2007\ntext\n  text\ntext\nMon Feb 26 11:25:16
2007\ntext\n  text\n text\nMon Feb 26 17:06:41 2007\ntext"]

all together :(

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: split and regexp on textfile

2007-04-13 Thread Flyzone
On 13 Apr, 10:40, [EMAIL PROTECTED] wrote:
> you trying to match the date part right? if re is what you desire,
> here's one example:

Amm..not! I need to get the text-block between the two data, not the
data! :)

-- 
http://mail.python.org/mailman/listinfo/python-list


split and regexp on textfile

2007-04-13 Thread Flyzone
Hi,
i have a problem with the split function and regexp.
I have a file that i want to split using the date as token.
Here a sample:
-
Mon Apr  9 22:30:18 2007
text
text
Mon Apr  9 22:31:10 2007
text
text


I'm trying to put all the lines in a one string and then to separate
it
(could be better to not delete the \n if possible...)
  while 1:
 line = ftoparse.readline()
 if not line: break
 if line[-1]=='\n': line=line[:-1]
 file_str += line
  matchobj=re.compile('[A-Z][a-z][a-z][ ][A-Z][a-z][a-z][ ][0-9| ][0-9]
[ ][0-9][0-9][:]')
  matchobj=matchobj.split(file_str)
  print matchobj

i have tried also
   matchobj=re.split(r"^[A-Z][a-z][a-z][ ][A-Z][a-z][a-z][ ][0-9| ]
[0-9][ ][0-9][0-9][:]",file_str)
and reading all with one:
   file_str=ftoparse.readlines()
but the split doesn't work...where i am wronging?

-- 
http://mail.python.org/mailman/listinfo/python-list


parsing text in blocks and line too

2007-04-12 Thread flyzone
Goodmorning people :)
I have just started to learn this language and i have a logical
problem.
I need to write a program to parse various file of text.
Here two sample:

---
trial text bla bla bla bla error
  bla bla bla bla bla
  bla bla bla on more lines
trial text bla bla bla bla warning bla
  bla bla more bla to be grouped with warning
  bla bla bla on more lines
  could be one two or ten lines also withouth the tab beginning
again text
text can contain also blank lines
text no delimiters
--
Apr  8 04:02:08 machine text on one line
Apr  8 04:02:09 machine this is an error
Apr  8 04:02:10 machine this is a warning
--
parsing the file, I'll need to decide if the line/group is an error,
warning or to skip.
Mine problem if how logical do it: if i read line by line, I'll catch
the error/warning
on first and the second/third/more will be skipped by control.
Reading a group of line i could lose the order on the output: my idea
is to have
an output in html with the line in the color of the check (yellow for
warning,
red for error).
And i have also many rules to be followed so if i read one rule and
then i search
on the entire file, the check will be really slow.

Hope someone could give me some tips.
Thanks in advance

-- 
http://mail.python.org/mailman/listinfo/python-list