|
|
|
#!/usr/bin/python2.5
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Mitter, a Maemo client for Twitter.
|
|
|
|
# Copyright (C) 2007, 2008 Julio Biason
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import time
|
|
|
|
import urllib
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
import mitterlib.network as network
|
|
|
|
|
|
|
|
from mitterlib.configopt import ConfigOpt
|
|
|
|
from mitterlib.network import Networks
|
|
|
|
from mitterlib.ui import Interfaces
|
|
|
|
|
|
|
|
log = logging.getLogger('mitter')
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Main function."""
|
|
|
|
|
|
|
|
# options
|
|
|
|
|
|
|
|
options = ConfigOpt()
|
|
|
|
options.add_group('General', 'General options')
|
|
|
|
options.add_option('-d', '--debug',
|
|
|
|
group='General',
|
|
|
|
option='debug',
|
|
|
|
action='store_true',
|
|
|
|
help='Display debugging information.',
|
|
|
|
default=False,
|
|
|
|
is_config_option=False)
|
|
|
|
options.add_option('-i', '--interface',
|
|
|
|
group='General',
|
|
|
|
option='interface',
|
|
|
|
default=None,
|
|
|
|
metavar='INTERFACE',
|
|
|
|
help='Interface to be used.')
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
|
|
# Start the network manager (which will add the network options)
|
|
|
|
connection = Networks(options)
|
|
|
|
|
|
|
|
# Start the interface manager and make interfaces add their options to the
|
|
|
|
# command line
|
|
|
|
interfaces = Interfaces(options)
|
|
|
|
interfaces.options()
|
|
|
|
|
|
|
|
# Parse the command line options and the config file
|
|
|
|
options()
|
|
|
|
|
|
|
|
# start the logging service
|
|
|
|
if options['General']['debug']:
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
else:
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
log = logging.getLogger('mitter')
|
|
|
|
|
|
|
|
# disable the warnings. Interfaces may choose to receive the warnings
|
|
|
|
# changing the filter to "error"
|
|
|
|
warnings.simplefilter('ignore')
|
|
|
|
|
|
|
|
# select an interface (preferably, the one the user selected in the
|
|
|
|
# command line)
|
|
|
|
preferred_interface = options['General']['interface']
|
|
|
|
log.debug('Config interface: %s', preferred_interface)
|
|
|
|
|
|
|
|
if 'interface' in options.conflicts:
|
|
|
|
preferred_interface = options.conflicts['interface']
|
|
|
|
log.debug('Command line interface: %s', preferred_interface)
|
|
|
|
|
|
|
|
# load the module with the selected interface (or pick one for the user if
|
|
|
|
# they don't chose anything.)
|
|
|
|
display = interface.load(connection, preferred_interface)
|
|
|
|
if display is None:
|
|
|
|
log.error('Sorry, no interface could be found for your system')
|
|
|
|
return
|
|
|
|
|
|
|
|
# display the interface (the interface should take care of updating
|
|
|
|
# itself)
|
|
|
|
display()
|
|
|
|
options.save()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|