Commits

Anonymous committed 7f76ce3

moved database file and config relevant to user to ~/.pythaules

  • Participants
  • Parent commits a18a13a

Comments (0)

Files changed (6)

File pythaules/conf.py

+import os, os.path
+
+try:
+    import simplejson as json
+except ImportError:
+    import json
+
+_CONFIG_SKEL = dict(MUSIC_DIRS=[])
+
+class PythaulesConf:
+    BASE_DIR = os.path.expanduser('~/.pythaules')
+
+    if not os.path.exists(BASE_DIR):
+        print "creating %s" % BASE_DIR
+        os.mkdir(BASE_DIR)
+
+    if not os.path.exists(os.path.join(BASE_DIR, 'config.json')):
+        print "generating config skeleton in %s" % BASE_DIR
+        json.dump(_CONFIG_SKEL, open(os.path.join(BASE_DIR, 'config.json'), 'w'))
+
+    ADD_CONFIG = json.load(open(os.path.join(BASE_DIR, 'config.json'), 'r'))
+
+    MUSIC_DIRS = ADD_CONFIG['MUSIC_DIRS']
+
+    VERSION = '<version>'
+
+    PATH_TO_DB_FILE = os.path.join(BASE_DIR, 'collection.db')
+
+    ALLOWED_SUFFIXES = ['.mp3', '.ogg', '.flac']
+
+    BACKEND_DB_RPC = {'host': '127.0.0.1',
+                      'port' : 49152
+    }
+
+    BACKEND_AUDIO_RPC = {'host': '127.0.0.1',
+                         'port': 49153
+    }
+
+    FRONTEND_RPC = {'host': '127.0.0.1',
+                    'port': 49154
+    }
+
+

File pythaules/conf.py.tmpl

-class PythaulesConf:
-
-    # Path(s) to your music collection
-    #
-    # Example:
-    # 
-    # MUSIC_DIRS = ['/home/user/collection', 
-    #               '/home/user/audio_books', 
-    #               '/home/user/sounds'
-    #              ] 
-
-    MUSIC_DIRS = []
-    
-    # Normally, you don't need to edit anything below this line
-
-    VERSION = '<version>'
-
-    ALLOWED_SUFFIXES = ['.mp3', '.ogg', '.flac']
-
-    BACKEND_DB_RPC = {'host': '127.0.0.1',
-                      'port' : 49152
-    }
-
-    BACKEND_AUDIO_RPC = {'host': '127.0.0.1',
-                         'port': 49153
-    }
-
-    FRONTEND_RPC = {'host': '127.0.0.1',
-                    'port': 49154
-    }
-
-

File pythaules/database/backend.py

 from SimpleXMLRPCServer import SimpleXMLRPCServer as Server
 
 from pythaules.conf import PythaulesConf as conf
+import pythaules.database
 import pythaules.database.database as database
 
 class PythaulesBackend(object):
     def __init__(self):
         print "Welcome to Pythaules database backend"
         print "Establishing connection to database..."
-        self.__db = database.collectionDatabase("collection.db")
+        self.__db = database.collectionDatabase(conf.PATH_TO_DB_FILE)
         #print "Creating empty database..."
         #self.__db.createEmptyDatabase()
         #print "Filling database..."

File pythaules/database/build_database.py

             print "\nERROR: Please set the path(s) to your music collection in conf.py"
             return
         print "Establishing connection to database..."
-        self.__db = database.collectionDatabase("collection.db")
+        self.__db = database.collectionDatabase(conf.PATH_TO_DB_FILE)
         print "Creating empty database..."
         self.__db.createEmptyDatabase()
         print "Filling database from directories ", conf.MUSIC_DIRS

File pythaules/database/update_database.py

             print "\nERROR: Please set the path(s) to your music collection in conf.py"
             return
         print "Establishing connection to database..."
-        self.__db = database.collectionDatabase("collection.db")
+        self.__db = database.collectionDatabase(conf.PATH_TO_DB_FILE)
         print "Updating database from directories ", conf.MUSIC_DIRS
         self.__db.fillDatabase(conf.MUSIC_DIRS)
         print "Ready"
     long_description=open('README.txt').read(),
     install_requires=[
         'mutagen',
+        'simplejson',
     ]
 )