Re: [Tutor] If you don't close file when writing, do bytes stay in memory?

2009-10-09 Thread Oxymoron
(Did not do a reply-all earlier)

On Sat, Oct 10, 2009 at 3:20 PM, xbmuncher  wrote:
> Which piece of code will conserve more memory?
>  I think that code #2 will because I close the file more often, thus freeing
> more memory by closing it.
> Am I right in this thinking... or does it not save me any more bytes in
> memory by closing the file often?

In general, you should only close a file once you're done with writing
all the data you need. Opening and closing after each write within a
loop is unnecessarily costly, as it usually translates to multiple
system calls. Thus the general pattern is:

open file
while have stuff to do:
  do stuff, read/write file
finally close file

(As an aside, you can also check out the 'with' statement in Python
2.5+ that'll handle the closing.)

With regard to memory consumption, there are 2 issues to be considered:

1. An open file handle obviously takes up some memory space, but this
is (usually) insignificant in comparison to actual data being
read/written, in your example the actual bytes. Not that you shouldn't
worry about keeping too many file descriptors open, there are limits
per process/user depending on the OS on the number of file
descriptors/handles that can be open at any one time.

2. The data itself, if the data is in memory, say from a list, etc.
obviously that takes up space, adding to the memory consumed by your
program. This is where Python's garbage collection (GC) comes in
handy. I am not familiar with the exact type of GC the CPython
interpreter uses, but as a general rule, if you scope your data to
just where it's needed, e.g. within functions, etc. and it is not
accidentally referred to from somewhere else for reference-able types
(e.g. lists), then once the function or code block is complete, the
memory will be reclaimed by Python. This is also a good reason to
avoid global variables, or limit them to things like constants, or
overall configuration, or items that are reused many times across the
application (e.g. caching). Otherwise, the memory remains for the
lifetime of the program even if your code does not use the data.

So point 2, the actual data items, lists, variables etc. are more
significant in terms of memory, in comparison to file handles. In your
example, the data is produced by getData(), so is only created as
necessary, but let's say you did:

x = getData()

x is a global, and is no longer ever used except maybe once - since it
is in scope, the memory remains. (Strings are of course immutable and
often cached by Python once created so this may be a moot point for
string data.)

Hope that helps.


-- Kamal

-- 
There is more to life than increasing its speed.
 -- Mahatma Gandhi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] If you don't close file when writing, do bytes stay in memory?

2009-10-09 Thread xbmuncher
Which piece of code will conserve more memory?
 I think that code #2 will because I close the file more often, thus freeing
more memory by closing it.
Am I right in this thinking... or does it not save me any more bytes in
memory by closing the file often?
Sure I realize that in my example it doesn't save much if it does... but I'm
dealing with writing large files.. so every byte freed in memory counts.
Thanks.

CODE #1:
def getData(): return '12345' #5 bytes
f = open('file.ext', 'wb')
for i in range(2000):
f.write(getData())

f.close()


CODE #2:
def getData(): return '12345' #5 bytes
f = open('file.ext', 'wb')
for i in range(2000):
f.write(getData())
if i == 5:
f.close()
f = open('file.ext', 'ab')
i = 1
i = i + 1

f.close()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Glen Zangirolami
Thats for all the responses. I'm going to use Kents method. I'll let you
know what I work out.
Rudiger - I did think about that. Luckily I am generating the list with a
start datetime and end datetime so if those don't exist
in either end if the list I can insert them after I check the dates between.


On Fri, Oct 9, 2009 at 5:11 PM, Rüdiger Wolf <
rudiger.w...@throughputfocus.com> wrote:

> Ah! but are we sure that the max and min dates are actually in the list?
> If there are 'missing dates' it might just be possible that it is the
> max or min date that is missing.
>
> On Fri, 09 Oct 2009 16:43 -0400, "Kent Johnson"  wrote:
> > On Fri, Oct 9, 2009 at 3:16 PM, Glen Zangirolami  >
> > wrote:
> > > If i have a list of dates:
> > > date_list =
> > >
> ['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']
> > > How do I find the missing dates in the range of dates and insert them
> into
> > > the list so I get?
> > > date_list =
> > >
> ['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']
> >
> > I would do something like the following using datetime.datetime and
> > datetime.timedelta:
> > - convert each list item to a datetime object using datetime.strptime()
> > - find the min and max datetimes in the list (use min() and max()
> > - create a new list by incrementing the min date by timedelta(days=1)
> > until it hits the max date
> > - convert the new list to strings using datetime.strftime()
> >
> > Kent
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Rüdiger Wolf
Ah! but are we sure that the max and min dates are actually in the list?
If there are 'missing dates' it might just be possible that it is the
max or min date that is missing.

On Fri, 09 Oct 2009 16:43 -0400, "Kent Johnson"  wrote:
> On Fri, Oct 9, 2009 at 3:16 PM, Glen Zangirolami 
> wrote:
> > If i have a list of dates:
> > date_list =
> > ['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']
> > How do I find the missing dates in the range of dates and insert them into
> > the list so I get?
> > date_list =
> > ['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']
> 
> I would do something like the following using datetime.datetime and
> datetime.timedelta:
> - convert each list item to a datetime object using datetime.strptime()
> - find the min and max datetimes in the list (use min() and max()
> - create a new list by incrementing the min date by timedelta(days=1)
> until it hits the max date
> - convert the new list to strings using datetime.strftime()
> 
> Kent

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


Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 3:16 PM, Glen Zangirolami  wrote:
> If i have a list of dates:
> date_list =
> ['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']
> How do I find the missing dates in the range of dates and insert them into
> the list so I get?
> date_list =
> ['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']

I would do something like the following using datetime.datetime and
datetime.timedelta:
- convert each list item to a datetime object using datetime.strptime()
- find the min and max datetimes in the list (use min() and max()
- create a new list by incrementing the min date by timedelta(days=1)
until it hits the max date
- convert the new list to strings using datetime.strftime()

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


Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Tim Golden

Glen Zangirolami wrote:

If i have a list of dates:date_list =
['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']

How do I find the missing dates in the range of dates and insert them into
the list so I get?
date_list =
['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']

Hopefully the case is that I haven't found the correct python module that
does it ;)



I'd be inclined to combine datetime.strptime
with a date-ranging function and some set work.

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


Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Wayne
On Fri, Oct 9, 2009 at 2:16 PM, Glen Zangirolami wrote:

> If i have a list of dates:date_list =
> ['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']
>
> How do I find the missing dates in the range of dates and insert them into
> the list so I get?
> date_list =
> ['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']
>
> Hopefully the case is that I haven't found the correct python module that
> does it ;)
>

The datetime module exists... you could easily write a function that does
something along the lines of:

def date_range(startdate, enddate):
 #do something here to make a range of dates

though you may want to write a function that checks for a missing date
first.

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


[Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Glen Zangirolami
If i have a list of dates:date_list =
['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']

How do I find the missing dates in the range of dates and insert them into
the list so I get?
date_list =
['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']

Hopefully the case is that I haven't found the correct python module that
does it ;)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Troubles with lists and control flow

2009-10-09 Thread Eduardo Vieira
On Thu, Oct 8, 2009 at 3:36 PM, Luke Paireepinart
 wrote:
> Oops, accidentally replied off-list.
>
> -- Forwarded message --
> From: Luke Paireepinart 
> Date: Thu, Oct 8, 2009 at 3:36 PM
> Subject: Re: [Tutor] Troubles with lists and control flow
> To: Eduardo Vieira 
>
>
>
>
> On Thu, Oct 8, 2009 at 2:42 PM, Eduardo Vieira 
> wrote:
>>
>> Hello I'm developing a script to compare two files, finding duplicate
>> entries and matching which id of one csv file corresponds to the id of
>> another csv file.
>> The first version was working nice, but I wanted to postpone the
>> writing to a file till the end and also make a correct csv file. The
>> code is not so great and I expect to work with no more than 3000 lines
>> of data in either file:
>> So here is the inicial code. I hope it's not too long or complicated:
>
> It's a little long to be in a message body, it'd have been nice if you
> posted to pastebin and chosen Python so we could have seen it with syntax
> highlighting and it would guarantee it doesn't mess up your indentation, but
> it's fine for now.  Just keep that in mind for longer code samples.
>
>>
>> def inbv(currentline = None):
>>    """writes a line of data when a date is found in BV"""
>>    if currentline is None:
>>        currentline = []
>>    else:
>>        currentline.append(item['USER_ID'])
>>        currentline.append(row['CUS_NO'])
>>        currentline.append(item['COMPANY'])
>>        currentline.append(row['BVADDR1'])
>>        currentline.append(item['ADDRESSLINEONE'])
>>        currentline.append(row['BVADDRTELNO1'])
>>        currentline.append(item['PHONE'])
>>        currentline.append(row['BVCITY'])
>>        currentline.append(item['CITY'])
>>
>>    return currentline
>
> You don't want to do it like this.
> What you're saying is:
> "if they didn't pass in an argument to my function, create a new list and
> return an empty list.  otherwise, if they did pass in a list, append an item
> and return the new list."  What you really want to do is "if they didn't
> pass in a list, create a new one.  Then append a value and return  the new
> list."  There's a subtle difference, do you see it? You want to add an item
> to the list whether or not they passed in a list in the first place, you
> just want to initialize a new list first.  Think about your code and how you
> can change it to do that.
>
> At least I think that's what your issue is, I don't really understand your
> code at all.
>
> Also:
>>
>> def notinbv(currentline):
>>    if currentline is None:
>>        currentline = []
>
> You should go ahead and define this one the same as the previous one (with
> the optional currentline parameter) unless you left it out on purpose.
>
> -Luke
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

Thanks Luke. I corrected my function, but I didn't have any good
result. In other words, the problem wasn't there.
The problem was with my control flow... I was using a "break" under
the else clause. I often get confused with control flow things...
Well, the 'else' clause on a for loop is always executed when there is
no "break" triggered in the loop. So, that "break" under the else was
not necessary ... and was not present in my first version too... copy
and paste error, I guess.

Eduardo
www.expresssignproducts.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
On Fri, Oct 9, 2009 at 11:02 PM, Kent Johnson  wrote:
> On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik  wrote:
>
> You can easily keep track of the previous item by assigning it to a
> variable. For example this shows just the increasing elements of a
> sequence:
>
> In [22]: items = [0, 1, 3, 2, 8, 5, 9 ]
>
> In [23]: last = None
>
> In [24]: for item in items:
>   :     if last is None or item > last:
>   :         print item
>   :     last = item

Darn... this is what happens when you're stuck on one solution
(referring to my index-only ways in the last post) - you miss other
obvious ways, duh * 10. Apologies for the unnecessarily complicated
exposition on iterables above. :-(



-- 
There is more to life than increasing its speed.
 -- Mahatma Gandhi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] for loop issue

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik  wrote:
> Hi,
>
> This feels like a strange issue, so i hope I formulate this so its
> understandable.
>
> I have some objects. Each object has associated values. I am looping
> through these objects, working with a value and printing out the
> value.
> The issue in this case is that i need to check if the one value
> superseeds the other, and in that case, not print it out. I think the
> problem is that when you are in the loop, you dont know about the
> other object that you havent processed yet, and when you are
> processing that object, you dont know about the previous one?  (not
> 100% sure if this assumption is correct)

You can easily keep track of the previous item by assigning it to a
variable. For example this shows just the increasing elements of a
sequence:

In [22]: items = [0, 1, 3, 2, 8, 5, 9 ]

In [23]: last = None

In [24]: for item in items:
   : if last is None or item > last:
   : print item
   : last = item

0
1
3
8
9
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list comprehensions

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 1:21 AM, wesley chun  wrote:

> [generator expressions] are
> "lazy" because you iterate over the values one at a time instead of
> creating the entire list. they are slightly slower but save memory.

I don't think you can make a blanket statement comparing speed of list
comp vs genexp. For example:

kent $ py -m timeit 'sum(x for x in xrange(1,1000) if x%3==0 or x%5==0)'
1000 loops, best of 3: 295 usec per loop
kent $ py -m timeit 'sum([x for x in xrange(1,1000) if x%3==0 or x%5==0])'
1000 loops, best of 3: 281 usec per loop

Here list comp is a bit faster.

kent $ py -m timeit 'sum(x for x in xrange(1,1) if x%3==0 or x%5==0)'
100 loops, best of 3: 2.83 msec per loop
kent $ py -m timeit 'sum([x for x in xrange(1,1) if x%3==0 or x%5==0])'
100 loops, best of 3: 2.85 msec per loop

Here they are neck and neck.

kent $ py -m timeit 'sum(x for x in xrange(1,10) if x%3==0 or x%5==0)'
10 loops, best of 3: 28.9 msec per loop
kent $ py -m timeit 'sum([x for x in xrange(1,10) if x%3==0 or x%5==0])'
10 loops, best of 3: 29.4 msec per loop

genexp pulls in to the lead.

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


Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
On Fri, Oct 9, 2009 at 9:35 PM, Oxymoron  wrote:
> Thus, you can muck around with x[i] (current item), and x[i+1] (next
> item), and decide how you want to proceed with the loop. Note the use
> of len(x) - 1 rather than just len(x) to easily prevent an IndexError
> or extra special case logic.

"easily prevent an IndexError without extra special case logic". It's
been a long week.

-- Kamal

-- 
There is more to life than increasing its speed.
 -- Mahatma Gandhi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
Hello,

On Fri, Oct 9, 2009 at 6:54 PM, Stefan Lesicnik  wrote:
> The issue in this case is that i need to check if the one value
> superseeds the other, and in that case, not print it out. I think the
> problem is that when you are in the loop, you dont know about the
> other object that you havent processed yet, and when you are
> processing that object, you dont know about the previous one?  (not
> 100% sure if this assumption is correct)

If I understand correctly, the items are basically in the same
collection that you're looping over. And you need to know an item
after/before the current one being iterated over.

Whether you can do this or not (or do it easily!) really depends on
what sort of sequence you are iterating over, if it's something
in-memory like a list or a tuple, it's easy, instead of iterating over
the actual items in the collection, you iterate their indexes, let's
assume your items are inside a list x:

x = ['foo', 'bar', 'baz', 'spam']
for i in xrange(0, len(x)-1):
print x[i], x[i+1]

Thus, you can muck around with x[i] (current item), and x[i+1] (next
item), and decide how you want to proceed with the loop. Note the use
of len(x) - 1 rather than just len(x) to easily prevent an IndexError
or extra special case logic.

Now, if what you're looping over is something that just follows the
iteration protocol (i.e. something you can iterate over), it may not
know or support knowing the length (look up the __len__ special method
for more info) of the items in advance, i.e. len(iterable_obj) fails.
An example of this is the file handle, which allows you to iterate
through lines in the file, but attempting to do a  len(handle), e.g.:

>>> f = open('foo.txt')
>>> len(f)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: object of type 'file' has no len()

fails.

In this case, the simplest thing is to first read in the items into an
in-memory structure like a list or tuple, then use the index iteration
method above. If not all data can fit into memory, then it is time to
wrack your brains some more, I suspect you won't have to go that far
for now though :-).

Ask away if this is unclear or I got your problem description wrong.

-- Kamal

-- 
There is more to life than increasing its speed.
 -- Mahatma Gandhi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] for loop issue

2009-10-09 Thread Adam Bark
2009/10/9 Stefan Lesicnik 

Hi,
>
> This feels like a strange issue, so i hope I formulate this so its
> understandable.
>
> I have some objects. Each object has associated values. I am looping
> through these objects, working with a value and printing out the
> value.
> The issue in this case is that i need to check if the one value
> superseeds the other, and in that case, not print it out. I think the
> problem is that when you are in the loop, you dont know about the
> other object that you havent processed yet, and when you are
> processing that object, you dont know about the previous one?  (not
> 100% sure if this assumption is correct)
>
> eg of my data  (im comparing ubuntu -> debian security fixes and the
> data comes from https://edge.launchpad.net/ubuntu/+source/openswan)
> You can see what i have so far here -
> http://people.ubuntu.com/~stefanlsd/synclist.html
>
> The Jaunty Jackalope  (current stable release)
> Show details 1:2.4.12+dfsg-1.3+lenny2build0.9.04.1  updates, security
> (universe)  two days ago
> Show details 1:2.4.12+dfsg-1.3  release (universe)  49 weeks ago
>
> In the above case, the first loop goes through
> 1:2.4.12+dfsg-1.3+lenny2build0.9.04.1. At this point i need it to stop
> without checking the next entry 1:2.4.12+dfsg-1.3 as the former
> superseeds it.
> I understand that I can use a break to exit the loop, but i run a
> whole bunch of things after this check, so i dont want to break out of
> it.
>
> Is this possible what i'm doing? or have i architected the loop wrong
> so i 'should' be able to break out of it.
>
> Thanks in advance!
>
> stefan
>
>
> snippet of code below if its of any use...
>
>
> for app in apps:
>print('app in apps: %s' % app)
>for item in series:
>print('item in series: %s' % item)
>debian_series = item[0]
>debian_fullversion = item[2]
>print('debian_series: %s' % debian_series)
>print('debian_fullversion: %s' % debian_fullversion)
>
>debian_version =
> re.sub('\+?(etch|lenny|sarge|squeeze|woody)[0-9]+$', '',
> debian_fullversion)
>print('debian_version: %s' % debian_version)
>
>main_archive =
> launchpad.distributions['ubuntu'].main_archive
>#TODO - May be able to use a version check in the
> publishedsource to increase speed of checking
>publishedsource =
> main_archive.getPublishedSources(source_name = app,
> status='Published', exact_match=True)
>
>for source in publishedsource:
>
>if source.distro_series.active:
>print source.distro_series.name,
> source.source_package_version
>ubuntu_fullversion = source.source_package_version
>print('ubuntu fullversion before: %s' %
> ubuntu_fullversion)
>ubuntu_version =
> re.sub('build0.[0-9]+.[0-9][0-9].[0-9]+$', '', ubuntu_fullversion)
>#ubuntu_version =
> re.sub('\+?(etch|lenny|sarge|squeeze|woody)[0-9]+$', '',
> ubuntu_version)
>print('ubuntu version after: %s' % ubuntu_version)
>#ubuntu_target = ('%subuntu/+source/%s') %
> (launchpad._root_uri,app)
>
>if debian_fullversion == ubuntu_version:
>continue
>
>if debian_version in ubuntu_fullversion:
>ubuntu_component = source.component_name
>ubuntu_series = source.distro_series.name
>ubuntu_pocket = source.pocket
>print('ubuntu_pocket: %s' % ubuntu_pocket)
>print('debian version: %s' % debian_version)
>
>#If pocket is Security, no need to check further
>if ubuntu_pocket == 'Security' or
> ubuntu_pocket == 'Updates':
>print('Not Found version in: %s.
> Continue' % ubuntu_pocket)
>break
>
>if debian_version == ubuntu_version:
>matchtype = 'Sync Match'
>else:
>matchtype = 'MoM Match'
>
>ubuntu_changelog = ' href=http://changelogs.ubuntu.com/changelogs/pool/' + ubuntu_component
> + '/' + app[:1] + '/' + app + '/' + app + '_' + ubuntu_version +
> '/changelog>Ubuntu Changelog'
>debian_changelog = ' href=http://packages.debian.org/changelogs/pool/' + 'main' + '/' +
> app[:1] + '/' + app + '/' + app + '_' + debian_fullversion +
> '/changelog>Debian Changelog'
>
>print('cve: %s' % cve)
>for cveitem in cve:
>cvestatus, url = cvechec

[Tutor] for loop issue

2009-10-09 Thread Stefan Lesicnik
Hi,

This feels like a strange issue, so i hope I formulate this so its
understandable.

I have some objects. Each object has associated values. I am looping
through these objects, working with a value and printing out the
value.
The issue in this case is that i need to check if the one value
superseeds the other, and in that case, not print it out. I think the
problem is that when you are in the loop, you dont know about the
other object that you havent processed yet, and when you are
processing that object, you dont know about the previous one?  (not
100% sure if this assumption is correct)

eg of my data  (im comparing ubuntu -> debian security fixes and the
data comes from https://edge.launchpad.net/ubuntu/+source/openswan)
You can see what i have so far here -
http://people.ubuntu.com/~stefanlsd/synclist.html

The Jaunty Jackalope  (current stable release)
Show details 1:2.4.12+dfsg-1.3+lenny2build0.9.04.1  updates, security
(universe)  two days ago
Show details 1:2.4.12+dfsg-1.3  release (universe)  49 weeks ago

In the above case, the first loop goes through
1:2.4.12+dfsg-1.3+lenny2build0.9.04.1. At this point i need it to stop
without checking the next entry 1:2.4.12+dfsg-1.3 as the former
superseeds it.
I understand that I can use a break to exit the loop, but i run a
whole bunch of things after this check, so i dont want to break out of
it.

Is this possible what i'm doing? or have i architected the loop wrong
so i 'should' be able to break out of it.

Thanks in advance!

stefan


snippet of code below if its of any use...


for app in apps:
print('app in apps: %s' % app)
for item in series:
print('item in series: %s' % item)
debian_series = item[0]
debian_fullversion = item[2]
print('debian_series: %s' % debian_series)
print('debian_fullversion: %s' % debian_fullversion)

debian_version =
re.sub('\+?(etch|lenny|sarge|squeeze|woody)[0-9]+$', '',
debian_fullversion)
print('debian_version: %s' % debian_version)

main_archive = launchpad.distributions['ubuntu'].main_archive
#TODO - May be able to use a version check in the
publishedsource to increase speed of checking
publishedsource =
main_archive.getPublishedSources(source_name = app,
status='Published', exact_match=True)

for source in publishedsource:

if source.distro_series.active:
print source.distro_series.name,
source.source_package_version
ubuntu_fullversion = source.source_package_version
print('ubuntu fullversion before: %s' %
ubuntu_fullversion)
ubuntu_version =
re.sub('build0.[0-9]+.[0-9][0-9].[0-9]+$', '', ubuntu_fullversion)
#ubuntu_version =
re.sub('\+?(etch|lenny|sarge|squeeze|woody)[0-9]+$', '',
ubuntu_version)
print('ubuntu version after: %s' % ubuntu_version)
#ubuntu_target = ('%subuntu/+source/%s') %
(launchpad._root_uri,app)

if debian_fullversion == ubuntu_version:
continue

if debian_version in ubuntu_fullversion:
ubuntu_component = source.component_name
ubuntu_series = source.distro_series.name
ubuntu_pocket = source.pocket
print('ubuntu_pocket: %s' % ubuntu_pocket)
print('debian version: %s' % debian_version)

#If pocket is Security, no need to check further
if ubuntu_pocket == 'Security' or
ubuntu_pocket == 'Updates':
print('Not Found version in: %s.
Continue' % ubuntu_pocket)
break

if debian_version == ubuntu_version:
matchtype = 'Sync Match'
else:
matchtype = 'MoM Match'

ubuntu_changelog = 'http://changelogs.ubuntu.com/changelogs/pool/' + ubuntu_component
+ '/' + app[:1] + '/' + app + '/' + app + '_' + ubuntu_version +
'/changelog>Ubuntu Changelog'
debian_changelog = 'http://packages.debian.org/changelogs/pool/' + 'main' + '/' +
app[:1] + '/' + app + '/' + app + '_' + debian_fullversion +
'/changelog>Debian Changelog'

print('cve: %s' % cve)
for cveitem in cve:
cvestatus, url = cvecheck(cveitem,
ubuntu_series, ubuntu_version)
print('cvestatus: "%s"' % cvestatus)
if cvestatus == 'released' or
cvestatus == 'dne' or cvestatus == 'not-affected':