# Path: mirror/task.py
# class Task(AbstractTask):
#     def __init__(self, name, scheduler_ref=None, **taskinfo):
#         super(Task, self).__init__(name, scheduler_ref, **taskinfo)
# 
#         try:
#             self.upstream = taskinfo['upstream[]']
#             self.rsyncdir = taskinfo['rsyncdir']
#             if self.rsyncdir[-1] != '/':
#                 self.rsyncdir += '/'
#             self.localdir = taskinfo['localdir']
#             if not os.path.exists(self.localdir):
#                 try:
#                     os.makedirs(self.localdir, 0o755)
#                 except:
#                     log.error("Error when create directory: %s", self.localdir)
#         except KeyError as e:
#             log.error("Error in config for mirror: %s, key: %s not found.", self.name, e)
#             self.enabled  = False
# 
#         self.exclude  = taskinfo['exclude'] if "exclude" in taskinfo else None
#         self.args     = taskinfo['args']    if "args" in taskinfo    else DEFAULT_ARGS
# 
#     def get_args(self, stage = 1):
#         args  = [os.path.basename(self.command)]
#         args += shlex.split(self.args)
#         if self.twostage and stage == 2:
#             args.remove("--delete")
#             args.append("--delete-after")
#         if self.exclude:
#             args += shlex.split(self.exclude)
#         if self.twostage and stage == 1:
#             args += [self.upstream[0] + '::' + self.rsyncdir + self.firststage + '/',\
#                      self.localdir + '/' + self.firststage]
#             return args
#         if self.twostage and stage == 2:
#             args += ['--exclude', '/' + self.firststage + '/']
#         args += [self.upstream[0] + '::' + self.rsyncdir,\
#                  self.localdir]
#         return args


import unittest
import time
from mirror.task import Task
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# mirror is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mirror. If not, write to:
#   The Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor
#   Boston, MA  02110-1301, USA.
#
#



class TaskTestCase(unittest.TestCase):

    def test_task(self):
        config = {
                 'upstream[]': 'mirror.bjtu.edu.cn',
                 'command': 'rsync',
                 'exclude': '',
                 'time':  '* */2 * * *',
                 'rsyncdir': 'archlinux/',

# Path: mirror/task.py
# class Task(AbstractTask):
#     def __init__(self, name, scheduler_ref=None, **taskinfo):
#         super(Task, self).__init__(name, scheduler_ref, **taskinfo)
# 
#         try:
#             self.upstream = taskinfo['upstream[]']
#             self.rsyncdir = taskinfo['rsyncdir']
#             if self.rsyncdir[-1] != '/':
#                 self.rsyncdir += '/'
#             self.localdir = taskinfo['localdir']
#             if not os.path.exists(self.localdir):
#                 try:
#                     os.makedirs(self.localdir, 0o755)
#                 except:
#                     log.error("Error when create directory: %s", self.localdir)
#         except KeyError as e:
#             log.error("Error in config for mirror: %s, key: %s not found.", self.name, e)
#             self.enabled  = False
# 
#         self.exclude  = taskinfo['exclude'] if "exclude" in taskinfo else None
#         self.args     = taskinfo['args']    if "args" in taskinfo    else DEFAULT_ARGS
# 
#     def get_args(self, stage = 1):
#         args  = [os.path.basename(self.command)]
#         args += shlex.split(self.args)
#         if self.twostage and stage == 2:
#             args.remove("--delete")
#             args.append("--delete-after")
#         if self.exclude:
#             args += shlex.split(self.exclude)
#         if self.twostage and stage == 1:
#             args += [self.upstream[0] + '::' + self.rsyncdir + self.firststage + '/',\
#                      self.localdir + '/' + self.firststage]
#             return args
#         if self.twostage and stage == 2:
#             args += ['--exclude', '/' + self.firststage + '/']
#         args += [self.upstream[0] + '::' + self.rsyncdir,\
#                  self.localdir]
#         return args


# Path: test/test_task.py
import unittest
import time
from mirror.task import Task

#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# mirror is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mirror. If not, write to:
#   The Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor
#   Boston, MA  02110-1301, USA.
#
#



class TaskTestCase(unittest.TestCase):

    def test_task(self):
        config = {
                 'upstream[]': 'mirror.bjtu.edu.cn',
                 'command': 'rsync',
                 'exclude': '',
                 'time':  '* */2 * * *',
                 'rsyncdir': 'archlinux/',

                 'localdir': '/tmp/mirror/archlinux',