You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/06/11 15:29:20 UTC

[GitHub] rabbah closed pull request #3483: Makes db tools python2 and python3 compatible

rabbah closed pull request #3483: Makes db tools python2 and python3 compatible
URL: https://github.com/apache/incubator-openwhisk/pull/3483
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tools/db/cleanUpActivations.py b/tools/db/cleanUpActivations.py
index d6c0cf359f..a51f73e42e 100755
--- a/tools/db/cleanUpActivations.py
+++ b/tools/db/cleanUpActivations.py
@@ -39,7 +39,7 @@ def deleteOldActivations(args):
     while True:
         activationIds = db.view("activations/byDate", limit=args.docsPerRequest, start_key=0, end_key=endkey)
         if activationIds:
-            documentsToDelete = map(lambda entry: couchdb.client.Document(_id=entry.value[0], _rev=entry.value[1], _deleted=True), activationIds)
+            documentsToDelete = [couchdb.client.Document(_id=entry.value[0], _rev=entry.value[1], _deleted=True) for entry in activationIds]
             db.update(documentsToDelete)
         else:
             return
diff --git a/tools/db/deleteLogsFromActivations.py b/tools/db/deleteLogsFromActivations.py
index ac2b424afb..7fa0973371 100755
--- a/tools/db/deleteLogsFromActivations.py
+++ b/tools/db/deleteLogsFromActivations.py
@@ -44,7 +44,7 @@ def deleteLogsFromOldActivations(args):
     while True:
         activations = db.view("logCleanup/byDateWithLogs", limit=args.docsPerRequest, start_key=0, end_key=endkey, include_docs=True)
         if activations:
-            activationsWithoutLogs = map(removeLogFromActivation, activations)
+            activationsWithoutLogs = [removeLogFromActivation(activation) for activation in activations]
             db.update(activationsWithoutLogs)
         else:
             return
diff --git a/tools/db/replicateDbs.py b/tools/db/replicateDbs.py
index ae4a4e1ccc..7de83a2357 100755
--- a/tools/db/replicateDbs.py
+++ b/tools/db/replicateDbs.py
@@ -43,7 +43,7 @@ def replicateDatabases(args):
     targetDb = couchdb.client.Server(args.targetDbUrl)
 
     excludedDatabases = args.exclude.split(",")
-    excludedBaseNames = filter(lambda x: x != "", args.excludeBaseName.split(","))
+    excludedBaseNames = [x for x in args.excludeBaseName.split(",") if x != ""]
 
     # Create _replicator DB if it does not exist yet.
     if "_replicator" not in sourceDb:
@@ -59,12 +59,12 @@ def isExcluded(dbName):
         # is the databaseName is in the list of excluded database
         isNameExcluded = dbNameWithoutPrefix in excludedDatabases
         # if one of the basenames matches, the database is excluded
-        isBaseNameExcluded = functools.reduce(lambda x, y: x or y, map(lambda en: dbNameWithoutPrefix.startswith(en), excludedBaseNames), False)
+        isBaseNameExcluded = functools.reduce(lambda x, y: x or y, [dbNameWithoutPrefix.startswith(en) for en in excludedBaseNames], False)
         return isNameExcluded or isBaseNameExcluded
 
     # Create backup of all databases with given prefix
     print("----- Create backups -----")
-    for db in filter(lambda dbName: dbName.startswith(args.dbPrefix) and not isExcluded(dbName), sourceDb):
+    for db in [dbName for dbName in sourceDb if dbName.startswith(args.dbPrefix) and not isExcluded(dbName)]:
         backupDb = backupPrefix + db if not args.continuous else 'continuous_' + db
         replicateDesignDocument = {
             "_id": backupDb,
@@ -92,14 +92,14 @@ def isExpired(timestamp):
 
     # Delete all documents in the _replicator-database of old backups to avoid that they continue after they are deprecated
     print("----- Delete backup-documents older than %d seconds -----" % args.expires)
-    for doc in filter(lambda doc: isBackupDb(doc.id) and isExpired(extractTimestamp(doc.id)), replicator.view('_all_docs', include_docs=True)):
+    for doc in [doc for doc in replicator.view('_all_docs', include_docs=True) if isBackupDb(doc.id) and isExpired(extractTimestamp(doc.id))]:
         print("deleting backup document: %s" % doc.id)
         # Get again the latest version of the document to delete the right revision and avoid Conflicts
         retry(lambda: replicator.delete(replicator[doc.id]), 5)
 
     # Delete all backup-databases, that are older than specified
     print("----- Delete backups older than %d seconds -----" % args.expires)
-    for db in filter(lambda db: isBackupDb(db) and isExpired(extractTimestamp(db)), targetDb):
+    for db in [db for db in targetDb if isBackupDb(db) and isExpired(extractTimestamp(db))]:
         print("deleting backup: %s" % db)
         targetDb.delete(db)
 
@@ -112,7 +112,7 @@ def replayDatabases(args):
     if "_replicator" not in sourceDb:
         sourceDb.create("_replicator")
 
-    for db in filter(lambda dbName: dbName.startswith(args.dbPrefix), sourceDb):
+    for db in [dbName for dbName in sourceDb if dbName.startswith(args.dbPrefix)]:
         plainDbName = db.replace(args.dbPrefix, "")
         (identifier, _) = sourceDb["_replicator"].save({
             "source": args.sourceDbUrl + "/" + db,


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services