Set the orientation before showing the main window.
[feedingit] / src / wc.py
1 # Copyright (c) 2011 Neal H. Walfield
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 import logging
17 logger = logging.getLogger(__name__)
18 import traceback
19
20 # Don't fail if the Woodchuck modules are not available.  Just disable
21 # Woodchuck's functionality.
22
23 # Whether we imported the woodchuck modules successfully.
24 woodchuck_imported = True
25 try:
26     import pywoodchuck
27     from pywoodchuck import PyWoodchuck
28     from pywoodchuck import woodchuck
29 except ImportError, exception:
30     logger.info(
31         "Unable to load Woodchuck modules: disabling Woodchuck support: %s"
32         % traceback.format_exc ())
33     woodchuck_imported = False
34     class PyWoodchuck (object):
35         def available(self):
36             return False
37     woodchuck = None
38
39 # The default channel refresh interval: 6 hours.
40 refresh_interval = 6 * 60 * 60
41
42 class mywoodchuck (PyWoodchuck):
43     def __init__(self, listing, human_readable_name, identifier,
44                  request_feedback):
45         PyWoodchuck.__init__ (self, human_readable_name, identifier,
46                               request_feedback)
47
48         self.listing = listing
49
50     # Woodchuck upcalls.
51     def stream_update_cb(self, stream):
52         logger.debug("stream update called on %s (%s)"
53                      % (stream.human_readable_name, stream.identifier,))
54
55         # Make sure no one else is concurrently updating this
56         # feed.
57         try:
58             self.listing.updateFeed(stream.identifier)
59         except:
60             logger.debug("Updating %s: %s"
61                          % (stream.identifier, traceback.format_exc ()))
62
63     def object_transfer_cb(self, stream, object,
64                            version, filename, quality):
65         log ("object transfer called on %s (%s) in stream %s (%s)"
66              % (object.human_readable_name, object.identifier,
67                 stream.human_readable_name, stream.identifier))
68
69 _w = None
70 def wc_init(listing, request_feedback=False):
71     global _w
72     assert _w is None
73     
74     _w = mywoodchuck (listing, "FeedingIt", "org.marcoz.feedingit",
75                       request_feedback)
76
77     if not woodchuck_imported or not _w.available ():
78         logger.info("Unable to contact Woodchuck server.")
79     else:
80         logger.debug("Woodchuck appears to be available.")
81
82 def wc():
83     """Connect to the woodchuck server and initialize any state."""
84     global _w
85     assert _w is not None
86     return _w