Suggested patch for max issues per recipe

This commit is contained in:
Spedinfargo 2011-02-25 16:05:02 -06:00
parent a64f4aeb0d
commit b540537f30
6 changed files with 73 additions and 7 deletions

View File

@ -58,6 +58,16 @@ class FetchNewsAction(InterfaceAction):
self.scheduler.recipe_download_failed(arg) self.scheduler.recipe_download_failed(arg)
return self.gui.job_exception(job) return self.gui.job_exception(job)
id = self.gui.library_view.model().add_news(pt.name, arg) id = self.gui.library_view.model().add_news(pt.name, arg)
# Arg may contain a "keep_issues" variable. if it is non-zer, delete all but newest x issues.
try:
ikeep_issues = int(arg['keep_issues'])
except:
ikeep_issues = 0
if ikeep_issues > 0:
ids2delete = self.gui.library_view.model().db.get_most_recent_by_tag(arg['keep_issues'], arg['title'])
self.gui.library_view.model().delete_books_by_id(ids2delete)
self.gui.library_view.model().reset() self.gui.library_view.model().reset()
sync = self.gui.news_to_be_synced sync = self.gui.news_to_be_synced
sync.add(id) sync.add(id)

View File

@ -153,9 +153,10 @@ class SchedulerDialog(QDialog, Ui_Dialog):
self.recipe_model.un_schedule_recipe(urn) self.recipe_model.un_schedule_recipe(urn)
add_title_tag = self.add_title_tag.isChecked() add_title_tag = self.add_title_tag.isChecked()
keep_issues = unicode(self.keep_issues.text())
custom_tags = unicode(self.custom_tags.text()).strip() custom_tags = unicode(self.custom_tags.text()).strip()
custom_tags = [x.strip() for x in custom_tags.split(',')] custom_tags = [x.strip() for x in custom_tags.split(',')]
self.recipe_model.customize_recipe(urn, add_title_tag, custom_tags) self.recipe_model.customize_recipe(urn, add_title_tag, custom_tags, keep_issues)
return True return True
def initialize_detail_box(self, urn): def initialize_detail_box(self, urn):
@ -215,9 +216,15 @@ class SchedulerDialog(QDialog, Ui_Dialog):
if d < timedelta(days=366): if d < timedelta(days=366):
self.last_downloaded.setText(_('Last downloaded')+': '+tm) self.last_downloaded.setText(_('Last downloaded')+': '+tm)
add_title_tag, custom_tags = customize_info add_title_tag, custom_tags, keep_issues = customize_info
self.add_title_tag.setChecked(add_title_tag) self.add_title_tag.setChecked(add_title_tag)
self.custom_tags.setText(u', '.join(custom_tags)) self.custom_tags.setText(u', '.join(custom_tags))
try:
ikeep_issues = int(keep_issues)
except:
ikeep_issues = 0
self.keep_issues.setValue(ikeep_issues)
class Scheduler(QObject): class Scheduler(QObject):
@ -299,7 +306,7 @@ class Scheduler(QObject):
un = pw = None un = pw = None
if account_info is not None: if account_info is not None:
un, pw = account_info un, pw = account_info
add_title_tag, custom_tags = customize_info add_title_tag, custom_tags, keep_issues = customize_info
script = self.recipe_model.get_recipe(urn) script = self.recipe_model.get_recipe(urn)
pt = PersistentTemporaryFile('_builtin.recipe') pt = PersistentTemporaryFile('_builtin.recipe')
pt.write(script) pt.write(script)
@ -312,6 +319,7 @@ class Scheduler(QObject):
'recipe':pt.name, 'recipe':pt.name,
'title':recipe.get('title',''), 'title':recipe.get('title',''),
'urn':urn, 'urn':urn,
'keep_issues':keep_issues
} }
self.download_queue.add(urn) self.download_queue.add(urn)
self.start_recipe_fetch.emit(arg) self.start_recipe_fetch.emit(arg)

View File

@ -245,6 +245,36 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string>Maximum number of copies (issues) of this recipe to keep. Set to 0 to keep all (disable).</string>
</property>
<property name="text">
<string>Maximum copies (0 to keep all): </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="keep_issues"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<widget class="QLabel" name="last_downloaded"> <widget class="QLabel" name="last_downloaded">
<property name="text"> <property name="text">

View File

@ -1476,6 +1476,18 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
############# End get_categories ############# End get_categories
def get_most_recent_by_tag(self, number_to_keep, tag):
#Based on tag and number passed in, create a list of books matching that tag, keeping only the newest X versions
tag = tag.lower().strip()
idlist = []
mycount = 0
for myid in (self.conn.get('select a.book id from books_tags_link a inner join books b on a.book = b.id where a.tag in (select tags.id from tags where tags.name = ?) order by b.timestamp desc', [tag])):
myid = myid[0]
mycount = mycount + 1
if mycount > int(number_to_keep):
idlist.append(myid)
return idlist
def tags_older_than(self, tag, delta): def tags_older_than(self, tag, delta):
tag = tag.lower().strip() tag = tag.lower().strip()
now = nowf() now = nowf()

View File

@ -201,12 +201,14 @@ class SchedulerConfig(object):
self.root.append(sr) self.root.append(sr)
self.write_scheduler_file() self.write_scheduler_file()
def customize_recipe(self, urn, add_title_tag, custom_tags): # 'keep_issues' argument for recipe-specific number of copies to keep
def customize_recipe(self, urn, add_title_tag, custom_tags, keep_issues):
with self.lock: with self.lock:
for x in list(self.iter_customization()): for x in list(self.iter_customization()):
if x.get('id') == urn: if x.get('id') == urn:
self.root.remove(x) self.root.remove(x)
cs = E.recipe_customization({ cs = E.recipe_customization({
'keep_issues' : keep_issues,
'id' : urn, 'id' : urn,
'add_title_tag' : 'yes' if add_title_tag else 'no', 'add_title_tag' : 'yes' if add_title_tag else 'no',
'custom_tags' : ','.join(custom_tags), 'custom_tags' : ','.join(custom_tags),
@ -316,17 +318,20 @@ class SchedulerConfig(object):
if x.get('id', False) == urn: if x.get('id', False) == urn:
return x.get('username', ''), x.get('password', '') return x.get('username', ''), x.get('password', '')
# 'keep_issues' element for recipe-specific number of copies to keep (default 0 == all)
def get_customize_info(self, urn): def get_customize_info(self, urn):
keep_issues = 0
add_title_tag = True add_title_tag = True
custom_tags = [] custom_tags = []
with self.lock: with self.lock:
for x in self.iter_customization(): for x in self.iter_customization():
if x.get('id', False) == urn: if x.get('id', False) == urn:
keep_issues = x.get('keep_issues',0)
add_title_tag = x.get('add_title_tag', 'yes') == 'yes' add_title_tag = x.get('add_title_tag', 'yes') == 'yes'
custom_tags = [i.strip() for i in x.get('custom_tags', custom_tags = [i.strip() for i in x.get('custom_tags',
'').split(',')] '').split(',')]
break break
return add_title_tag, custom_tags return add_title_tag, custom_tags, keep_issues
def get_schedule_info(self, urn): def get_schedule_info(self, urn):
with self.lock: with self.lock:

View File

@ -354,9 +354,10 @@ class RecipeModel(QAbstractItemModel, SearchQueryParser):
self.scheduler_config.schedule_recipe(self.recipe_from_urn(urn), self.scheduler_config.schedule_recipe(self.recipe_from_urn(urn),
sched_type, schedule) sched_type, schedule)
def customize_recipe(self, urn, add_title_tag, custom_tags): # 'keep_issues' argument for recipe-specific number of copies to keep
def customize_recipe(self, urn, add_title_tag, custom_tags, keep_issues):
self.scheduler_config.customize_recipe(urn, add_title_tag, self.scheduler_config.customize_recipe(urn, add_title_tag,
custom_tags) custom_tags, keep_issues)
def get_to_be_downloaded_recipes(self): def get_to_be_downloaded_recipes(self):
ans = self.scheduler_config.get_to_be_downloaded_recipes() ans = self.scheduler_config.get_to_be_downloaded_recipes()