Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Create simple copyfile overlord module that is able to send big files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof A. Adamski committed Aug 21, 2008
1 parent 4005973 commit 0502b27
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
41 changes: 41 additions & 0 deletions func/minion/modules/copyfile.py
Expand Up @@ -46,6 +46,47 @@ def checksum(self, thing):

return thissum.hexdigest()

def open(self, filepath, mode=None, uid=-1, gid=-1):
dirpath = os.path.dirname(filepath)
if not os.path.exists(dirpath):
os.makedirs(dirpath)

# Create empty file
try:
fo = open(filepath, 'w')
fo.close()
del fo
except (IOError, OSError), e:
# XXX logger output here
return -1

try:
# we could intify the mode here if it's a string
if mode:
os.chmod(filepath, mode)
if uid != -1 or gid != -1:
os.chown(filepath, uid, gid)
except (IOError, OSError), e:
return -1

return filepath

def append(self, filepath, filebuf):
if not os.path.exists(filepath):
# file disaperead
return -1

try:
fo = open(filepath, 'a')
fo.write(filebuf.data)
fo.close()
del fo
except (IOError, OSError), e:
# XXX logger output here
return -1

return 1


def copyfile(self, filepath, filebuf, mode=0644, uid=0, gid=0, force=None):
# -1 = problem file was not copied
Expand Down
16 changes: 1 addition & 15 deletions func/overlord/cmd_modules/copyfile.py
Expand Up @@ -49,19 +49,5 @@ def do(self, args):

self.server_spec = self.parentCommand.server_spec
self.getOverlord()

try:
fb = open(self.options.filename, "r").read()
except IOError, e:
sys.stderr.write("Unable to open file: %s: %s\n" % (self.options.filename, e))
return

st = os.stat(self.options.filename)
mode = stat.S_IMODE(st.st_mode)
uid = st.st_uid
gid = st.st_gid


data = xmlrpclib.Binary(fb)
results = self.overlord_obj.run("copyfile", "copyfile", [self.options.remotepath, data,
mode, uid, gid])
return self.overlord_obj.local.copyfile.send(self.options.filename, self.options.remotepath)
27 changes: 27 additions & 0 deletions func/overlord/modules/copyfile.py
@@ -0,0 +1,27 @@
from func.overlord import overlord_module
import os
import stat
import xmlrpclib

class copyfile(overlord_module.BaseModule):
def send(self, localpath, remotepath, bufsize=60000):
try:
f = open(localpath, "r")
except IOError, e:
sys.stderr.write("Unable to open file: %s: %s\n" % (self.options.filename, e))
return

st = os.stat(localpath)
mode = stat.S_IMODE(st.st_mode)
uid = st.st_uid
gid = st.st_gid

self.parent.run("copyfile", "open", [remotepath, mode, uid, gid])

while True:
data=f.read(bufsize)
if data:
self.parent.run("copyfile", "append", [remotepath, xmlrpclib.Binary(data)])
else:
break

0 comments on commit 0502b27

Please sign in to comment.