Skip to content

Commit

Permalink
Whitespace removal
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : 8e5e3aa
  • Loading branch information
acdha committed Apr 12, 2009
1 parent f15c65d commit aecc895
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 83 deletions.
2 changes: 1 addition & 1 deletion examples/crankd/MountManager.py
Expand Up @@ -8,4 +8,4 @@ def onNSWorkspaceDidMountNotification_(self, aNotification):
def onNSWorkspaceDidUnmountNotification_(self, aNotification):
path = aNotification.userInfo()['NSDevicePath']
self.logger.info("Unmount: %s" % path)

1 change: 0 additions & 1 deletion examples/crankd/NetworkConfig.py
Expand Up @@ -4,4 +4,3 @@ class NetworkConfig(object):
"""Handles network related changes for kicker-replacement"""
def atalk_change(self, context=None, logger=None, **kwargs):
logger.info("Atalk? You poor person, you…")

28 changes: 14 additions & 14 deletions examples/crankd/sample-of-events/generate-event-plist.py
Expand Up @@ -31,12 +31,12 @@ def AddCategoryOfEvents(event_category, events):

def AddKnownEvents():
"""Here we add all the events that we know of to the dictionary"""

# Add a bunch of dynamic events
store = SCDynamicStoreCreate(None, "generate_event_plist", None, None)
AddCategoryOfEvents(u"SystemConfiguration",
SCDynamicStoreCopyKeyList(store, ".*"))

# Add some standard NSWorkspace events
AddCategoryOfEvents(u"NSWorkspace",
u'''
Expand All @@ -57,45 +57,45 @@ def AddKnownEvents():
def PrintEvents():
"""Prints all the events, for debugging purposes"""
for category in sorted(event_dict):

print category

for event in sorted(event_dict[category]):
print "\t" + event

def OutputEvents():
"""Outputs all the events to a file"""

# print the header for the file
plist = open(OUTPUT_FILE, 'w')

print >>plist, '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>'''

for category in sorted(event_dict):

# print out the category
print >>plist, " <key>%s</key>\n <dict>" % category

for event in sorted(event_dict[category]):
print >>plist, """
<key>%s</key>
<dict>
<key>command</key>
<string>%s '%s' '%s'</string>
</dict>""" % ( event, 'tunnel.sh', category, event )

# end the category
print >>plist, " </dict>"

# end the plist file
print >>plist, '</dict>'
print >>plist, '</plist>'

plist.close()

def main():
"""Runs the program"""
AddKnownEvents()
Expand All @@ -104,4 +104,4 @@ def main():

main()


3 changes: 1 addition & 2 deletions examples/ctypes/keychain-delete.py
Expand Up @@ -38,5 +38,4 @@

if rc != 0:
raise RuntimeError('SecKeychainItemDelete failed: rc=%d' % rc)



38 changes: 19 additions & 19 deletions examples/ctypes/keychain-update.py
Expand Up @@ -38,40 +38,40 @@ def UpdatePassword(account_name, new_password, server_name, protocol_type_string
protocol_type_code = FourCharCode(protocol_type_string)
else:
protocol_type_code = 0

# Call function to locate existing keychain item
rc = Security.SecKeychainFindInternetPassword(
None,
len(server_name),
None,
len(server_name),
server_name,
None,
None,
len(account_name),
account_name,
None,
None,
port_number,
protocol_type_code,
None,
None,
None,
len(account_name),
account_name,
None,
None,
port_number,
protocol_type_code,
None,
None, # To retrieve the current password, change this argument to: ctypes.byref(password_length)
None, # To retrieve the current password, change this argument to: ctypes.pointer(password_pointer)
ctypes.pointer(item)
)

if rc != 0:
raise RuntimeError('Did not find existing password for server %s, protocol type %s, account name %s: rc=%d' % (server_name, protocol_type_code, account_name, rc))

# Call function to update password
rc = Security.SecKeychainItemModifyAttributesAndData(
item,
None,
len(new_password),
item,
None,
len(new_password),
new_password
)

if rc != 0:
raise RuntimeError('Failed to record new password for server %s, protocol type %s, account name %s: rc=%d' % (server_name, protocol_type_code, account_name, rc))

return 0

# Start execution
Expand All @@ -85,11 +85,11 @@ def UpdatePassword(account_name, new_password, server_name, protocol_type_string
new_password = sys.argv[2]

# Call UpdatePassword for each password to update.
#
#
# If more than one keychain item will match a server and account name, you must
# specify a protocol type. Otherwise, only the first matching item will be
# updated.
#
#
# The list of protocol type codes is in
# /System/Library/Frameworks/Security.framework/Versions/Current/Headers/SecKeychain.h

Expand Down
12 changes: 6 additions & 6 deletions lib/PyMacAdmin/SCUtilities/SCPreferences.py
Expand Up @@ -17,28 +17,28 @@ class SCPreferences(object):
"""Utility class for working with the SystemConfiguration framework"""
proxy_protocols = ('HTTP', 'FTP', 'SOCKS') # List of the supported protocols
session = None

def __init__(self):
super(SCPreferences, self).__init__()
self.session = SCPreferencesCreate(None, "set-proxy", None)

def save(self):
if not self.session:
return
return
if not SCPreferencesCommitChanges(self.session):
raise RuntimeError("Unable to save SystemConfiguration changes")
if not SCPreferencesApplyChanges(self.session):
raise RuntimeError("Unable to apply SystemConfiguration changes")
def set_proxy(self, enable=True, protocol="HTTP", server="localhost", port=3128):

def set_proxy(self, enable=True, protocol="HTTP", server="localhost", port=3128):
new_settings = SCPreferencesPathGetValue(self.session, u'/NetworkServices/')

for interface in new_settings:
new_settings[interface]['Proxies']["%sEnable" % protocol] = 1 if enable else 0
if enable:
new_settings[interface]['Proxies']['%sPort' % protocol] = int(port)
new_settings[interface]['Proxies']['%sProxy' % protocol] = server

SCPreferencesPathSetValue(self.session, u'/NetworkServices/', new_settings)

class SCPreferencesTests(unittest.TestCase):
Expand Down
22 changes: 11 additions & 11 deletions lib/PyMacAdmin/Security/tests/test_Keychain.py
Expand Up @@ -11,23 +11,23 @@

class KeychainTests(unittest.TestCase):
"""Unit test for the Keychain module"""

def setUp(self):
pass

def test_load_default_keychain(self):
k = Keychain()
self.failIfEqual(k, None)

def test_load_system_keychain(self):
k = Keychain('/Library/Keychains/System.keychain')
self.failIfEqual(k, None)

def test_find_airport_password(self):
system_keychain = Keychain("/Library/Keychains/System.keychain")
# BUG: Most people probably have this - but not everyone?
system_keychain.find_generic_password(account_name="linksys")
system_keychain.find_generic_password(account_name="linksys")

def test_find_nonexistent_generic_password(self):
import uuid
system_keychain = Keychain("/Library/Keychains/System.keychain")
Expand All @@ -39,11 +39,11 @@ def test_add_and_remove_generic_password(self):
service_name = "PyMacAdmin Keychain Unit Test"
account_name = str(uuid.uuid4())
password = str(uuid.uuid4())

i = GenericPassword(service_name=service_name, account_name=account_name, password=password)
k.add(i)
self.assertEquals(i.password, k.find_generic_password(service_name, account_name).password)

k.remove(i)
self.assertRaises(KeyError, k.find_generic_password, **{"service_name": service_name, "account_name": account_name})

Expand All @@ -63,16 +63,16 @@ def test_add_and_remove_internet_password(self):
'authentication_type': 'http',
'password': str(uuid.uuid4())
}

i = InternetPassword(**kwargs)
k.add(i)

self.assertEquals(i.password, k.find_internet_password(server_name=kwargs['server_name'], account_name=kwargs['account_name']).password)

k.remove(i)
self.assertRaises(KeyError, k.find_internet_password, **{"server_name": kwargs['server_name'], "account_name": kwargs['account_name']})


if __name__ == '__main__':
unittest.main()

6 changes: 3 additions & 3 deletions utilities/diskimage_unittesting/dmgtestutilities.py
@@ -1,15 +1,15 @@
#!/usr/bin/python2.5
#
#
# Use 2.5 so we can import objc & Foundation in tests
#
# Copyright 2008 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
4 changes: 2 additions & 2 deletions utilities/diskimage_unittesting/macdmgtest.py
Expand Up @@ -7,9 +7,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
8 changes: 4 additions & 4 deletions utilities/diskimage_unittesting/run_image_tests.py
Expand Up @@ -7,9 +7,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -71,7 +71,7 @@ def AttachDiskImage(path):

def DetachDiskImage(path):
"""forcibly unmounts a given dmg from the mountpoint path."""

command = ["/usr/bin/hdiutil", "detach", path]
returncode = subprocess.call(command)
if returncode:
Expand Down Expand Up @@ -116,7 +116,7 @@ def GetTestSuite(path, mountpoint, options):

def ListTests(path):
"""lists tests in directory "path" ending in _test.py."""

pattern = re.compile("^\w*_test.py$", re.IGNORECASE)
tests = []
for test in os.listdir(path):
Expand Down

0 comments on commit aecc895

Please sign in to comment.