Skip to content
Browse files

PEP8 fixes

  • Loading branch information...
1 parent 35ad867 commit 2a37e1ef621d3a76d24ff9f3d4baad5b07d8bb61 vintitres committed Feb 18, 2012
Showing with 63 additions and 50 deletions.
  1. +1 −0 .gitignore
  2. +3 −1 config.py
  3. +7 −8 gnome-shell-google-calendar.py
  4. +8 −8 keyring.py
  5. +29 −20 oauth.py
  6. +15 −13 test
View
1 .gitignore
@@ -1,3 +1,4 @@
*.pyc
*~
excludes
+config.json
View
4 config.py
@@ -5,12 +5,14 @@
'''
import json
+
def set(parameter, value):
config = get(None)
config[parameter] = value
with open('config.json', 'w') as fp:
json.dump(config, fp)
+
def get(parameter):
try:
with open('config.json', 'r') as fp:
@@ -20,7 +22,7 @@ def get(parameter):
if parameter is None:
return config
- if config.has_key(parameter):
+ if parameter in config:
return config.get(parameter)
else:
config[parameter] = None
View
15 gnome-shell-google-calendar.py
@@ -170,13 +170,13 @@ def get_key(self):
@write_traceback
def as_gnome_event(self):
- return ('', # uid
- self.title if self.title else '', # summary
- '', # description
- self.allday, # allDay
- self.start_time, # date
- self.end_time, # end
- {}) # extras
+ return ('', # uid
+ self.title if self.title else '', # summary
+ '', # description
+ self.allday, # allDay
+ self.start_time, # date
+ self.end_time, # end
+ {}) # extras
def __repr__(self):
return '<Event: %r>' % (self.title)
@@ -438,7 +438,6 @@ def GetEvents(self, since, until, force_reload):
if o == '--hide-cal':
SHOW_SHORT_CALENDAR_TITLE = False
-
account = config.get('account')
# Login
View
16 keyring.py
@@ -5,7 +5,7 @@
_keyring = 'login'
_display_name = 'GNOME Shell Google Calendar Account'
-_attrs = { 'application': 'gnome-shell-google-calendar' }
+_attrs = {'application': 'gnome-shell-google-calendar'}
_type = gk.ITEM_GENERIC_SECRET
_item_id = None
@@ -16,10 +16,10 @@ class KeyringError(Exception):
def get_item_id():
global _item_id
-
+
if _item_id:
return _item_id
-
+
try:
results = gk.find_items_sync(gk.ITEM_GENERIC_SECRET, _attrs)
_item_id = results[0].item_id
@@ -37,24 +37,24 @@ def get_item_id():
def get_credentials():
item_id = get_item_id()
attrs = gk.item_get_attributes_sync(_keyring, item_id)
-
+
if not 'email' in attrs:
raise KeyringError('Login credentials not found')
-
+
info = gk.item_get_info_sync(_keyring, item_id)
-
+
return attrs['email'], info.get_secret()
def set_credentials(email, password):
item_id = get_item_id()
-
+
info = gk.ItemInfo()
info.set_display_name(_display_name)
info.set_type(_type)
info.set_secret(password)
gk.item_set_info_sync(_keyring, item_id, info)
-
+
attrs = _attrs.copy()
attrs['email'] = email
gk.item_set_attributes_sync(_keyring, item_id, attrs)
View
49 oauth.py
@@ -4,52 +4,61 @@
@author: flocki
'''
import dbus
-#import dbus.mainloop.glib
-#import dbus.service
import gdata.calendar.client
def oauth_prompt():
bus = dbus.SessionBus()
- #accounts = bus.get_object('org.gnome.OnlineAccounts', '/org/gnome/OnlineAccounts/Accounts')
- online_accounts = bus.get_object('org.gnome.OnlineAccounts', '/org/gnome/OnlineAccounts')
+ online_accounts = bus.get_object('org.gnome.OnlineAccounts',
+ '/org/gnome/OnlineAccounts')
- l = online_accounts.GetManagedObjects(dbus_interface='org.freedesktop.DBus.ObjectManager')
+ l = online_accounts.GetManagedObjects(
+ dbus_interface='org.freedesktop.DBus.ObjectManager')
accounts = []
for account_info in l.values():
- #print account_info
- if account_info.has_key('org.gnome.OnlineAccounts.Account'):
- email = str(account_info['org.gnome.OnlineAccounts.Account']['PresentationIdentity'])
+ if 'org.gnome.OnlineAccounts.Account' in account_info:
+ email = str(account_info['org.gnome.OnlineAccounts.Account']
+ ['PresentationIdentity'])
print "%d. %s" % (len(accounts), email)
accounts.append(email)
- email = accounts[ int(raw_input('Please choose the Account: ')) ]
+ email = accounts[int(raw_input('Please choose the Account: '))]
print "You choose '{0}'".format(email)
return email
+
def oauth_login(email):
bus = dbus.SessionBus()
- online_accounts = bus.get_object('org.gnome.OnlineAccounts', '/org/gnome/OnlineAccounts')
+ online_accounts = bus.get_object('org.gnome.OnlineAccounts',
+ '/org/gnome/OnlineAccounts')
- l = online_accounts.GetManagedObjects(dbus_interface='org.freedesktop.DBus.ObjectManager')
+ l = online_accounts.GetManagedObjects(
+ dbus_interface='org.freedesktop.DBus.ObjectManager')
for account_path, account_info in l.items():
- #print account_path
- #print account_info
- if account_info.has_key('org.gnome.OnlineAccounts.Account') and str(account_info['org.gnome.OnlineAccounts.Account']['PresentationIdentity']) == email:
- consumer_key = str(account_info['org.gnome.OnlineAccounts.OAuthBased']['ConsumerKey'])
- consumer_secret = str(account_info['org.gnome.OnlineAccounts.OAuthBased']['ConsumerSecret'])
+ if 'org.gnome.OnlineAccounts.Account' in account_info and \
+ str(account_info['org.gnome.OnlineAccounts.Account']
+ ['PresentationIdentity']) == email:
+ consumer_key = str(
+ account_info['org.gnome.OnlineAccounts.OAuthBased']
+ ['ConsumerKey'])
+ consumer_secret = str(
+ account_info['org.gnome.OnlineAccounts.OAuthBased']
+ ['ConsumerSecret'])
o = bus.get_object('org.gnome.OnlineAccounts', account_path)
- oauth_data = o.get_dbus_method('GetAccessToken', 'org.gnome.OnlineAccounts.OAuthBased')()
+ oauth_data = o.get_dbus_method('GetAccessToken',
+ 'org.gnome.OnlineAccounts.OAuthBased')()
access_token = str(oauth_data[0])
access_token_secret = str(oauth_data[1])
- client = gdata.calendar.client.CalendarClient(source='gnome-shell-google-calendar')
- client.auth_token = gdata.gauth.OAuthHmacToken(consumer_key, consumer_secret, access_token, access_token_secret, gdata.gauth.ACCESS_TOKEN)
+ client = gdata.calendar.client.CalendarClient(
+ source='gnome-shell-google-calendar')
+ client.auth_token = gdata.gauth.OAuthHmacToken(consumer_key,
+ consumer_secret, access_token, access_token_secret,
+ gdata.gauth.ACCESS_TOKEN)
return client
raise Exception
-
View
28 test
@@ -6,15 +6,17 @@
import unittest
import datetime
+
# remove the copied module
def cleanup():
- import os
- os.remove('gsgc_test.py')
- if os.path.exists('gsgc_test.pyc'):
- os.remove('gsgc_test.pyc')
+ import os
+ os.remove('gsgc_test.py')
+ if os.path.exists('gsgc_test.pyc'):
+ os.remove('gsgc_test.pyc')
import atexit
atexit.register(cleanup)
+
# import, but have to use a python-compatible name
import shutil
shutil.copy('gnome-shell-google-calendar.py', 'gsgc_test.py')
@@ -23,24 +25,24 @@ import gsgc_test as gsgc
#################################################
class TestGnomeGoogleCalendar(unittest.TestCase):
- def test_GetMonthKey(self):
- from time import strftime, localtime
+ def test_GetMonthKey(self):
+ from time import strftime, localtime
- def tostr(x):
- return [ strftime('%Y%m%d %H%M%S', localtime(x)) for x in x ]
+ def tostr(x):
+ return [strftime('%Y%m%d %H%M%S', localtime(x)) for x in x]
- self.assertEqual(tostr(
+ self.assertEqual(tostr(
gsgc.get_month_key(datetime.datetime(2011, 12, 12))),
['20111127 000000', '20111231 235959'])
- self.assertEqual(tostr(
+ self.assertEqual(tostr(
gsgc.get_month_key(datetime.datetime(2011, 11, 1))),
['20111030 000000', '20111203 235959'])
- self.assertEqual(tostr(
+ self.assertEqual(tostr(
gsgc.get_month_key(datetime.datetime(2011, 1, 31))),
['20101226 000000', '20110205 235959'])
- self.assertEqual(tostr(
+ self.assertEqual(tostr(
gsgc.get_month_key(datetime.datetime(2012, 1, 31))),
['20120101 000000', '20120204 235959'])
suite = unittest.TestLoader().loadTestsFromTestCase(TestGnomeGoogleCalendar)
-unittest.TextTestRunner(verbosity = 2).run(suite)
+unittest.TextTestRunner(verbosity=2).run(suite)

0 comments on commit 2a37e1e

Please sign in to comment.
Something went wrong with that request. Please try again.