def store_and_forward(self):

        self._read_header()
        header = self.json_header
        requests_a = header['requests']

        self._open_dest_files(requests_a)
        destinations = header['destinations']
        self._get_valid_vcons(destinations)
        self._process_io()

        # close all open files
        self._close_files()
        # read the footer from the sending machine
        self._read_footer()
        # send foot to all machines this is streaming to
        self._send_footer()
        # wait for eof and close
        self._close_connections()
        self._rename_files(requests_a)

        pylantorrent.log(logging.DEBUG, "All data sent %s %d" % (self.md5str, len(requests_a)))
        # if we got to here it was successfully written to a file
        # and we can call it success.  Print out a success message for 
        # everyfile written
        vex = LTException(0, "Success", header['host'], int(header['port']), requests_a, md5sum=self.md5str)
        s = vex.get_printable()
        self.print_results(s)
        self.clean_up()
示例#2
0
    def store_and_forward(self):

        self._read_header()
        header = self.json_header
        requests_a = header['requests']

        self._open_dest_files(requests_a)
        destinations = header['destinations']
        self._get_valid_vcons(destinations)
        self._process_io()

        # close all open files
        self._close_files()
        # read the footer from the sending machine
        self._read_footer()
        # send foot to all machines this is streaming to
        self._send_footer()
        # wait for eof and close
        self._close_connections()
        self._rename_files(requests_a)

        pylantorrent.log(
            logging.DEBUG,
            "All data sent %s %d" % (self.md5str, len(requests_a)))
        # if we got to here it was successfully written to a file
        # and we can call it success.  Print out a success message for
        # everyfile written
        vex = LTException(0,
                          "Success",
                          header['host'],
                          int(header['port']),
                          requests_a,
                          md5sum=self.md5str)
        s = vex.get_printable()
        self.print_results(s)
        self.clean_up()
示例#3
0
 def _open_dest_files(self, requests_a):
     files_a = []
     for req in requests_a:
         filename = req['filename']
         try:
             rn = req['rename']
             if rn:
                 filename = filename + self.suffix
             f = open(filename, "w")
             files_a.append(f)
             self.created_files.append(filename)
         except Exception, ex:
             pylantorrent.log(logging.ERROR,
                              "Failed to open %s" % (filename), traceback)
             raise LTException(503,
                               str(ex),
                               self.json_header['host'],
                               int(self.json_header['port']),
                               reqs=requests_a)
def main(argv=sys.argv[1:]):

    pylantorrent.log(logging.INFO, "server starting")
    rc = 1
    v = LTServer(sys.stdin, sys.stdout)
    try:
        v.store_and_forward()
        rc = 0
    except LTException, ve:
        pylantorrent.log(logging.ERROR, "error %s" % (str(ve)), traceback)
        s = ve.get_printable()
        v.print_results(s)
        v.clean_up()
    except Exception, ex:
        pylantorrent.log(logging.ERROR, "error %s" % (str(ex)), traceback)
        vex = LTException(500, str(ex))
        s = vex.get_printable()
        v.print_results(s)
        v.clean_up()

    return rc

if __name__ == "__main__":
    if 'LANTORRENT_HOME' not in os.environ:
        msg = "The env LANTORRENT_HOME must be set"
        print msg
        raise Exception(msg)

    rc = main()
    sys.exit(rc)
示例#5
0
def main(argv=sys.argv[1:]):

    pylantorrent.log(logging.INFO, "server starting")
    rc = 1
    v = LTServer(sys.stdin, sys.stdout)
    try:
        v.store_and_forward()
        rc = 0
    except LTException, ve:
        pylantorrent.log(logging.ERROR, "error %s" % (str(ve)), traceback)
        s = ve.get_printable()
        v.print_results(s)
        v.clean_up()
    except Exception, ex:
        pylantorrent.log(logging.ERROR, "error %s" % (str(ex)), traceback)
        vex = LTException(500, str(ex))
        s = vex.get_printable()
        v.print_results(s)
        v.clean_up()

    return rc


if __name__ == "__main__":
    if 'LANTORRENT_HOME' not in os.environ:
        msg = "The env LANTORRENT_HOME must be set"
        print msg
        raise Exception(msg)

    rc = main()
    sys.exit(rc)