Move data tools to util.py. Remove legacy marshal garbage. default tip
authorSam Hart <criswellious@gmail.com>
Sun Apr 06 22:56:04 2008 -0400 (15 months ago)
changeset 2686ceb8700106f
parent 267f6e82d635465
Move data tools to util.py. Remove legacy marshal garbage.
swarmlib/data_tools.py
swarmlib/hive.py
swarmlib/util.py
       1 --- a/swarmlib/hive.py	Sun Apr 06 22:40:23 2008 -0400
       2 +++ b/swarmlib/hive.py	Sun Apr 06 22:56:04 2008 -0400
       3 @@ -23,6 +23,8 @@
       4  """
       5  
       6  import urlparse
       7 +
       8 +#from swarmlib.exceptions import 
       9  
      10  class Hive(object):
      11      def __init__(self, url, log, Force=False, config=None):
      12 @@ -64,6 +66,13 @@
      13          """
      14          Called when a new Hive is to be initialized
      15          """
      16 +        config = Config.config(working_dir, log, force)
      17 +        project_hash = data_tools.get_hash(project_name, swarm_time.human_readable_from_stamp(), socket.getfqdn())
      18 +        config.init(project_name, project_hash)
      19 +        xactions = xaction.xaction_dispatch()
      20 +        db = swarmdb(working_dir, config, log, xactions, force)
      21 +        db.backend.init()
      22 +        db.backend.close()
      23  
      24      def connect(self):
      25          """
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/swarmlib/util.py	Sun Apr 06 22:56:04 2008 -0400
     1.3 @@ -0,0 +1,39 @@
     1.4 +#!/usr/bin/env python
     1.5 +#
     1.6 +# data_tools - Various tools to manipulate data
     1.7 +#
     1.8 +# Copyright 2007 Sam Hart
     1.9 +#
    1.10 +# This program is free software; you can redistribute it and/or modify
    1.11 +# it under the terms of the GNU General Public License as published by
    1.12 +# the Free Software Foundation; either version 2 of the License, or
    1.13 +# (at your option) any later version.
    1.14 +#
    1.15 +# This program is distributed in the hope that it will be useful,
    1.16 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 +# GNU General Public License for more details.
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License
    1.21 +# along with this program; if not, write to the Free Software
    1.22 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.23 +#
    1.24 +# Author: Sam Hart
    1.25 +
    1.26 +"""
    1.27 +Swarm utility functions
    1.28 +
    1.29 +A collection of utility functions used by Swarm
    1.30 +"""
    1.31 +
    1.32 +import sha
    1.33 +
    1.34 +def get_hash(str1, str2, str3):
    1.35 +    """
    1.36 +    get_unique_hash(str1, str2, str3):
    1.37 +    Given three strings, will return a unique hex hash
    1.38 +    """
    1.39 +    h = sha.new(str1)
    1.40 +    h.update(str2)
    1.41 +    h.update(str3)
    1.42 +    return h.hexdigest()
     2.1 --- a/swarmlib/data_tools.py	Sun Apr 06 22:40:23 2008 -0400
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,47 +0,0 @@
     2.4 -#!/usr/bin/env python
     2.5 -
     2.6 -# data_tools - Various tools to manipulate data
     2.7 -#
     2.8 -# Copyright 2007 Sam Hart
     2.9 -#
    2.10 -# This program is free software; you can redistribute it and/or modify
    2.11 -# it under the terms of the GNU General Public License as published by
    2.12 -# the Free Software Foundation; either version 2 of the License, or
    2.13 -# (at your option) any later version.
    2.14 -
    2.15 -# This program is distributed in the hope that it will be useful,
    2.16 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.17 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.18 -# GNU General Public License for more details.
    2.19 -
    2.20 -# You should have received a copy of the GNU General Public License
    2.21 -# along with this program; if not, write to the Free Software
    2.22 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.23 -#
    2.24 -# Author: Sam Hart
    2.25 -
    2.26 -import marshal
    2.27 -import binascii
    2.28 -import sha
    2.29 -
    2.30 -# FIXME
    2.31 -# The following needs to go away... it's being moved into xaction since that's
    2.32 -# where it'll *only* be used. Also, we don't want to use marshal, I was misinformed
    2.33 -# as to what it did... turns out I likely want pickle instead
    2.34 -#def encode_content(content_obj):
    2.35 -#    """
    2.36 -#    encode_content(content_obj)
    2.37 -#    Given some sort of content that is marshalable, will
    2.38 -#    encode it into a transportable format
    2.39 -#    """
    2.40 -#    return binascii.hexlify(marshal.dumps(content_obj))
    2.41 -
    2.42 -def get_hash(str1, str2, str3):
    2.43 -    """
    2.44 -    get_unique_hash(str1, str2, str3):
    2.45 -    Given three strings, will return a unique hex hash
    2.46 -    """
    2.47 -    h = sha.new(str1)
    2.48 -    h.update(str2)
    2.49 -    h.update(str3)
    2.50 -    return h.hexdigest()