Mercurial > hg > Feedworm
annotate util.py @ 78:a728bbc7171e
add some todo items
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 14 Aug 2010 02:54:01 +0200 |
parents | 254d5b89a6ca |
children | 04a730f9d07d |
rev | line source |
---|---|
12
9ede118b93ef
move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 |
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
|
2 from datetime import datetime, timedelta |
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
|
3 from Feed import Feed |
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 |
57
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
5 import sys |
12
9ede118b93ef
move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
6 |
13
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
7 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
|
8 |
57
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
9 def databaseLoggingEnabled(): |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
10 loggingEnabled = False |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
11 for arg in sys.argv: |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
12 if arg == "--databaseLogging": |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
13 loggingEnabled = True |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
14 return loggingEnabled |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
15 |
13
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
16 def configureLogging(): |
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
17 logging.basicConfig(level=logging.DEBUG) |
57
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
18 |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
19 sqlalchemyLogLevel = logging.ERROR |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
20 if databaseLoggingEnabled(): |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
21 sqlalchemyLogLevel = logging.INFO |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
22 logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel) |
254d5b89a6ca
make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
23 |
13
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
24 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) |
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
25 |
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
|
26 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
|
27 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
|
28 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
|
29 (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
|
30 # 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 |
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 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
|
38 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
|
39 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
|
40 session.commit() |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
41 |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
42 def str2bool(string): |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
43 return string.lower() in ["yes", "true", "t", "1"] |
46
03358c113170
Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
44 |
03358c113170
Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
45 def bool2str(bool): |
03358c113170
Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
46 if bool: |
03358c113170
Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
47 return "True" |
03358c113170
Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
48 else: |
03358c113170
Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
49 return "False" |