[Tutor] sftp in python without using pysftp or paramiko

2018-10-20 Thread Asad
hi All ,

I am looking to create a python script which logs in to the server and
copies the fie from ftp to local system .:

sftp a...@us.com 2100

password : xxx

sftp> cd /to_dir
sftp > get file1
sftp >exit

Please advice .

-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to print lines within two timestamp

2018-10-26 Thread Asad
Hi ,

Yes i have the code :

import re
import datetime
from datetime import timedelta

Header = "*"

f3 = open ( r"D:\QI\logA.txt", 'r' )
string = f3.read ()
regex = re.compile ( "\n" )
st = regex.sub ( " ", string )
st1 = st.split ( " " )

if re.search ('ERR-1:', st ):
x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)", st )
j = x[0][0] + " "+ x[0][1]+" " + x[0][2] +":"+ x[0][3]+":" +
x[0][4]+" " + x[0][5]
h = x[1][0] + " "+ x[1][1]+" "+ x[1][2] +":" + x[1][3] +":"+
x[1][4] +" "+ x[1][5]
y = datetime.datetime.strptime ( j, '%b %d %H:%M:%S %Y' )
print y
k = datetime.datetime.strptime ( h, '%b %d %H:%M:%S %Y' )
print k

f4 = open ( r"D:\QI\logC11.txt", 'r' )

string1 = f4.read ()
reg = re.compile ( "\n" )
newst = reg.sub ( " ", string1 )
newst1 = newst.split ( " " )

if re.search ( "ERR-2", newst ):
a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", newst )
for i in range ( len ( a ) ):
newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
if newtime > y and newtime < k:
   print "Install patch1"

if re.search ( "ERR-3", newst ):
a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", newst )
for i in range ( len ( a ) ):
newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
if newtime > y and newtime < k:
print newtime, y, k
print "Install patch2"

==

output i get :

*Install patch1   - wrong solution
2018-10-22 10:21:23 2018-10-22 10:21:15 2018-10-22 10:21:25
Install patch2   - correct solution *


*It should have only searched between timestamps **2018-10-22 10:21:15
2018-10-22 10:21:25*

*in logC11.txt  what I am doing wrong please adice stuck on this for long.*
Patching tool version 12.2.0.1.0 Production on Mon Oct 22 10:21:15 2018

verify_queryable_inventory returned ERR-1: Latest xml inventory is not loaded 
into table


Prereq check failed, exiting without installing any patches.

Patching tool complete on Mon Oct 22 10:21:25 2018
 LOG file opened at 04/26/18 06:11:52

ERR-2: OS message: No child processes
operation "wait", location "skudmi:prp:6"

 LOG file opened at 10/22/18 09:10:25


ERR-3: patchObjectPossible causes are:"

Trim whitespace same as SQL Loader

 LOG file opened at 10/22/18 10:21:23


ERR-3: patchObjectPossible causes are:"

Trim whitespace same as SQL Loader


 LOG file opened at 10/22/18 10:22:25


ERR-3: patchObjectPossible causes are:"

Trim whitespace same as SQL Loader___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to print lines within two timestamp

2018-10-27 Thread Asad
On Sat, Oct 27, 2018 at 4:01 AM  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>1. How to print lines within two timestamp (Asad)
>2. Re: How to print lines within two timestamp (Alan Gauld)
>3. Re: Python Help (Bob Gailer)
>4. Re: Python Help (Adam Eyring)
>5. Re: Python Help (Adam Eyring)
>
>
>
> -- Forwarded message --
> From: Asad 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Fri, 26 Oct 2018 17:03:01 +0530
> Subject: [Tutor] How to print lines within two timestamp
> Hi ,
>
> Yes i have the code :
>
> import re
> import datetime
> from datetime import timedelta
>
> f3 = open ( r"D:\QI\logA.txt", 'r' )
> string = f3.read ()
> regex = re.compile ( "\n" )
> st = regex.sub ( " ", string )
> st1 = st.split ( " " )
>
> if re.search ('ERR-1:', st ):
> x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)",
> st )
> j = x[0][0] + " "+ x[0][1]+" " + x[0][2] +":"+ x[0][3]+":" +
> x[0][4]+" " + x[0][5]
> h = x[1][0] + " "+ x[1][1]+" "+ x[1][2] +":" + x[1][3] +":"+
> x[1][4] +" "+ x[1][5]
> y = datetime.datetime.strptime ( j, '%b %d %H:%M:%S %Y' )
> print y
> k = datetime.datetime.strptime ( h, '%b %d %H:%M:%S %Y' )
> print k
>
> f4 = open ( r"D:\QI\logC11.txt", 'r' )
>
> string1 = f4.read ()
> reg = re.compile ( "\n" )
> newst = reg.sub ( " ", string1 )
> newst1 = newst.split ( " " )
>
> if re.search ( "ERR-2", newst ):
> a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]",
> newst )
> for i in range ( len ( a ) ):
> newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
> if newtime > y and newtime < k:
>print "Install patch1"
>
> if re.search ( "ERR-3", newst ):
> a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]",
> newst )
> for i in range ( len ( a ) ):
> newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
> if newtime > y and newtime < k:
> print newtime, y, k
> print "Install patch2"
>
>
> ==
>
> output i get :
>
> *Install patch1   - wrong solution
> 2018-10-22 10:21:23 2018-10-22 10:21:15 2018-10-22 10:21:25
> Install patch2   - correct solution *
>
>
> *It should have only searched between timestamps **2018-10-22 10:21:15
> 2018-10-22 10:21:25*
>
> *in logC11.txt  what I am doing wrong please adice stuck on this for long.*
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Fri, 26 Oct 2018 18:45:17 +0100
> Subject: Re: [Tutor] How to print lines within two timestamp
> On 26/10/2018 12:33, Asad wrote:
> > Hi ,
> >
> > Yes i have the code :
>
> It woiyukld help us to help you if you provided some clues as to what it
> was doing.
> A good start would be some comments - especially around the regexes.
> Don't make us parse them without some idea of what you are expecting.
> Also moremeaningful variable names than h,j,k etc
>
> > import re
> > import datetime
> > from datetime import timedelta
>
> You don't appear to use timedelta?
>
 Answer: Yes I remove from datetime import timedelta


>
> > Header = "*"
> >
> > f3 = open ( r"D:\QI\logA.txt", 'r' )
> > string = f3.read ()
> > regex = re.compile ( "\n" )
> > st = regex.sub ( " ", string )
>
> I suspect regular string methods would be simpler here.
> answer : can you please provide the code to replace above
>


> > st1 = st.split ( " " )
> >
> > if re.search ('ERR-1:', st ):
> > x = re.

[Tutor] (no subject)

2018-10-27 Thread Asad
Hi All ,

  I found a logic :

1.initialize print flag to false
2. Save starting and ending times in variables
3. loop to read or process sequential lines in the file
  a. See if line contains time
  b. If it does, extract time
  c. Compare time in line to starting time
  d. If line time is greater than or equal to start time, set print flag to
true
  e. If line time is greater than ending time, set print flag to false
  f. If print flag is true print line
  g. End of loop — process next line

start_time = 2018-10-22 10:21:15
end_time = 2018-10-22 10:21:25

f4 = open ( r"logC11.txt", 'r' )

for line in f4.readlines():
  a = re.findall( r'\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]', line )
  print a
  #b = a.group(0)
  newtime = datetime.datetime.strptime ( a[0], '%m/%d/%y %H:%M:%S' )
  print newtime
  if newtime > y and newtime < k:
flag = True
  else:
flag = False
  if flag :
print line
  else :
continue


But it errors out :

C:\Python27\python.exe D:/QI/test_qopatch.py
Traceback (most recent call last):
2018-10-22 10:21:15
  File "D:/QI/test_qopatch.py", line 32, in 
2018-10-22 10:21:25
newtime = datetime.datetime.strptime ( a[0], '%m/%d/%y %H:%M:%S' )
['04/26/18 06:11:52']
2018-04-26 06:11:52
[]
IndexError: list index out of range

Process finished with exit code 1


Please provide the code

Thanks,

On Sat, Oct 27, 2018 at 1:35 PM  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>1. Re: How to print lines within two timestamp (Alan Gauld)
>    2. Re: Python Help (Alan Gauld)
>3. Re: How to print lines within two timestamp (Peter Otten)
>4. How to print lines within two timestamp (Asad)
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Fri, 26 Oct 2018 23:30:09 +0100
> Subject: Re: [Tutor] How to print lines within two timestamp
> On 26/10/2018 18:45, Alan Gauld via Tutor wrote:
>
> > It woiyukld
>
> No idea what happened there. Should be "would" of course!
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Fri, 26 Oct 2018 23:34:17 +0100
> Subject: Re: [Tutor] Python Help
> On 26/10/2018 18:20, Adam Eyring wrote:
>
> > beef = (beefmeals * 15.95)
>
> Note that the parens here are completely redundant.
> They don't break anything but neither do they
> contribute anything.
>
> WE already have LISP(*) for those who love parens,
> no need for (so many of) them in Python
>
> (*)Lots of Irrelevant Silly Parentheses :
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
>
>
>
> -- Forwarded message --
> From: Peter Otten <__pete...@web.de>
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sat, 27 Oct 2018 06:07:43 +0200
> Subject: Re: [Tutor] How to print lines within two timestamp
> Alan Gauld via Tutor wrote:
>
> > On 26/10/2018 18:45, Alan Gauld via Tutor wrote:
> >
> >> It woiyukld
> >
> > No idea what happened there. Should be "would" of course!
>
> Of coiyukrse! Nobody thoiyukght otherwiiyske :)
>
>
>
>
>
> -- Forwarded message --
> From: Asad 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sat, 27 Oct 2018 12:32:51 +0530
> Subject: [Tutor] How to print lines within two timestamp
> On Sat, Oct 27, 2018 at 4:01 AM  wrote:
>
> > Send Tutor mailing list submissions to
> > tutor@python.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> > https://mail.python.org/mailman/listinfo/tutor
> > or, via email, send a message with subject or body 'help' to
> > tutor-requ...@python.org
> >
> > You can reach the

[Tutor] Regex for Filesystem path

2018-11-06 Thread Asad
Hi all ,

Can you provide some advice and code for the following problem :

I have a logfile to check for errors :

/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log

f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log", 'r' )
st1 = f3.readlines ()

from the above log I extract the directory location to determine the
location of  another log  using the following regular expresssion:

for j in range ( len ( st1 ) ):
   patchnumber = re.compile(r'(\d+)\/(\d+)')

   mo = patchnumber.search (st1[j-1])
   a = mo.group()   ## 123456/789
   ===
   How to do I traverse to the required directory which is
/a/b/c/d/test/123456/789 ?

   1) First I need to extract /a/b/c/d/test/  from
 /a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log  ?
   2) Then add 123456/789 and create directory location as
/a/b/c/d/test/123456/789
   3) cd /a/b/c/d/test/123456/789
   4) look for the latest file in the directory  /a/b/c/d/test/123456/789
   5) print its content

Please advice ,
-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-07 Thread Asad
Hi All,

 I tired seems its not working as required :

from os.path import dirname, join

testdir = dirname("/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log")

dirpath = join(testdir, '123456/789')

print dirpath

/a/b/c/d/test/test_2814__2018_10_05_12_12_45\123456/789

Instead i need the script to go to the location :

/a/b/c/d/test/123456/789

Please advice .


Thanks,









> -- Forwarded message --
> From: Cameron Simpson 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Wed, 7 Nov 2018 06:47:33 +1100
> Subject: Re: [Tutor] Regex for Filesystem path
> On 06Nov2018 18:10, Alan Gauld  wrote:
> >On 06/11/2018 13:13, Asad wrote:
> >
> >> Can you provide some advice and code for the following problem :
> >
> >The first thing is to go read the documentation for the os.path module.
> >It is designed for reliable path manipulation.
> >
> >> /a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log
> >>
> >> f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log",
> 'r' )
> >> st1 = f3.readlines ()
> >
> >You hardly ever need readlines() any more, just iterate
> >over the file, its much easier.
> >
> >> for j in range ( len ( st1 ) ):
> >
> >for line in f3:
>
> Not to mention cheaper in memory usage.
>
> [...snip...]
> >>a = mo.group()   ## 123456/789
> >>===
> >>How to do I traverse to the required directory which is
> >> /a/b/c/d/test/123456/789 ?
> >
> >You can use relative paths in os.chdir.
> >So a payth of '..' will be one level up from the current
> >directory. Of course you need to chdir to that directory first
> >but os.path will tell you the dir you need.
>
> It is better to just construct the required path. Chdir there requires a
> chdir back, and chdir affects all the relative paths your programme may
> be using.
>
> I'd use os.path.dirname to get '/a/b/c/d/test' and then just append to
> it with os.path.join to contruct each directory path.
>
> [...]
> >But I'm guessing that's too obvious so the path may vary?
> >>1) First I need to extract /a/b/c/d/test/  from
> >>  /a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log  ?
>
> Use os.path.dirname:
>
># up the top
>from os.path import dirname, join
>
># later
>testdir = dirname(logfile_path)
>
> >get the dir then chdir to .. from there.
> >
> >>2) Then add 123456/789 and create directory location as
> >> /a/b/c/d/test/123456/789
> >
> >Simple string manipulation or use the os.path functions.
>
> Eg dirpath = join(testdir, '123456/789')
>
> >>3) cd /a/b/c/d/test/123456/789
> >
> >os.chdir()
>
> I still recommend avoiding this. Just construct the full path to what
> you need.
>
> >>4) look for the latest file in the directory
> /a/b/c/d/test/123456/789
> >
> >Slightly more complex, you need the creation timestamp.
> >You can find that with os.path.getctime() (or several
> >other options, eg os.stat)
>
> Do not use ctime, it is _not_ "creation" time. It is "last change to
> inode" time. It _starts_ as creation time, but a chmod or even a
> link/unlink can change it: anything that changes the metadata.
>
> Generally people want mtime (last nmodified time), which is the last
> time the file data got changed. It is more meaningful.
>
> Cheers,
> Cameron Simpson 
>
>
>
>
> --
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Asad
Hi All ,

 Thanks it works for me . However the other issue is :

testdir =
dirname(dirname("/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log"))

/a/b/c/d/test


dirpath = join(testdir, '28163133/22326541')


print dirpath


/a/b/c/d/test\28163133/22326541

*

Why is it putting \  this breaks the unix path it should be:

/a/b/c/d/test/28163133/22326541   ===> for unix platform logs

\a\b\c\d\test\28163133\22326541  ===> for windows platform logs


Please advice ,

Thanks,





On Thu, N

> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Wed, 7 Nov 2018 19:21:58 +
> Subject: Re: [Tutor] Regex for Filesystem path (Asad)
> On 07/11/2018 15:56, Asad wrote:
> > Hi All,
> >
> >  I tired seems its not working as required :
> >
> > from os.path import dirname, join
> >
> > testdir =
> dirname("/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log")
>
> Note that this will set testdir to
>
> /a/b/c/d/test/test_2814__2018_10_05_12_12_45
>
> But you want the dir above that.
> The easiest way (if this is always the case) is to just use
> dirname() again:
>
> testdir = dirname(testdir)
>
> Which should result in:
>
> /a/b/c/d/test
>
> You could of course do it in one line as
>
> myPath = "/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log"
> testdir = dirname( dirname(myPath) )
>
> Which is nicer than my original suggestion of using
> chdir and relative paths :-)
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
>
>
>
> -- Forwarded message --
> From: Zachary Ware 
> To:
> Cc: tutor 
> Bcc:
> Date: Wed, 7 Nov 2018 13:23:15 -0600
> Subject: Re: [Tutor] Displaying Status on the Command Line
> On Wed, Nov 7, 2018 at 1:17 PM Alan Gauld via Tutor 
> wrote:
> > In Python 3 there are parameters to print()
> >
> > while someProcess():
> >time.sleep(1)
> >print('.', end='', sep='')   # no newline and no spaces
>
> You'll also want `flush=True` here to avoid having your dots buffered
> until end-of-line.
>
> --
> Zach
>
> ___
> Tutor maillist  -  Tutor@python.org
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Example for read and readlines()

2018-11-11 Thread Asad
Hi All ,

 If I am loading a logfile what should I use from the option 1,2,3

f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log", 'r' )

1) should only iterate over f3

2) st = f3.read()
Should iterate over st


3) st1 = f3.readlines()

Should iterate over st1

How are the above options different it they are not can there be some
examples to describe in which situations should we each method .


Thanks,

-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Example for read and readlines()

2018-11-11 Thread Asad
Hi All,

  thanks for the reply so to put into context say I have a file
logfile formatted in text lines

1)   and I want to extract the start time , error number and end
time from this logfile so in this case what should I use I guess option 1  :

with open(filename, 'r') as f:
for line in f:
process(line)

should be fine or any other option ?

2) Another case is a text formatted logfile and I want to print (n-4)
lines n is the line where error condition was encountered .

3) Do we need to ensure that each line in the logfile ends with \n .

\n is not visible so can we verify in someway to proof EOL \n is placed
in the file .


Thanks,




>
>
>
>
>
> -- Forwarded message --
> From: Asad 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 12:19:36 +0530
> Subject: [Tutor] Example for read and readlines()
> Hi All ,
>
>  If I am loading a logfile what should I use from the option 1,2,3
>
> f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log", 'r' )
>
> 1) should only iterate over f3
>
> 2) st = f3.read()
> Should iterate over st
>
>
> 3) st1 = f3.readlines()
>
> Should iterate over st1
>
> How are the above options different it they are not can there be some
> examples to describe in which situations should we each method .
>
>
> Thanks,
>
> --
> Asad Hasan
> +91 9582111698
>
>
>
>
> -- Forwarded message --
> From: "Steven D'Aprano" 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 20:40:49 +1100
> Subject: Re: [Tutor] Example for read and readlines()
> On Sun, Nov 11, 2018 at 12:19:36PM +0530, Asad wrote:
> > Hi All ,
> >
> >  If I am loading a logfile what should I use from the option
> 1,2,3
>
> Depends what you want to do. I assume that the log file is formatted
> into lines of text, so you probably want to iterate over each line.
>
> with open(filename, 'r') as f:
> for line in f:
> process(line)
>
> is the best idiom to use for line-by-line iteration. It only reads each
> line as needed, not all at once, so it can handle huge files even if the
> file is bigger than the memory you have.
>
>
> > f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log",
> 'r' )
>
> Don't use raw strings r"..." for pathnames.
>
>
> > 1) should only iterate over f3
> >
> > 2) st = f3.read()
>
> Use this if you want to iterate over the file character by character,
> after reading the entire file into memory at once.
>
>
> > 3) st1 = f3.readlines()
>
> Use this if you want to read all the lines into memory at once.
>
>
>
> --
> Steve
>
> ___
> Tutor maillist  -  Tutor@python.org
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Example for read and readlines() (Asad)

2018-11-12 Thread Asad
Hi All ,

   Thanks for the reply . I am building a framework for the two error
conditions, therefore I need to read and readlines because in one only
regex is required and in other regex+ n-1 line is required to process :

#Here we are opening the file and substituting space " " for each \n
encountered
f3 = open  (r"D:\QI\log.log", 'r')
string = f3.read()
string1 = f3.readlines()
regex = re.compile ( "\n" )
st = regex.sub ( " ", string )

if re.search('ERR1',st):
y=re.findall("[A-Z][a-z][a-z] [ 123][0-9]
[012][0-9]:[0-5][0-9]:[0-5][0-9] [0-9][0-9][0-9][0-9]",st)
print y

patchnumber = re.compile(r'(\d+)\/(\d+)')==> doesnot
work it only works if I use  #string = f3.read()
for j in range(len(string1)):
if re.search ( r'ERR2', string1[j] ):
print "Error line \n", string1[j - 1]
mo = patchnumber.search (string1[j-1])
a = mo.group()
print a
print os.getcwd()
break

Please advice how to proceed.

Thanks,


On Sun, Nov 11, 2018 at 10:30 PM  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>1. Re: Require Python assistance (Alan Gauld)
>2. Re: Example for read and readlines() (Alan Gauld)
>3. Re: Example for read and readlines() (Alan Gauld)
>4. Re: Example for read and readlines() (Asad)
>5. Re: Example for read and readlines() (Alan Gauld)
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 09:53:23 +
> Subject: Re: [Tutor] Require Python assistance
> On 10/11/2018 18:10, Avi Gross wrote:
> > WARNING to any that care:
> >
> > As the following letter  is a repeat request without any hint they read
> the earlier comments here, I did a little searching and see very much the
> same request on another forum asking how to do this in MATLAB:
>
> The OP has also repeated posted the same message to this list
> (which I rejected as moderator).
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 10:00:33 +
> Subject: Re: [Tutor] Example for read and readlines()
> On 11/11/2018 06:49, Asad wrote:
> > Hi All ,
> >
> >  If I am loading a logfile what should I use from the option
> 1,2,3
> >
> > f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log",
> 'r' )
> >
> > 1) should only iterate over f3
>
> This is best for processing line by line which is the most
> common way to handle files. It saves memory and allows you
> to exit early, without reading the entire file if you are
> only looking for say a single entry.
>
> for line in file:
>if terminal_Condition: break
># process line here
>
> > 2) st = f3.read()
>
> The best solution if you want to process individual characters
> or small character groups. Also best if you want to process
> the entire file at once, for example using a regular expression
> which might span lines.
>
> > 3) st1 = f3.readlines()
>
> Mainly historical and superseded by iterating over the file.
> But sometimes useful if you need to do multiple passes over
> the lines since it only reads the file once. Very heavy
> memory footprint for big files.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 10:02:40 +
> Subject: Re: [Tutor] Example for read and readlines()
> On 11/11/2018 09:40, Steven D'Aprano wrote:
>
> >> f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log",
> 'r

[Tutor] How to create a html hyperlink for a document

2018-11-12 Thread Asad
Hi All ,

I am creating a python script to analyze the log and provide a
solution , in the solution part I want to include a document and create a
hyperlink to the document so that its clickable .
I have python 2.6.6 cannot use :hyperlink module because this is production
server and the module cannot be installed on it . Need some trick to create
it .

Please advice ,

Thanks,
-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] how to print lines which contain matching words or strings

2018-11-18 Thread Asad
Hi All ,

   I have a set of words and strings :

like :

p = [A ,"B is good" ,123456 , "C "]

I have a file in which I need to print only the lines which matches the
pattern in p

thanks,

-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to print lines which contain matching words or strings

2018-11-20 Thread Asad
Hi Avi Gross /All,

 Thanks for the reply. Yes you are correct , I would like to to
open a file and process a line at a time from the file and want to select
just lines that meet my criteria and print them while ignoring the rest. i
have created the following code :


   import re
   import os

   f3 = open(r'file1.txt',r)
   f = f3.readlines()
   d = []
   for linenum in range(len(f)):
if re.search("ERR-1" ,f[linenum])
   print f[linenum]
   break
if re.search("\d\d\d\d\d\d",f[linenum])   --- > seach for a patch
number length of six digits for example 123456
   print f[line]
   break
if re.search("Good Morning",f[linenum])
   print f[line]
   break
if re.search("Breakfast",f[linenum])
   print f[line]
   break
...
further 5 more hetrogeneus if conditions I have

===
This is beginners approach to print the lines which match the if conditions
.

How should I make it better may be create a dictionary of search items or a
list and then iterate over the lines in a file to print the lines matching
the condition.


Please advice ,

Thanks,

Previous email :
======

Asad,

As others have already pointed out, your request is far from clear.

Ignoring the strange use of words, and trying to get the gist of the
request, would this be close to what you wanted to say?

You have a file you want to open and process a line at a time. You want to
select just lines that meet your criteria and print them while ignoring the
rest.

So what are the criteria? It sounds like you have a list of criteria that
might be called patterns. Your example shows a heterogenous collection:

[A ,"B is good" ,123456 , "C "]

A is either an error or the name of a variable that contains something. We
might want a hint as searching for any old object makes no sense.

The second and fourth are exact strings. No special regular expression
pattern. Searching for them is trivial using normal string functionality.
Assuming they can be anywhere in a line:

>>> line1 = "Vitamin B is good for you and so is vitamin C"
>>> line2 = "Currently nonsensical."
>>> line3 = ""
>>> "B is good" in line1
True
>>> "B is good" in line2
False
>>> "B is good" in line3
False
>>> "C" in line1
True
>>> "C" in line2
True
>>> "C" in line2
True

To test everything in a list, you need code like for each line:

for whatever in [A ,"B is good" ,123456 , "C "]
If whatever in line: print(line)

Actually, the above could print multiple copies so you should break out
after any one matches.

123456 is a challenge to match. You could search for str(whatever) perhaps.

Enough. First explain what you really want.

If you want to do a more general search using regular expressions, then the
list of things to search for would be all the string in RE format. You could
search multiple times or use the OR operator carefully inside one regular
expression. You have not stated any need to tell what was matched or where
it is the line so that would be yet another story.

-Original Message-
From: Tutor  On Behalf Of
Asad
Sent: Sunday, November 18, 2018 10:19 AM
To: tutor@python.org
Subject: [Tutor] how to print lines which contain matching words or strings

Hi All ,

   I have a set of words and strings :

like :

p = [A ,"B is good" ,123456 , "C "]

I have a file in which I need to print only the lines which matches the
pattern in p

thanks,


On Tue, Nov 20, 2018 at 6:12 AM  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>1. Re: seeking beginners tutorial for async (Mats Wichmann)
>2. Re: seeking beginners tutorial for async (Bob Gailer)
>3. Re: how to print lines which contain matching words or
>   strings (Avi Gross)
>4. [Python 3] Threads status, join() and Semaphore queue
>   (Dimitar Ivanov)
>
>
>
> -- Forwarded message --
> From: Mats Wichmann 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Mon, 19 Nov 2018 10:05:35 -0700
> Subje

[Tutor] Search error code in a logfile and print all lines until the error code

2018-11-29 Thread Asad
Hi All ,

  I need some help to print error lines from a log file :

for example the following logfile :

SQL>
SQL> SET PAGESIZE 0
SQL> SELECT 'Starting apply for patch 26925263/21857460 on ' ||
  2 SYSTIMESTAMP FROM dual;
Starting apply for patch 26925263/21857460 on 28-JUN-18 07.46.34.893957 PM
-05:00

1 row selected.

SQL> SET PAGESIZE 10
SQL>
SQL> BEGIN
  2  dbms_sqlpatch.patch_initialize(p_patch_id  => 26925263,
  3 p_patch_uid => 21857460,
  4 p_flags => '&flags',
  5 p_description   => '&description',
  6 p_action=> 'APPLY',
  7 p_logfile   => '&full_logfile',
  8 p_bundle_series =>
'&bundle_series');
  9  END;
 10  /
BEGIN
*
ERROR at line 1:
ORA-20001: set_patch_metadata not called
ORA-06512: at "SYS.DBMS_SQLPATCH", line 647
ORA-06512: at line 2


SQL>
SQL> COLUMN install_file NEW_VALUE sql_script
SQL>
SQL>
SQL> ALTER SESSION SET CURRENT_SCHEMA = SYS;

Session altered.


So here I want to open the log file and find the error and print all the
lines from starting till the error : ORA-20001: set_patch_metadata not
called


f4 = open (r"file1.log", 'r')
string2=f4.readlines()
for i in range(len(string2)):
position=i
lastposition =position+1
while True:
 if re.search('ORA-20001: set_patch_metadata not
called',string2[lastposition]):
break
 elif lastposition==len(string2)-1:
 break
 else:
lastposition += 1
errorcheck=string2[position:lastposition]
 print errorcheck

It gives me error :

IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=100.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

the first for loop will search for the error and provide me the position of
the error .

I think the logic I am using is correct but need some expert comment to
make it work also some guidance on how to print all the lines until the
error is received .
Please advice,
-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] sftp using subprocess

2018-12-03 Thread Asad
Hi All ,

I am looking for a solution to automate downloading file using sftp
process using :

batch.txt :contains the following two lines
cd 12345678
get 12345678_1.zip


import subprocess
host="abc.com"
user="sa"
user_host="%s@%s" % (user, host)
sftp_process = subprocess.Popen(['sftp', '-b', 'batch.txt', user_host],
shell=False)

however it gives error even unable to provide password .

Please advise.

Thank you,
-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sftp using subprocess

2018-12-04 Thread Asad
Hi All,

I get the following error :

>>> sftp_process = subprocess.Popen(['sftp', '-b', 'batch.txt', user_host],
shell=False)
>>>

Permission denied (keyboard-interactive,publickey,password).
Connection closed

Is there any other way to acheive this because I cannot import pexcept
module .

Thanks,


>
>
> -- Forwarded message --
> From: David Rock 
> To: Tutor Python 
> Cc:
> Bcc:
> Date: Mon, 3 Dec 2018 18:12:05 -0600
> Subject: Re: [Tutor] sftp using subprocess
>
> > On Dec 3, 2018, at 16:01, Asad  wrote:
> >
> > Hi All ,
> >
> >I am looking for a solution to automate downloading file using
> sftp
> > process using :
> >
> > batch.txt :contains the following two lines
> > cd 12345678
> > get 12345678_1.zip
> >
> >
> > import subprocess
> > host="abc.com"
> > user="sa"
> > user_host="%s@%s" % (user, host)
> > sftp_process = subprocess.Popen(['sftp', '-b', 'batch.txt', user_host],
> > shell=False)
> >
> > however it gives error even unable to provide password .
>
> batch mode for sftp assumes you don’t need a password.  From the manage:
>
>  -b batchfile
>  Batch mode reads a series of commands from an input batchfile
> instead of stdin.
>  Since it lacks user interaction it should be used in
> conjunction with non-inter‐
>  active authentication.
>
> You would need to set up an ssh key with a null passphrase, or set up an
> ssh-agent in order for that to work.
>
> Another option would be to use pexpect to automate console input
>
>
> —
> David Rock
> da...@graniteweb.com
>
>
>
>
>
>
>
>
> -- Forwarded message --
> From: "Steven D'Aprano" 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Tue, 4 Dec 2018 11:12:56 +1100
> Subject: Re: [Tutor] sftp using subprocess
> On Tue, Dec 04, 2018 at 03:31:53AM +0530, Asad wrote:
>
> > however it gives error even unable to provide password .
>
> Is the error a secret? Would you like us to guess what it is?
>
>
> --
> Steve
>
> ___
> Tutor maillist  -  Tutor@python.org
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] sftp using subprocess

2018-12-04 Thread Asad
Hi All ,

   I am not allowed to import pexcept   .Therefore only option I
have is to implement a solution using the standard libraries in python .

However I am using subprocess.Popen for sftp I am unable to
pass the password.

I tried the following :

>>> import subprocess
>>> subprocess.Popen(['sftp','usern...@server.com', 'stop'],
stdin=PIPE).communicate(input='abc')


Enter password for username
Password:

  Here I am unable to proceed , I am sure someone would have cracked this
problem earlier if they can share the code

Thanks in advance,   .

On Tue, Dec 4, 2018 at 10:30 PM  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>1. Re: sftp using subprocess (Alan Gauld)
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Tue, 4 Dec 2018 08:41:03 +
> Subject: Re: [Tutor] sftp using subprocess
> On 04/12/2018 06:25, Asad wrote:
>
> > Permission denied (keyboard-interactive,publickey,password).
> > Connection closed
> >
> > Is there any other way to acheive this because I cannot import pexcept
> > module .
>
> That looks like the problem that David already highlighted
> with sftp.
>
> When you say you cannot import pexpect, is that because
> you are not allowed to? Or because of some technical issue?
> If so what? We might be able to help fix that.
>
> Also, you do realize that pexpect is not part of the
> standard library? You need to install it first.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] unzip and connect to Oracle database

2018-12-07 Thread Asad
Hi All ,

 I would like to unzip a file using python and then execute the sql
scripts  in the file on Oracle database .

 >>> from zipfile import ZipFile
>>> file_name = 'file.zip'
>>> z = ZipFile(file_name)
>>> print(z.namelist())
[]
>>> z = ZipFile('file.zip')
>>> print z.namelist()
[]
>>> print z

>>> z.extractall()
Doesnot unzip the zip file

I unable to unzip the file what I am doing wrong ?

Also share some code or documentation to connect to Oracle DB and execute
sql scripts.

Thanks,

-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Increase performance of the script

2018-12-09 Thread Asad
Hi All ,

  I have the following code to search for an error and prin the
solution .

/A/B/file1.log size may vary from 5MB -5 GB

f4 = open (r" /A/B/file1.log  ", 'r' )
string2=f4.readlines()
for i in range(len(string2)):
position=i
lastposition =position+1
while True:
 if re.search('Calling rdbms/admin',string2[lastposition]):
  break
 elif lastposition==len(string2)-1:
  break
 else:
  lastposition += 1
errorcheck=string2[position:lastposition]
for i in range ( len ( errorcheck ) ):
if re.search ( r'"error(.)*13?"', errorcheck[i] ):
print "Reason of error \n", errorcheck[i]
print "script \n" , string2[position]
print "block of code \n"
print errorcheck[i-3]
print errorcheck[i-2]
print errorcheck[i-1]
print errorcheck[i]
print "Solution :\n"
print "Verify the list of objects belonging to Database "
break
else:
continue
break

The problem I am facing in performance issue it takes some minutes to print
out the solution . Please advice if there can be performance enhancements
to this script .

Thanks,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Increase performance of the script

2018-12-11 Thread Asad
Hi All,

  I used your solution , however found a strange issue with deque :

I am using python 2.6.6:

>>> import collections
>>> d = collections.deque('abcdefg')
>>> print 'Deque:', d
  File "", line 1
print 'Deque:', d
 ^
SyntaxError: invalid syntax
>>> print ('Deque:', d)
Deque: deque(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
>>> print d
  File "", line 1
print d
  ^
SyntaxError: invalid syntax
>>> print (d)
deque(['a', 'b', 'c', 'd', 'e', 'f', 'g'])

In python 2.6 print statement work as print "Solution"

however after import collection I have to use print with print("Solution")
is this a known issue ?

Please let me know .

Thanks,

On Mon, Dec 10, 2018 at 10:30 PM  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>1. Re: Increase performance of the script (Peter Otten)
>    2. Re: Increase performance of the script (Steven D'Aprano)
>3. Re: Increase performance of the script (Steven D'Aprano)
>
>
>
> -- Forwarded message --
> From: Peter Otten <__pete...@web.de>
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 09 Dec 2018 21:17:53 +0100
> Subject: Re: [Tutor] Increase performance of the script
> Asad wrote:
>
> > Hi All ,
> >
> >   I have the following code to search for an error and prin the
> > solution .
> >
> > /A/B/file1.log size may vary from 5MB -5 GB
> >
> > f4 = open (r" /A/B/file1.log  ", 'r' )
> > string2=f4.readlines()
>
> Do not read the complete file into memory. Read one line at a time and
> keep
> only those lines around that you may have to look at again.
>
> > for i in range(len(string2)):
> > position=i
> > lastposition =position+1
> > while True:
> >  if re.search('Calling rdbms/admin',string2[lastposition]):
> >   break
> >  elif lastposition==len(string2)-1:
> >   break
> >  else:
> >   lastposition += 1
>
> You are trying to find a group of lines. The way you do it for a file of
> the
> structure
>
> foo
> bar
> baz
> end-of-group-1
> ham
> spam
> end-of-group-2
>
> you find the groups
>
> foo
> bar
> baz
> end-of-group-1
>
> bar
> baz
> end-of-group-1
>
> baz
> end-of-group-1
>
> ham
> spam
> end-of-group-2
>
> spam
> end-of-group-2
>
> That looks like a lot of redundancy which you can probably avoid. But
> wait...
>
>
> > errorcheck=string2[position:lastposition]
> > for i in range ( len ( errorcheck ) ):
> > if re.search ( r'"error(.)*13?"', errorcheck[i] ):
> > print "Reason of error \n", errorcheck[i]
> > print "script \n" , string2[position]
> > print "block of code \n"
> > print errorcheck[i-3]
> > print errorcheck[i-2]
> > print errorcheck[i-1]
> > print errorcheck[i]
> > print "Solution :\n"
> > print "Verify the list of objects belonging to Database "
> > break
> > else:
> > continue
> > break
>
> you throw away almost all the hard work to look for the line containing
> those four lines? It looks like you only need the
> "error...13" lines, the three lines that precede it and the last
> "Calling..." line occuring before the "error...13".
>
> > The problem I am facing in performance issue it takes some minutes to
> > print out the solution . Please advice if there can be performance
> > enhancements to this script .
>
> If you want to learn the Python way you should try hard to write your
> scripts without a single
>
> for i in range(...):
> ...
>
> loop. This style is usually the last resort, it may work fo

[Tutor] Re Module

2018-12-27 Thread Asad
Hi All ,

  I trying find a solution for my script , I have two files :

file1 - I need a search a error say x if the error matches

Look for the same error x in other file 2

Here is the code :
I have 10 different patterns therefore I used list comprehension and
compiling the pattern so I loop over and find the exact pattern matching

re_comp1 = [re.compile(pattern) for pattern in str1]

for pat in re_comp1:
if pat.search(st,re.IGNORECASE):
x = pat.pattern
print x===> here it gives the expected output it correct
match
print type(x)



if re.search('x', line, re.IGNORECASE) is not None:  ===> Gives a wrong
match
  print line

Instead if I use :

if re.search(x, line, re.IGNORECASE) is not None: then no match occurs
  print line

Please advice where I going wrong or what can be done to make it better .

Thanks,


-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Log file for Nested if-elif

2019-01-02 Thread Asad
Hi All ,

Need advice on the following piece of code :

with open(r"file1.log", 'r') as f:
tail = deque(maxlen=8)  # the last eight lines
script = None
for line in f:
tail.append(line)
if
re.search('\?/patch/\d{8}/\d{8}/admin/load.sql',line,re.IGNORECASE):
script = line
elif re.search(r'Starting\s+apply\s+for\s+patch\s+\d{8}/\d{8}',
line, re.IGNORECASE):
script = line
elif re.search(r'set_metadata', line ,re.IGNORECASE) is not None:
print "Reason of error \n", tail[-1]
print "Script:\n", script
print "Block of code:\n"
for item in tail:
 print item
print " Danger "
break
Now this is printing the last cached line in the variable line   . However
I would like to see the following output :

1) if it matches the pattern: \?/patch/\d{8}/\d{8}/admin/load.sql then

look for the line "set_metadata" in the file1.log  if it finds the pattern
then print the line which matches the pattern
\?/patch/\d{8}/\d{8}/admin/load.sql

print last 4 lines of the tail array  and exit

2) if it doesnot match '\?/patch/\d{8}/\d{8}/admin/load.sql'

then look of the anothern pattern
:Starting\s+apply\s+for\s+patch\s+\d{8}/\d{8} if it find the pattern

then look for line "set_metadata" in the file1.log  if it finds the pattern
then print the line which matches the pattern
\?/patch/\d{8}/\d{8}/admin/load.sql

print all the lines in tail

print a recommendation "Please check the installation"


3 ) if it doesnot match  the pattern: \?/patch/\d{8}/\d{8}/admin/load.sql
or '\?/patch/\d{8}/\d{8}/admin/load.sql'

print "No match found refer to install guide"

Can you advice what I can do to change the code .

Thanks,
--
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Log file for to search in order

2019-01-11 Thread Asad
Hi All ,

   Let me answer :


> Where are you looking? *Anywhere* in the log file?

>>Yes anywhere in the log file .


> Only in the immediate next line? Anywhere forward of the "patch" line?

>> Anywhere forward from the line which matches the search


> You are looking for two patterns, but does the order they appear, or the
> distance apart, matter?
>
>  Yes the order does matter :

  1)  first it looks for :  \?/patch/\d{8}/\d{8}/admin/load.sql
   - Condition if there are 10 lines containing the same pattern
then it should save and print the last line containing the pattern means
the 10th line
 - if it find the above string it start searching from that line
with successful match regex match until it gets to the line containing
set_metadata
   - Once it get the line containing set_metadata print last 4
lines prior to the line containing  set_metadata


 2)   if it doesnot find  the above pattern look for second in order
   :Starting\s+apply\s+for\s+patch\s+\d{8}/\d{8}
  - Condition if there are 10 lines containing the same pattern
then it should save and print the last line containing the pattern means
the 10th line
   -  if it find the above string it start searching from that line
with successful match regex match until it gets to the line containing
set_metadata
- Once it get the line containing set_metadata print last 10
lines prior to the line containing  set_metadata

3)  if it doesnot match  the pattern: \?/patch/\d{8}/\d{8}/admin/load.sql
or '\?/patch/\d{8}/\d{8}/admin/load.sql'  anywhere in the log file .

print "No match found refer to install guide"

4) If I have two errors how do I prioritize one above other ?


   Thanks,



>
> -- Forwarded message --
> From: Asad 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Wed, 2 Jan 2019 20:39:53 +0530
> Subject: [Tutor] Log file for Nested if-elif
> Hi All ,
>
> Need advice on the following piece of code :
>
> with open(r"file1.log", 'r') as f:
> tail = deque(maxlen=8)  # the last eight lines
> script = None
> for line in f:
> tail.append(line)
> if
> re.search('\?/patch/\d{8}/\d{8}/admin/load.sql',line,re.IGNORECASE):
> script = line
> elif re.search(r'Starting\s+apply\s+for\s+patch\s+\d{8}/\d{8}',
> line, re.IGNORECASE):
> script = line
> elif re.search(r'set_metadata', line ,re.IGNORECASE) is not None:
> print "Reason of error \n", tail[-1]
> print "Script:\n", script
> print "Block of code:\n"
> for item in tail:
>  print item
> print " Danger "
> break
> Now this is printing the last cached line in the variable line   . However
> I would like to see the following output :
>
> 1) if it matches the pattern: \?/patch/\d{8}/\d{8}/admin/load.sql then
>
> look for the line "set_metadata" in the file1.log  if it finds the pattern
> then print the line which matches the pattern
> \?/patch/\d{8}/\d{8}/admin/load.sql
>
> print last 4 lines of the tail array  and exit
>
> 2) if it doesnot match '\?/patch/\d{8}/\d{8}/admin/load.sql'
>
> then look of the anothern pattern
> :Starting\s+apply\s+for\s+patch\s+\d{8}/\d{8} if it find the pattern
>
> then look for line "set_metadata" in the file1.log  if it finds the pattern
> then print the line which matches the pattern
> \?/patch/\d{8}/\d{8}/admin/load.sql
>
> print all the lines in tail
>
> print a recommendation "Please check the installation"
>
>
> 3 ) if it doesnot match  the pattern: \?/patch/\d{8}/\d{8}/admin/load.sql
> or '\?/patch/\d{8}/\d{8}/admin/load.sql'
>
> print "No match found refer to install guide"
>
> Can you advice what I can do to change the code .
>
> Thanks,
> --
>
>
>
>
> -- Forwarded message --
> From: "Steven D'Aprano" 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Thu, 3 Jan 2019 15:16:45 +1100
> Subject: Re: [Tutor] Log file for Nested if-elif
> On Wed, Jan 02, 2019 at 08:39:53PM +0530, Asad wrote:
> > Hi All ,
> >
> > Need advice on the following piece of code :
>
> Let me write it in a more "Pythonic" style:
>
>
>
> PATCH = r'\?/patch/\d{8}/\d{8}/admin/load.sql'
> APPLY = r'Starting\s+apply\s+for\s+patch\s+\d{8}/\d{8}'
> ERROR = r'set_metadata'
>
> tail = deque(maxlen=8)  # the last eight lines
> script = None
> with open("file1.log", 'r') as

[Tutor] python - files

2019-01-26 Thread Asad
Hi All ,

   I would like to know how do I make and option file as an argument on
command propmnt in python .

   At present I using :

  if len(sys.argv) == 3:
first = sys.argv[1]
second = sys.argv[2]
  else:

print "enter the second argument"
It works well for the following command :
python test.py file1 file2

However I have another case where only file1 may be present so file1 is
mandatory for this script to run however file2 is optionnal :


  if len(sys.argv) == 2:
first_log = sys.argv[1]
second_log = sys.argv[2]

pthon test.py file1

It gives error :

   second_log = sys.argv[2]
IndexError: list index out of range


How do I acheive this because if python test.py file1 file2   then I would
process both files .

If python test.py file1  is given then I would process file1 using the
variable first_log .


Please advice .

Thanks,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python-files

2019-01-27 Thread Asad
orrected.
>
> >Your custom logic
> [...]
> >can roughly be replicated with the two lines
> >
> >parser.add_argument("first")
> >parser.add_argument("second", nargs="?")
> >[... extended example ...]
>
> Thank you!
>
> Cheers,
> Cameron Simpson 
>
>
>
>
> -- Forwarded message --
> From: Marco Mistroni 
> To: mhysnm1...@gmail.com
> Cc: tutor@python.org
> Bcc:
> Date: Sun, 27 Jan 2019 10:46:06 +
> Subject: Re: [Tutor] Web scraping using selenium and navigating nested
> dictionaries / lists.
> Hi my 2 cents. Have a look at scrapy for scraping.selenium is v good  tool
> to learn but is mainly to automate uat of guis
> Scrapy will scrape for you and u can automate it via cron. It's same stuff
> I am doing ATM
> Hth
>
> On Sun, Jan 27, 2019, 8:34 AM 
> > All,
> >
> >
> >
> > Goal of new project.
> >
> > I want to scrape all my books from Audible.com that I have purchased.
> > Eventually I want to export this as a CSV file or maybe Json. I have not
> > got
> > that far yet. The reasoning behind this is to  learn selenium  for my
> work
> > and get the list of books I have purchased. Killing two birds with one
> > stone
> > here. The work focus is to see if selenium   can automate some of the
> > testing I have to do and collect useful information from the web page for
> > my
> > reports. This part of the goal is in the future. As I need to build my
> > python skills up.
> >
> >
> >
> > Thus far, I have been successful in logging into Audible and showing the
> > library of books. I am able to store the table of books and want to use
> > BeautifulSoup to extract the relevant information. Information I will
> want
> > from the table is:
> >
> > *   Author
> > *   Title
> > *   Date purchased
> > *   Length
> > *   Is the book in a series (there is a link for this)
> > *   Link to the page storing the publish details.
> > *   Download link
> >
> > Hopefully this has given you enough information on what I am trying to
> > achieve at this stage. AS I learn more about what I am doing, I am adding
> > possible extra's tasks. Such as verifying if I have the book already
> > download via itunes.
> >
> >
> >
> > Learning goals:
> >
> > Using the BeautifulSoup  structure that I have extracted from the page
> > source for the table. I want to navigate the tree structure.
> BeautifulSoup
> > provides children, siblings and parents methods. This is where I get
> stuck
> > with programming logic. BeautifulSoup does provide find_all method plus
> > selectors which I do not want to use for this exercise. As I want to
> learn
> > how to walk a tree starting at the root and visiting each node of the
> tree.
> > Then I can look at the attributes for the tag as I go. I believe I have
> to
> > set up a recursive loop or function call. Not sure on how to do this.
> > Pseudo
> > code:
> >
> >
> >
> > Build table structure
> >
> > Start at the root node.
> >
> > Check to see if there is any children.
> >
> > Pass first child to function.
> >
> > Print attributes for tag at this level
> >
> > In function, check for any sibling nodes.
> >
> > If exist, call function again
> >
> > If no siblings, then start at first sibling and get its child.
> >
> >
> >
> > This is where I get struck. Each sibling can have children and they can
> > have
> > siblings. So how do I ensure I visit each node in the tree?
> >
> > Any tips or tricks for this would be grateful. As I could use this in
> other
> > situations.
> >
> >
> >
> > Sean
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
>
> ___
> Tutor maillist  -  Tutor@python.org
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Webinterface for python script

2019-01-30 Thread Asad
Hi All ,

  I have created certain python scripts to analyze log files and
suggest solution based on logic which I invoke on the command line . I need
some information on how to execute these through browser . I am using :

python test.py file1 file2

How do I use the browser to upload the files file1 and file2 and it process
the files .

Please advice ,

Thanks,



--
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Visual studio Code -Python

2019-02-17 Thread Asad
Hi All ,

I am using Visual Studio Code for Python . However I was using
the debug option F5 i see it list the variables in my program neatly ,I set
breakpoints it stops there  but I am unable  to preview each line of the
execution of the code .

Thanks,
--
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Visual studio Code -Python

2019-02-23 Thread Asad
Hi All ,

 I am using : pdb.set_trace()

  can you all share some good tricks i using n ,s , l . The tedious
part which I see is  if it is a loop like for loop then I need to do next
till the length for the data is completed

for x in string :
 if re.search(x,line)

len(string)
= 2500

therefore I need to press n 2500 time so that the loop completes and goes
to another line of code . Any suggestions? how can run the for loop without
doing n for 2500 times ?

Thanks,

On Sun, Feb 17, 2019 at 8:58 PM Mats Wichmann  wrote:

> On 2/17/19 1:50 AM, Asad wrote:
> > Hi All ,
> >
> > I am using Visual Studio Code for Python . However I was
> using
> > the debug option F5 i see it list the variables in my program neatly ,I
> set
> > breakpoints it stops there  but I am unable  to preview each line of the
> > execution of the code .
> >
> > Thanks,
>
> You'll need to go to the source for that... the Python extension should
> have limited instructions, and a bunch of pointers for where to go find
> out more, and some animations that intend to show how things work.
>
> Best of luck!
>
>
>

-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to create a structure from a Log file

2019-03-09 Thread Asad
Hi All ,

   I would like to know , how can I approach this problem to create
a easy structure from the logfile using python so I can review the logfiles
quite efficiently . Please share suggestion tip or already written codes.



Thanks,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to create a structure from a Log file

2019-03-09 Thread Asad
Hi All ,

 Please a sample logfile

[main] [ 2019-01-21 10:13:14.041 CET ]
[AssistantLogHandler.configureLogging:176]  Begin tracing..
INFO: Jan 21, 2019 10:13:14 AM oracle.assistants.dbua.driver.UpgradeDriver
configureLogging
INFO: Loading upgrade driver,
 DBUA running in mode : NONE
 DBUA running on platform : Linux


[main] [ 2019-01-21 10:13:14.237 CET ]
[ClusterVerification.getInstance:553]  Method Entry. workDir=/tmp
frameworkHome=/u01/app/oracle/product/12.2.0.1/dbhome_1
[main] [ 2019-01-21 10:13:14.289 CET ] [CVUVariables.initialize:1456]
Start parse all variables from variables.xml...
[main] [ 2019-01-21 10:13:14.304 CET ]
[VerificationUtil.getVariablesXmlURI:10687]    XML variables file:
file:/u01/app/oracle/product/12.2.0.1/dbhome_1/cv/cvdata/variables.xml
[main] [ 2019-01-21 10:13:14.305 CET ]
[VerificationUtil.getVariablesXmlSchemaURI:10669]   XML variables
schema file: file:/u01/app/oracle/product/
12.2.0.1/dbhome_1/cv/cvdata/variables.xsd
[main] [ 2019-01-21 10:13:14.305 CET ] [CVUVariables.getRootElement:1721]
 URIs obtained :xsd URI = file:/u01/app/oracle/product/
12.2.0.1/dbhome_1/cv/cvdata/variables.xsd
[main] [ 2019-01-21 10:13:14.306 CET ] [CVUVariables.getRootElement:1722]
 URIs obtained :xml URI = file:/u01/app/oracle/product/
12.2.0.1/dbhome_1/cv/cvdata/variables.xml
[main] [ 2019-01-21 10:13:14.306 CET ] [CVUVariables.getRootElement:1735]
xsdFile exists : file:/u01/app/oracle/product/
12.2.0.1/dbhome_1/cv/cvdata/variables.xsd
[main] [ 2019-01-21 10:13:14.307 CET ] [CVUVariables.getRootElement:1750]
xmlFile exists : file:/u01/app/oracle/product/
12.2.0.1/dbhome_1/cv/cvdata/variables.xml
[main] [ 2019-01-21 10:13:14.307 CET ] [CVUVariables.getRootElement:1763]
setting xmlFactory to use xsdFile : file:/u01/app/oracle/product/
12.2.0.1/dbhome_1/cv/cvdata/variables.xsd
[main] [ 2019-01-21 10:13:14.408 CET ] [CVUVariables.getRootElement:1794]
The xml variables file: file:/u01/app/oracle/product/
12.2.0.1/dbhome_1/cv/cvdata/variables.xml, was parsed correctly
[main] [ 2019-01-21 10:13:14.410 CET ] [CVUVariables.parse:1521]  Version
found ALL
[main] [ 2019-01-21 10:13:14.411 CET ] [CVUVariables.parse:1524]  Process
common variables
[main] [ 2019-01-21 10:13:14.415 CET ] [CVUVariableData.:98]
CVUVariableData created with names:  "s_silent,SILENT"
[main] [ 2019-01-21 10:13:14.416 CET ] [CVUVariables.parse:1521]  Version
found 12.2
[main] [ 2019-01-21 10:13:14.416 CET ] [CVUVariables.parse:1529]  Process
variables for the release: 12.2
[main] [ 2019-01-21 10:13:14.418 CET ] [CVUVariableData.:98]
CVUVariableData created with names:


I was thinking to convert it in a excel format  or any other format which
better viewable

Thanks,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to create a structure from a Log file

2019-03-11 Thread Asad
Hi All ,

   I think this format would be easy in a row and table format

Date Time  Message
1/21/2019 10:13:14.237 CET Method Entry. workDir=/tmp
frameworkHome=/u01/app/oracle/product/12.2.0.1/dbhome_1
I was also thinking of pandas but not sure how to proceed .

Thanks,

On Sun, Mar 10, 2019 at 7:47 PM Bob Gailer  wrote:

> Thank you for showing us a sample of the log file. That is half the
> battle. Would you now reformat a couple of the lines so that we can see how
> you'd like to see them.
>
> It also may be the case that the advice given by others will be sufficient
> to guide you
>


-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to store output of Python program in XML

2019-07-13 Thread Asad
Hi All ,

   I written a python script which opens a logfile and searches for
error and based or error found it prints  a solution to screen , instead I
want to print the output of the script in a xml file so that I can add some
tags . How can it be done ?

Thanks,
-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor