Mercurial > hg > Feedworm
annotate util.py @ 120:e830fa1cc7a2 backend
re-enabled PreferencesDialog
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sun, 21 Aug 2011 04:04:37 +0200 |
parents | 04a730f9d07d |
children | c923e4c57a81 |
rev | line source |
---|---|
12
9ede118b93ef
move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 |
34
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
2 from Feed import Feed |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
3 from datetime import datetime, timedelta |
13
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
4 import logging |
12
9ede118b93ef
move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 |
13
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
6 logger = logging.getLogger("database") |
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
7 |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
8 # TODO remove this |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
9 #def databaseLoggingEnabled(): |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
10 # loggingEnabled = False |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
11 # for arg in sys.argv: |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
12 # if arg == "--databaseLogging": |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
13 # loggingEnabled = True |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
14 # return loggingEnabled |
57
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
15 |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
16 # TODO remove this |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
17 #def configureLogging(): |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
18 # logging.basicConfig(level=logging.DEBUG) |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
19 # |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
20 # sqlalchemyLogLevel = logging.ERROR |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
21 # if databaseLoggingEnabled(): |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
22 # sqlalchemyLogLevel = logging.INFO |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
23 # logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel) |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
24 # |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
57
diff
changeset
|
25 # logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) |
13
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
26 |
34
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
27 def loadFeeds(session=None, filename="feeds.txt"): |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
28 file = open(filename) |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
29 for line in file: |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
30 (title, rss_url) = line.split("|") |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
31 # remove the newline |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
32 rss_url = rss_url.rstrip() |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
33 feed = Feed(title, rss_url) |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
34 session.add(feed) |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
35 file.close() |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
28
diff
changeset
|
36 session.commit() |
35
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
37 |
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
38 def forceUpdateAllFeeds(session=None): |
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
39 for feed in Feed.all(session): |
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
40 feed.next_update = datetime.now() - timedelta(minutes=1) |
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
41 session.commit() |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
42 |