Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed useless code (mainly due to the refactoring of the rsync).

  • Loading branch information...
commit 62fd3df6a5df8516f3413a23b37c822889694044 1 parent adfd70c
@SeyZ authored
Showing with 7 additions and 110 deletions.
  1. +1 −54 baboond/executor.py
  2. +0 −49 baboond/task.py
  3. +6 −7 baboond/transport.py
View
55 baboond/executor.py
@@ -1,8 +1,7 @@
-import uuid
from threading import Thread
from Queue import PriorityQueue
-from task import EndTask, RsyncTask, MergeTask, AlertTask, CorruptedTask
+from task import EndTask, MergeTask, AlertTask, CorruptedTask
from common.logger import logger
from common.errors.baboon_exception import BaboonException
@@ -63,58 +62,6 @@ class Preparator():
""" The preparator builds the task and put it in the tasks queue.
"""
- # Stores the rsync task in a dict:
- # Key: req_id
- # Value: RsyncTask
- rsync_tasks = {}
-
- def prepare_rsync_start(self, project_name, username):
- """ Prepares the beginning of a new rsync task.
- """
-
- # Create the rsync task.
- rsync_task = RsyncTask(project_name, username)
- tasks.put(rsync_task)
-
- # Associate a uuid to the rsync task and store it into
- # rsync_tasks dict.
- req_id = str(uuid.uuid4())
- self.rsync_tasks[req_id] = rsync_task
-
- # TODO - Permission !
- # Return all the necessary information to the baboon client.
- ret = {'req_id': req_id,
- 'remote_dir': 'seyz@%s:/tmp/%s/%s/' % \
- (self.config.baboonsrv_host, project_name, username)
- }
-
- # Return the dict
- return ret
-
- def prepare_rsync_stop(self, req_id):
- """ The rsync transaction with the req_id and prepares a new
- rsync stop task to warn the associated rsync_task it's
- completed.
- """
-
- try:
- # Gets the rsync task in the rsync_tasks dict with the
- # req_id key.
- rsync_task = self.rsync_tasks.pop(req_id)
-
- # Throws the event to warn the rsync is now completed.
- rsync_task.ready.set()
-
- # Returns True to say the request is correctly completed.
- return True
- except KeyError:
- self.logger.debug("Cannot find the rsync transaction with the key"
- " %s" % req_id)
-
- # Returns False because the request cannot be completed
- # due to the bad req_id.
- return False
-
def prepare_merge_verification(self, node, jid):
""" Prepares a new merge verification task.
"""
View
49 baboond/task.py
@@ -2,7 +2,6 @@
import subprocess
import executor
-from threading import Event
from transport import transport
from common.logger import logger
from common.errors.baboon_exception import BaboonException
@@ -79,54 +78,6 @@ def run(self):
@logger
-class RsyncTask(Task):
- """ A task to rsync the local repository of the baboon client and
- the server.
- """
-
- def __init__(self, project_name, username):
- """ Initialize the RsyncTask
- """
-
- # The priority is lower than MergeTask in order to have a
- # higher priority.
- super(RsyncTask, self).__init__(3)
-
- self.project_name = project_name
- self.username = username
-
- self.ready = Event()
-
- def run(self):
- self.logger.info("Wait rsync... !")
-
- # Times out after the <arg> second(s).
- no_timeout = self.ready.wait(30)
-
- # If the no_timeout is False, it means the request was too
- # long.
- if no_timeout is False:
- # The user's repository on the server can be
- # corrupted. So, marks the repository to be in corrupted
- # mode.
- executor.preparator.prepare_corrupted(self.project_name,
- self.username)
- raise BaboonException('The rsync request takes too long time.')
- else:
- self.logger.info("The rsync is finished !")
-
- # If the repository was corrupted, remove the .lock file
- # to say it's now good.
- cwd = os.path.join(config.working_dir, self.project_name,
- self.username)
- cwd_lock = os.path.join(cwd, '.lock')
- if os.path.exists(cwd_lock):
- os.remove(cwd_lock)
- self.logger.debug("The %s directory was corrupted. It's now"
- " fixed." % cwd)
-
-
-@logger
class CorruptedTask(Task):
""" A task to mark a repository in corrupted mode.
"""
View
13 baboond/transport.py
@@ -15,10 +15,6 @@
from common import pyrsync
-# Registers pending rsyncs.
-rsyncs = {}
-
-
@logger
class Transport(sleekxmpp.ClientXMPP):
""" The transport has the responsability to communicate with the
@@ -45,6 +41,9 @@ def __init__(self):
StanzaPath('iq@type=set/merge'),
self._handle_merge_verification))
+ # Registers pending rsyncs.
+ self.rsyncs = {}
+
if self.connect():
self.process()
@@ -63,7 +62,7 @@ def _handle_rsync(self, iq):
# Registers the reply iq to the rsyncs dict. This result IQ
# will be sent when the rsync is completely finished.
- rsyncs[sid] = reply
+ self.rsyncs[sid] = reply
# Sets the future socket response dict.
ret = {'sid': sid}
@@ -164,14 +163,14 @@ def on_recv(self, recv):
os.remove(save_fd.name)
# Gets the reply IQ associated to the SID.
- reply_iq = rsyncs.get(sid)
+ reply_iq = self.rsyncs.get(sid)
if reply_iq:
# The rsync is completely finished. It's time to send the
# reply IQ to warn the client-side.
reply_iq.send()
# Removes the pending rsync from the rsyncs dict.
- del rsyncs[sid]
+ del self.rsyncs[sid]
else:
# TODO: Handle this error.
pass
Please sign in to comment.
Something went wrong with that request. Please try again.