changeset 37:22214d79ed41

database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 14 May 2010 06:16:05 +0200
parents 74b8c9a9d5de
children 11bac653edfd
files Database.py MainWindow.py Ui_MainWindow.ui database-cassiopeia.ini util.py
diffstat 5 files changed, 41 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/Database.py	Wed May 05 03:10:15 2010 +0200
+++ b/Database.py	Fri May 14 06:16:05 2010 +0200
@@ -2,7 +2,7 @@
 import Mapping
 import sqlalchemy
 import sqlalchemy.orm
-import util
+import sys
 
 # Keep the connection to the database only once. The feed updater and the GUI app will
 # operate on a single engine/session but this comes in handy for interactive use
@@ -10,16 +10,22 @@
 SessionMaker = None
 
 def createSession():
-    databaseUrl = util.loadDatabaseUrl()
+    databaseUrl = _getDatabaseUrl()
     initEngine(databaseUrl)
     Mapping.createMapping(engine)
     initSessionMaker()
     return SessionMaker()
 
+def _getDatabaseUrl():
+    if len(sys.argv) < 2:
+        print("Usage: %s <database url>" % (sys.argv[0]))
+        sys.exit(1)
+    return sys.argv[1]
+
 def initEngine(databaseUrl):
     global engine
     if engine is None:
-        engine = sqlalchemy.create_engine(databaseUrl, echo=False)
+        engine = sqlalchemy.create_engine(databaseUrl, echo=True)
 
 def initSessionMaker():
     global SessionMaker
--- a/MainWindow.py	Wed May 05 03:10:15 2010 +0200
+++ b/MainWindow.py	Fri May 14 06:16:05 2010 +0200
@@ -8,6 +8,7 @@
 from PyQt4.QtGui import QFont
 from Ui_MainWindow import Ui_MainWindow
 import FeedUpdater
+import subprocess
 
 class MainWindow(QtGui.QMainWindow):
     def __init__(self, session=None):
@@ -55,6 +56,11 @@
             # TODO get status from feedUpdater and display in status area of the main window
             self.updateFeedList()
 
+    def openSelectedEntry(self):
+        # TODO make browser configurable
+        browser = "/usr/local/bin/opera"
+        subprocess.Popen([browser, self.selectedEntry.link])
+
 class FeedEntryItemDelegate(QtGui.QStyledItemDelegate):
     def __init__(self):
         QtGui.QStyledItemDelegate.__init__(self, None)
--- a/Ui_MainWindow.ui	Wed May 05 03:10:15 2010 +0200
+++ b/Ui_MainWindow.ui	Fri May 14 06:16:05 2010 +0200
@@ -71,6 +71,7 @@
      <string>Article</string>
     </property>
     <addaction name="actionMarkSelectedRead"/>
+    <addaction name="actionOpenInBrowser"/>
    </widget>
    <addaction name="menuFeed"/>
    <addaction name="menuArticle"/>
@@ -105,6 +106,14 @@
     <string>M</string>
    </property>
   </action>
+  <action name="actionOpenInBrowser">
+   <property name="text">
+    <string>Open in browser</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+O</string>
+   </property>
+  </action>
  </widget>
  <customwidgets>
   <customwidget>
@@ -195,11 +204,28 @@
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>actionOpenInBrowser</sender>
+   <signal>activated()</signal>
+   <receiver>MainWindow</receiver>
+   <slot>openSelectedEntry()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>-1</x>
+     <y>-1</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>495</x>
+     <y>374</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>addFeed()</slot>
   <slot>feedSelected(QModelIndex)</slot>
   <slot>feedEntrySelected(QModelIndex)</slot>
   <slot>toggleReadOnSelectedEntry()</slot>
+  <slot>openSelectedEntry()</slot>
  </slots>
 </ui>
--- a/database-cassiopeia.ini	Wed May 05 03:10:15 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-
-[database]
-url = sqlite:///feedworm.sqlite
--- a/util.py	Wed May 05 03:10:15 2010 +0200
+++ b/util.py	Fri May 14 06:16:05 2010 +0200
@@ -1,9 +1,7 @@
 
-from ConfigParser import ConfigParser
 from datetime import datetime, timedelta
 from Feed import Feed
 import logging
-import socket
 
 logger = logging.getLogger("database")
 
@@ -12,15 +10,6 @@
     logging.getLogger("sqlalchemy").setLevel(logging.INFO)
     logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)
 
-def loadDatabaseUrl():
-    hostname = socket.gethostname()
-    filename = "database-%s.ini" % hostname
-    logger.debug("loading database configuration from " + filename)
-
-    parser = ConfigParser();
-    parser.read(filename)
-    return parser.get("database", "url")
-
 def loadFeeds(session=None, filename="feeds.txt"):
     file = open(filename)
     for line in file: