Help with python code!
Hi - I am a newbie to python and was wondering can someone tell me what the
following code does. I need to figure out how to test it
import time
import glob
import re
import os
current_time = time.time() + 60*60+24*30
dirList = glob.glob('\content\paytek\ejbProperties\cybersource\*.crt')
q = re.compile('^Owner:.*CN=([^\s\,]+)')
p = re.compile('until: (\w+) (\w+) (\d+) (\d+):(\d+):(\d+) \w+ (\d+)')
cert_name = ""
days = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6}
months = {"Jan":1, "Feb":2, "Mar":3, "Apr":4,
"May":5, "Jun":6, "Jul":7, "Aug":8,
"Sep":9, "Oct":10, "Nov":11, "Dec":12}
for fname in dirList:
cmd = "keytool printcert file " + fname
for line in os.popen(cmd).readlines():
line = line.rstrip()
m = p.search(line)
if m:
sue = time.mktime(
(int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
int(m.group(4)), int(m.group(5)), int(m.group(6)),
int(days[m.group(1)]), 0, 0)
)
expire_time = (sue current_time)/60/60/24
if expire_time < 0:
print cert_name + " has already expired!"
elif expire_time < 31:
print cert_name + " expires in " +str(int(expire_time)) + " days"
else:
m = q.search(line)
if m:
cert_name = m.group(1)
Im used to C# so the syntax looks bizarre to me! Any help would be great.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Help with python code!
On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote:
> On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote:
>
> > Im used to C# so the syntax looks bizarre to me! Any help would be great.
>
>
>
> The first thing you'll need to understand about Python syntax is that
>
> indentation is important. By posting this code flush-left, you've
>
> actually destroyed its block structure. Could you post it again, with
>
> indentation, please? We'd then be in a much better position to help.
>
>
>
> Chris Angelico
Hi Chris, thanks for your reply. See code below...
import time
import glob
import re
import os
current_time = time.time() + 60*60+24*30
dirList = glob.glob('\content\paytek\ejbProperties\cybersource\*.crt')
q = re.compile('^Owner:.*CN=([^\s\,]+)')
p = re.compile('until: (\w+) (\w+) (\d+) (\d+):(\d+):(\d+) \w+ (\d+)')
cert_name = ""
days = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6}
months = {"Jan":1, "Feb":2, "Mar":3, "Apr":4,
"May":5, "Jun":6, "Jul":7, "Aug":8,
"Sep":9, "Oct":10, "Nov":11, "Dec":12}
for fname in dirList:
cmd = "keytool printcert file " + fname
for line in os.popen(cmd).readlines():
line = line.rstrip()
m = p.search(line)
if m:
sue = time.mktime(
(int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
int(m.group(4)), int(m.group(5)), int(m.group(6)),
int(days[m.group(1)]), 0, 0)
)
expire_time = (sue current_time)/60/60/24
if expire_time < 0:
print cert_name + " has already expired!"
elif expire_time < 31:
print cert_name + " expires in " +str(int(expire_time)) + " days"
else:
m = q.search(line)
if m:
cert_name = m.group(1)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Help with python code!
On Sunday, March 31, 2013 5:13:49 PM UTC-4, Roy Smith wrote: > In article <[email protected]>, > > jojo wrote: > > > > > for fname in dirList: > > > cmd = "keytool �printcert �file " + fname > > > for line in os.popen(cmd).readlines(): > > >line = line.rstrip() > > >m = p.search(line) > > >if m: > > > sue = time.mktime( > > > (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), > > > int(m.group(4)), int(m.group(5)), int(m.group(6)), > > > int(days[m.group(1)]), 0, 0) > > > ) > > > expire_time = (sue � current_time)/60/60/24 > > > if expire_time < 0: > > > print cert_name + " has already expired!" > > > elif expire_time < 31: > > > print cert_name + " expires in " +str(int(expire_time)) + " days" > > >else: > > > m = q.search(line) > > > if m: > > > cert_name = m.group(1) > > > > Was this code really indented like this when you got it? You've got (at > > least) three different indent sizes. I see 1, 2, and 3 space indents in > > different places in the code. > > > > I'm not even sure if this is legal, but even if it is, it's really bad > > form. Pick an indent, and stick with it uniformly. 4 spaces seems to > > be pretty standard. > > > > That being said, I'm going to return to my previous statement that until > > you know what the code is *supposed* to do, trying to test it is > > meaningless. Hi Rob. Thanks for your replies. Just to be clear this is for a interview and they would like me to figure out what the code does and come back with some test cases. I don't need to code the tests, just give some high level tests. As far as I can make out it is some system where you input your name and it will bring back your details plus how much time you have left on your card. Have to say I find the code extremely confusing, hopefully all python isn't like this!! -- http://mail.python.org/mailman/listinfo/python-list
How to sort using hash's key?
Hello, I want to sort a dict via its key,but I have no idea on how to do it. Please help me,thanks. --- 3webXS HiSpeed Dial-up...surf up to 5x faster than regular dial-up alone... just $14.90/mo...visit www.get3web.com for details -- http://mail.python.org/mailman/listinfo/python-list
web programming with Python
Hello, Is there a Quick Reference for Python web programming? Thank you. --Jojo --- 3webXS High Speed Cable or DSL Internet...surf at speeds up to 3.0 Mbps for as low as $24.95/mo...visit www.get3web.com for details -- http://mail.python.org/mailman/listinfo/python-list
recording input/outputs, attributes and parameters of modules
i would like to track all inputs/output to modules/functions -if a module retrieved and used files and run some analysis on them and produced other files in return, i would like to take not of this. i.e what i want is to record all input sand outputs to a module. and also to record all parameters, attribute vaules used by the same module and also would like to know how one module calls another whether it instantiates classes from one module etc Any help will be highly appreciated.. Jojo -- http://mail.python.org/mailman/listinfo/python-list
