Skip to content
Browse files

moved profiling code to its own script and added __all__ to daap.py

  • Loading branch information...
1 parent 6bcf233 commit 14fed86af2ae2c04b23867787116784616ba13f3 jason committed Apr 20, 2006
Showing with 55 additions and 49 deletions.
  1. +4 −49 daap.py
  2. +51 −0 daap_profile.py
View
53 daap.py
@@ -12,12 +12,11 @@
import md5, md5daap
import gzip
import logging
+from cStringIO import StringIO
-log = logging.getLogger('daap')
+__all__ = ['DAAPError', 'DAAPObject', 'DAAPClient', 'DAAPSession', 'DAAPDatabase', 'DAAPPlaylist', 'DAAPTrack']
-# cStringIO is faster, but not subclassable
-#from StringIO import StringIO
-from cStringIO import StringIO
+log = logging.getLogger('daap')
# the itunes authentication hasher
seed_v2 = []
@@ -619,7 +618,6 @@ def main():
tracks[0].atom.printTree()
-
finally:
# this here, so we logout even if there's an error somewhere,
# or itunes will eventually refuse more connections.
@@ -628,47 +626,4 @@ def main():
session.logout()
except Exception: pass
- def main_profile():
- import hotshot
-
- prof = hotshot.Profile('daap.prof')
- connection = DAAPClient()
-
- # I'm new to this python thing. There's got to be a better idiom
- # for this.
- try: host = sys.argv[1]
- except IndexError: host = "localhost"
- try: port = sys.argv[2]
- except IndexError: port = 3689
-
- try:
- # do everything in a big try, so we can disconnect at the end
-
- connection.connect( host, port )
-
- # auth isn't supported yet. Just log in
- session = connection.login()
-
- prof.start()
-
- library = session.library()
- tracks = library.tracks()
-
- finally:
- # this here, so we logout even if there's an error somewhere,
- # or itunes will eventually refuse more connections.
- try:
- session.logout()
- except Exception: pass
-
- # save profiling data
- prof.stop()
- prof.close()
-
- # load profile data and print out stats
- import hotshot.stats
- stats = hotshot.stats.load("daap.prof")
- stats.print_stats()
-
- #main()
- main_profile()
+ main()
View
51 daap_profile.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+import sys
+import optparse
+import hotshot
+import hotshot.stats
+
+from daap import DAAPClient
+
+def main():
+
+ prof = hotshot.Profile('daap.prof')
+ connection = DAAPClient()
+
+ # I'm new to this python thing. There's got to be a better idiom
+ # for this.
+ try: host = sys.argv[1]
+ except IndexError: host = "localhost"
+ try: port = sys.argv[2]
+ except IndexError: port = 3689
+
+ try:
+ # do everything in a big try, so we can disconnect at the end
+
+ connection.connect( host, port )
+
+ # auth isn't supported yet. Just log in
+ session = connection.login()
+
+ prof.start()
+
+ library = session.library()
+ tracks = library.tracks()
+
+ finally:
+ # this here, so we logout even if there's an error somewhere,
+ # or itunes will eventually refuse more connections.
+ try:
+ session.logout()
+ except Exception: pass
+
+ # save profiling data
+ prof.stop()
+ prof.close()
+
+ # load profile data and print out stats
+ stats = hotshot.stats.load("daap.prof")
+ stats.print_stats()
+
+if __name__ == '__main__':
+ main()

0 comments on commit 14fed86

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