Changeset 40dd8c1


Ignore:
Timestamp:
Sep 9, 2009 9:52:44 AM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-2.00, version-3.01, version-3.02
Children:
11860f52
Parents:
f07fa49
Message:

make file_copy a utility route so many can use it.

Location:
fedd/federation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/experiment_control.py

    rf07fa49 r40dd8c1  
    339339        }
    340340
    341     def copy_file(self, src, dest, size=1024):
    342         """
    343         Exceedingly simple file copy.
    344         """
    345         s = open(src,'r')
    346         d = open(dest, 'w')
    347 
    348         buf = "x"
    349         while buf != "":
    350             buf = s.read(size)
    351             d.write(buf)
    352         s.close()
    353         d.close()
    354 
    355341    # Call while holding self.state_lock
    356342    def write_state(self):
     
    362348        """
    363349        if os.access(self.state_filename, os.W_OK):
    364             self.copy_file(self.state_filename, \
    365                     "%s.bak" % self.state_filename)
     350            copy_file(self.state_filename, \
     351                    "%s.bak" % self.state_filename)
    366352        try:
    367353            f = open(self.state_filename, 'w')
     
    16021588                        "Cannot write hosts file: %s" % e)
    16031589            try:
    1604                 self.copy_file("%s" % gw_pubkey, "%s/%s" % \
     1590                copy_file("%s" % gw_pubkey, "%s/%s" % \
    16051591                        (configdir, gw_pubkey_base))
    1606                 self.copy_file("%s" % gw_secretkey, "%s/%s" % \
     1592                copy_file("%s" % gw_secretkey, "%s/%s" % \
    16071593                        (configdir, gw_secretkey_base))
    16081594            except IOError, e:
  • fedd/federation/util.py

    rf07fa49 r40dd8c1  
    153153            log.error("Bad experiment_log value: %s" % level_str)
    154154
     155def copy_file(src, dest, size=1024):
     156    """
     157    Exceedingly simple file copy.  Throws an IOError if there's a problem.
     158    """
     159    s = open(src,'r')
     160    d = open(dest, 'w')
     161
     162    buf = s.read(size)
     163    while buf != "":
     164        d.write(buf)
     165        buf = s.read(size)
     166    s.close()
     167    d.close()
     168
Note: See TracChangeset for help on using the changeset viewer.