Commits

Ronny Pfannschmidt committed 11d3dd0 Merge

merge from default

Comments (0)

Files changed (1)

scripts/lodgeit.py

 
     A script that pastes stuff into the lodgeit pastebin.
 
-    .lodgeitrc / _lodgeitrc
-    -----------------------
+    lodgeitrc config file
+    ---------------------
 
-    Under UNIX create a file called ``~/.lodgeitrc``, under Windows
-    create a file ``%APPDATA%/_lodgeitrc`` to override defaults::
+    Under UNIX create a file called ``~/.lodgeitrc`` for user and/or
+    system-wide ``/etc/lodgeitrc``, under Windows create a file
+    ``%APPDATA%/_lodgeitrc`` to override defaults::
 
+        server_name=default_server_base_url
         language=default_language
         clipboard=true/false
         open_browser=true/false
               2006 Armin Ronacher <armin.ronacher@active-4.com>,
               2006 Matt Good <matt@matt-good.net>,
               2005 Raphael Slinckx <raphael@slinckx.net>
+    :license: BSD
 """
 import os
 import sys
 
 SCRIPT_NAME = os.path.basename(sys.argv[0])
 VERSION = '0.3'
-SETTING_KEYS = ['author', 'title', 'language', 'private', 'clipboard',
-                'open_browser', 'raw']
 
 # global server proxy
 _xmlrpc_service = None
     print >> sys.stderr, 'ERROR: %s' % msg
     sys.exit(code)
 
+def parse_rcfile(rcfile, key_list=None):
+    """Parse lodgeitrc file, return dict of settings."""
+    settings = {}
+    try:
+        f = open(rcfile)
+        for line in f:
+            if line.strip()[:1] in '#;':
+                continue
+            p = line.split('=', 1)
+            if len(p) == 2:
+                key = p[0].strip().lower()
+                if key_list is not None and key not in key_list:
+                    continue
+                if key in ('clipboard', 'open_browser', 'raw'):
+                    settings[key] = p[1].strip().lower() in \
+                                    ('true', '1', 'on', 'yes')
+                else:
+                    settings[key] = p[1].strip()
+        f.close()
+    except IOError:
+        pass
+    return settings
+
 
 def load_default_settings():
-    """Load the defaults from the lodgeitrc file."""
+    """Load the defaults from the lodgeitrc file(s)."""
+
     settings = {
         'language':     None,
         'clipboard':    True,
         'encoding':     'iso-8859-15',
         'server_name':  'http://paste.pocoo.org',
     }
-    rcfile = None
+    key_list = settings.keys()
+    rcfiles = ()
     if os.name == 'posix':
-        rcfile = os.path.expanduser('~/.lodgeitrc')
+        rcfiles = ('/etc/lodgeitrc',
+                   os.path.expanduser('~/.lodgeitrc'))
     elif os.name == 'nt' and 'APPDATA' in os.environ:
-        rcfile = os.path.expandvars(r'$APPDATA\_lodgeitrc')
-    if rcfile:
-        try:
-            f = open(rcfile)
-            for line in f:
-                if line.strip()[:1] in '#;':
-                    continue
-                p = line.split('=', 1)
-                if len(p) == 2:
-                    key = p[0].strip().lower()
-                    if key in settings:
-                        if key in ('clipboard', 'open_browser', 'raw'):
-                            settings[key] = p[1].strip().lower() in \
-                                            ('true', '1', 'on', 'yes')
-                        else:
-                            settings[key] = p[1].strip()
-            f.close()
-        except IOError:
-            pass
+        rcfiles = (os.path.expandvars(r'$APPDATA\_lodgeitrc'), )
+    for rc in rcfiles:
+        settings.update(parse_rcfile(rc, key_list))
     settings['tags'] = []
     settings['title'] = None
     return settings