[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [bridgedb/master] Fix some issues that popped up during BridgeDB deployment



commit ce76133b4779011db023004d48288e606138b50e
Author: Christian Fromme <kaner@xxxxxxxxxx>
Date:   Tue Feb 15 19:45:12 2011 +0100

    Fix some issues that popped up during BridgeDB deployment
    - Install translations to ~/ by default instead of /usr
    - Use ~ as prefix by default
    - Make sure pseudo distributors don't end up as actual ring names
---
 README                  |    6 +++---
 bridgedb.conf           |    2 +-
 lib/bridgedb/Bridges.py |    4 ++++
 lib/bridgedb/Bucket.py  |   18 +++++++++++++++++-
 lib/bridgedb/I18n.py    |    6 ++++--
 setup.cfg               |    3 ++-
 6 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/README b/README
index a77369f..64b402a 100644
--- a/README
+++ b/README
@@ -3,9 +3,9 @@ To set up:
  - Install Python 2.4 or later.
  - Install Twisted-Web, Twisted-Mail, PyOpenSSL, and all their dependencies.
  - To run unit tests, "python setup.py test"
- - python setup.py install --prefix=$HOME
- - To generate translation files, run "python setup.py trans" and then run
-   "python setup.py install_data" to install them
+ - python setup.py install
+ - To generate translation files, run "python setup.py trans" 
+ - Run "python setup.py install_data" to install them
  - Edit bridgedb.conf; put it somewhere good.
  - Make sure that the input files referred to in bridgedb.conf exist.
    - You can make a self-signed certificate with
diff --git a/bridgedb.conf b/bridgedb.conf
index 91465c7..44422a7 100644
--- a/bridgedb.conf
+++ b/bridgedb.conf
@@ -140,4 +140,4 @@ EMAIL_INCLUDE_FINGERPRINTS=False
 #   HTTPS_SHARE : EMAIL_SHARE : RESERVED_SHARE
 RESERVED_SHARE=2
 
-FILE_BUCKETS = {}
\ No newline at end of file
+FILE_BUCKETS = {}
diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py
index 7ba5d6d..a06cf26 100644
--- a/lib/bridgedb/Bridges.py
+++ b/lib/bridgedb/Bridges.py
@@ -17,6 +17,7 @@ import socket
 import time
 
 import bridgedb.Storage
+import bridgedb.Bucket
 
 HEX_FP_LEN = 40
 ID_LEN = 20
@@ -453,6 +454,9 @@ class BridgeSplitter(BridgeHolder):
         ringname = db.insertBridgeAndGetRing(bridge, ringname, time.time())
         db.commit()
 
+        # Resolve pseudo distributor ring names
+        ringname = bridgedb.Bucket.getRealDistributorName(ringname)
+
         ring = self.ringsByName.get(ringname)
         ring.insert(bridge)
 
diff --git a/lib/bridgedb/Bucket.py b/lib/bridgedb/Bucket.py
index cf32ac9..39edaea 100644
--- a/lib/bridgedb/Bucket.py
+++ b/lib/bridgedb/Bucket.py
@@ -24,6 +24,22 @@ instead of 'unallocated'. This is why they are called pseudo-distributors.
 import time
 import bridgedb.Storage
 
+# What should pseudo distributors be prefixed with in the database so we can
+# distinguish them from real distributors?
+PSEUDO_DISTRI_PREFIX = "pseudo_"
+
+def getRealDistributorName(distributor):
+    """Return the *real* ring name for a given one. This is needed because
+       with pseudo distributors, we've got strings in the database that aren't
+       real distributors. 
+    """
+
+    # If it starts with "pseudo_", its really "unallocated"
+    if distributor.startswith(PSEUDO_DISTRI_PREFIX):
+        distributor = "unallocated"
+
+    return distributor
+
 class BucketData:
     """A file bucket value class.
        name      - Name of the bucket (From config)
@@ -95,7 +111,7 @@ class BucketManager:
         self.bucketList = []
         self.unallocatedList = []
         self.unallocated_available = False
-        self.distributor_prefix = "pseudo_"
+        self.distributor_prefix = PSEUDO_DISTRI_PREFIX
         self.db = bridgedb.Storage.Database(self.cfg.DB_FILE+".sqlite",
                                             self.cfg.DB_FILE)
 
diff --git a/lib/bridgedb/I18n.py b/lib/bridgedb/I18n.py
index 550b0b4..3383ec9 100644
--- a/lib/bridgedb/I18n.py
+++ b/lib/bridgedb/I18n.py
@@ -1,12 +1,14 @@
 # BridgeDB i18n strings & helper routines. The string should go into pootle
 
+import os
 import gettext
 
-def getLang(lang):
+def getLang(lang, localedir=os.path.expanduser("~") + "/share/locale"):
     """Return the Translation instance for a given language. If no Translation
        instance is found, return the one for 'en'
     """
-    return gettext.translation("bridgedb", languages=[lang], fallback="en")
+    return gettext.translation("bridgedb", localedir=localedir, 
+                               languages=[lang], fallback="en")
 
 def _(text):
     """This is necessary because strings are translated when they're imported.
diff --git a/setup.cfg b/setup.cfg
index e91c159..9fa8c68 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,2 +1,3 @@
 [install]
-install-data=/usr
+prefix=$HOME
+install-data=$HOME