You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by le...@apache.org on 2005/12/12 11:37:36 UTC

svn commit: r356243 - in /gump/branches/Gump3/pygump/python: gump/config.py gump/engine/algorithm.py gump/engine/persistence.py gump/util/autopickling.py main.py

Author: leosimons
Date: Mon Dec 12 02:37:30 2005
New Revision: 356243

URL: http://svn.apache.org/viewcvs?rev=356243&view=rev
Log:
Make pickling stuff work in general by not pickling stuff we can't pickle in a brute-force way. Add some utility code to save *all* stuff in a workspace, not just info on the successful builds.

Added:
    gump/branches/Gump3/pygump/python/gump/util/autopickling.py
Modified:
    gump/branches/Gump3/pygump/python/gump/config.py
    gump/branches/Gump3/pygump/python/gump/engine/algorithm.py
    gump/branches/Gump3/pygump/python/gump/engine/persistence.py
    gump/branches/Gump3/pygump/python/main.py

Modified: gump/branches/Gump3/pygump/python/gump/config.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/config.py?rev=356243&r1=356242&r2=356243&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/config.py (original)
+++ gump/branches/Gump3/pygump/python/gump/config.py Mon Dec 12 02:37:30 2005
@@ -335,9 +335,11 @@
           Phooey...you're very on-the-edge at the moment!""")
         import shelve
         shelf = shelve.open(config.persistence_file)
+        
+        ws_shelf = shelve.open(config.turbogump_db)
     
         from gump.engine.persistence import ShelfBasedPersistenceHelper
-        helper = ShelfBasedPersistenceHelper(shelf, log)
+        helper = ShelfBasedPersistenceHelper(shelf, ws_shelf, log)
         return helper
     else:
         log.info("Not using persistence! (pass --enable-persistence to enable)")

Modified: gump/branches/Gump3/pygump/python/gump/engine/algorithm.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/algorithm.py?rev=356243&r1=356242&r2=356243&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/algorithm.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/algorithm.py Mon Dec 12 02:37:30 2005
@@ -176,6 +176,9 @@
     
     def stop_using_previous_build(self, *args):
         pass
+    
+    def save_workspace(self, *args):
+        pass
 
 DEFAULT_PROJECT_REGEX = ".*"
 DEFAULT_PROJECT_LIST = []
@@ -298,5 +301,6 @@
         for project in workspace.projects:
             self.persistence_helper.stop_using_previous_build(project)
         self.persistence_helper.store_previous_builds(workspace)
+        self.persistence_helper.save_workspace(workspace)
         self.project_model_list = []
         self.module_model_list = []

Modified: gump/branches/Gump3/pygump/python/gump/engine/persistence.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/persistence.py?rev=356243&r1=356242&r2=356243&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/persistence.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/persistence.py Mon Dec 12 02:37:30 2005
@@ -59,18 +59,41 @@
 from gump.model.util import get_project_directory, check_failure, check_skip
 from gump.model.util import mark_previous_build
 from gump.util.sync import smart_sync
+from gump.util.autopickling import add_pickle_support
 import os
 import shutil
 import copy
 
 GUMP_STORAGE_DIRNAME=".gump-persist"
 
+PICKLEABLE_MODEL=False
+def ensure_pickleable_model():
+    global PICKLEABLE_MODEL
+    if PICKLEABLE_MODEL:
+        return
+    
+    PICKLEABLE_MODEL = True
+    classtype = type(Workspace)
+    import gump.model
+    for x in dir(gump.model):
+        v = getattr(gump.model, x)
+        if isinstance(v, type(classtype)):
+            add_pickle_support(v)
+
 class ShelfBasedPersistenceHelper:
-    def __init__(self, shelf, log):
+    def __init__(self, shelf, ws_shelf, log):
         self.shelf = shelf
+        self.ws_shelf = ws_shelf
         self.log = log
+    
+    def save_workspace(self, workspace):
+        ensure_pickleable_model()
+        import time
+        key = time.strftime('%Y%m%d-%H%M')
+        self.ws_shelf[key] = workspace
         
     def store_previous_builds(self, workspace):
+        ensure_pickleable_model()
         for project in workspace.projects.values():
             if check_failure(project) or\
                check_skip(project) or \

Added: gump/branches/Gump3/pygump/python/gump/util/autopickling.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/autopickling.py?rev=356243&view=auto
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/autopickling.py (added)
+++ gump/branches/Gump3/pygump/python/gump/util/autopickling.py Mon Dec 12 02:37:30 2005
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+# Copyright 2004-2005 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+def _needs_support(obj):
+    try:
+        import cPickle as pickle
+    except:
+        import pickle
+    
+    try:
+        pickle.dumps(obj)
+        return False
+    except TypeError:
+        return True
+
+def add_pickle_support(klass):
+    if not _needs_support(klass):
+        return
+    
+    def getstate(self):
+        newdict = self.__dict__.copy()
+        for k,v in self.__dict__.iteritems():
+            if _needs_support(v):
+                del newdict[k]
+        return newdict
+    
+    klass.__getstate__ = getstate

Modified: gump/branches/Gump3/pygump/python/main.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/main.py?rev=356243&r1=356242&r2=356243&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/main.py (original)
+++ gump/branches/Gump3/pygump/python/main.py Mon Dec 12 02:37:30 2005
@@ -58,7 +58,8 @@
 def get_parser(_homedir=None, _hostname=None, _projects=None, _workdir=None,
                _logdir=None, _workspace=None, _databaseserver="localhost",
                _databaseport=3306, _databasename="gump", _databaseuser="gump",
-               _databasepassword=None, _persistencefile="gumpshelf"):
+               _databasepassword=None, _persistencefile="gumpshelf",
+               _turbogumpdb="turbogumpdb"):
     """Pygump uses the optparse package to provide the CLI.
     
     To add new options to pygump, change this method and document the changes
@@ -170,6 +171,11 @@
                       action="store_true",
                       dest="enable_persistence",
                       default=False, # Default to NOT. At least during initial development...
+                      help="enable ***experimental*** persistence support")
+    parser.add_option("--turbogump-db",
+                      action="store",
+                      dest="turbogump_db",
+                      default=_turbogumpdb,
                       help="enable ***experimental*** persistence support")
     parser.add_option("--color",
                       action="store_true",