Exemple #1
0
    def _store_file(self, file_content, user_login, session_id):
        # TODO: this is a very dirty way to implement this.
        # Anyway until the good approach is taken, this will store the students programs.
        def get_time_in_str():
            cur_time = self._time.time()
            s = self._time.strftime('%Y_%m_%d___%H_%M_%S_',
                                    self._time.gmtime(cur_time))
            millis = int((cur_time - int(cur_time)) * 1000)
            return s + str(millis)

        file_content = file_content.commandstring
        if isinstance(file_content, unicode):
            file_content_encoded = file_content.encode('utf8')
        else:
            file_content_encoded = file_content
        deserialized_file_content = ExperimentUtil.deserialize(
            file_content_encoded)
        storage_path = self._cfg_manager.get_value(
            'proxy_store_students_programs_path')
        relative_file_path = get_time_in_str(
        ) + '_' + user_login + '_' + session_id
        sha_obj = hashlib.new('sha')
        sha_obj.update(deserialized_file_content)
        file_hash = sha_obj.hexdigest()
        where = storage_path + '/' + relative_file_path
        f = open(where, 'w')
        f.write(deserialized_file_content)
        f.close()
        return relative_file_path, "{sha}%s" % file_hash
    def _store_file(self, file_content, user_login, session_id):
        # TODO: this is a very dirty way to implement this.
        # Anyway until the good approach is taken, this will store the students programs.
        def get_time_in_str():
            cur_time = self._time.time()
            s = self._time.strftime('%Y_%m_%d___%H_%M_%S_', self._time.gmtime(cur_time))
            millis = int((cur_time - int(cur_time)) * 1000)
            return s + str(millis)

        file_content = file_content.commandstring
        if isinstance(file_content, unicode):
            file_content_encoded = file_content.encode('utf8')
        else:
            file_content_encoded = file_content
        deserialized_file_content = ExperimentUtil.deserialize(file_content_encoded)
        storage_path = self._cfg_manager.get_value('proxy_store_students_programs_path')
        relative_file_path = get_time_in_str() + '_' + user_login + '_' + session_id
        sha_obj            = hashlib.new('sha')
        sha_obj.update(deserialized_file_content)
        file_hash          = sha_obj.hexdigest()
        where = storage_path + '/' + relative_file_path
        f = open(where,'w')
        f.write(deserialized_file_content)
        f.close()
        return relative_file_path, "{sha}%s" % file_hash
Exemple #3
0
    def store_file(self, file_content, file_info):
        import weblab.data.experiments as Experiments

        # TODO: this is a very dirty way to implement this. Anyway until the good approach is taken, this will store the students programs
        # TODO: there should be two global variables: first, if store_student_files is not activated, do nothing.
        #       but, if store_student_files is activated, it should check that for a given experiment, they should be stored or not.
        #       For instance, I may want to store GPIB experiments but not FPGA experiments. Indeed, this should be stored in the db
        #       in the permission of the student/group with the particular experiment, with a default value to True.
        should_i_store = self._cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS)
        timestamp_before   = self._utc_timestamp()
        if should_i_store:
            # TODO not tested
            if isinstance(file_content, unicode):
                file_content_encoded = file_content.encode('utf8')
            else:
                file_content_encoded = file_content
            deserialized_file_content = ExperimentUtil.deserialize(file_content_encoded)
            storage_path = self._cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS_PATH)
            relative_file_path = _get_time_in_str() + '_' + self._reservation_id
            file_hash = sha0(deserialized_file_content)

            where = storage_path + '/' + relative_file_path
            f = open(where,'w')
            f.write(deserialized_file_content)
            f.close()

            return Experiments.FileSent(relative_file_path, "{sha}%s" % file_hash, timestamp_before, file_info = file_info)
        else:
            return Experiments.FileSent("<file not stored>","<file not stored>", timestamp_before, file_info = file_info)
Exemple #4
0
    def _program_file(self, file_content):
        try:
            fd, file_name = tempfile.mkstemp(
                prefix="ud_xilinx_experiment_program", suffix="." + self._xilinx_impact.get_suffix()
            )
            try:
                try:
                    # TODO: encode? utf8?
                    if isinstance(file_content, unicode):
                        file_content_encoded = file_content.encode("utf8")
                    else:
                        file_content_encoded = file_content
                    file_content_recovered = ExperimentUtil.deserialize(file_content_encoded)
                    os.write(fd, file_content_recovered)
                finally:
                    os.close(fd)
                self._programmer.program(file_name)
            finally:
                os.remove(file_name)
                # print file_name
                # import sys
                # sys.stdout.flush()
        except Exception as e:

            # TODO: test me
            log.log(UdXilinxExperiment, log.level.Info, "Exception joining sending program to device: %s" % e.args[0])
            log.log_exc(UdXilinxExperiment, log.level.Debug)
            raise ExperimentErrors.SendingFileFailureError("Error sending file to device: %s" % e)
        self._clear()
Exemple #5
0
    def _program_file(self, file_content):
        try:
            fd, file_name = tempfile.mkstemp(
                prefix='ud_xilinx_experiment_program',
                suffix='.' + self._programmer.get_suffix())
            try:
                try:
                    # TODO: encode? utf8?
                    if isinstance(file_content, unicode):
                        file_content_encoded = file_content.encode('utf8')
                    else:
                        file_content_encoded = file_content
                    file_content_recovered = ExperimentUtil.deserialize(
                        file_content_encoded)
                    os.write(fd, file_content_recovered)
                finally:
                    os.close(fd)
                self._programmer.program(file_name)
            finally:
                os.remove(file_name)
                # print file_name
                # import sys
                # sys.stdout.flush()
        except Exception as e:

            # TODO: test me
            log.log(
                ElevatorExperiment, log.level.Info,
                "Exception programming the logic into the board: %s" %
                e.args[0])
            log.log_exc(ElevatorExperiment, log.level.Debug)
            raise ExperimentErrors.SendingFileFailureError(
                "Error sending file to device: %s" % e)
        self._clear()
    def store_file(self, file_content, file_info):
        import weblab.data.experiments as Experiments

        # TODO: this is a very dirty way to implement this. Anyway until the good approach is taken, this will store the students programs
        # TODO: there should be two global variables: first, if store_student_files is not activated, do nothing.
        #       but, if store_student_files is activated, it should check that for a given experiment, they should be stored or not.
        #       For instance, I may want to store GPIB experiments but not FPGA experiments. Indeed, this should be stored in the db
        #       in the permission of the student/group with the particular experiment, with a default value to True.
        should_i_store = self._cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS)
        timestamp_before   = self._utc_timestamp()
        if should_i_store:
            # TODO not tested
            if isinstance(file_content, unicode):
                file_content_encoded = file_content.encode('utf8')
            else:
                file_content_encoded = file_content
            deserialized_file_content = ExperimentUtil.deserialize(file_content_encoded)
            storage_path = self._cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS_PATH)
            relative_file_path = _get_time_in_str() + '_' + self._reservation_id
            sha_obj            = hashlib.new('sha')
            sha_obj.update(deserialized_file_content)
            file_hash          = sha_obj.hexdigest()

            where = storage_path + '/' + relative_file_path
            f = open(where,'w')
            f.write(deserialized_file_content)
            f.close()

            return Experiments.FileSent(relative_file_path, "{sha}%s" % file_hash, timestamp_before, file_info = file_info)
        else:
            return Experiments.FileSent("<file not stored>","<file not stored>", timestamp_before, file_info = file_info)
Exemple #7
0
 def _program_file(self, file_content):
     try:
         fd, file_name = tempfile.mkstemp(prefix='pic18_experiment_program',
                                          suffix='.hex')
         try:
             try:
                 #TODO: encode? utf8?
                 if isinstance(file_content, unicode):
                     file_content_encoded = file_content.encode('utf8')
                 else:
                     file_content_encoded = file_content
                 file_content_recovered = ExperimentUtil.deserialize(
                     file_content_encoded)
                 os.write(fd, file_content_recovered)
             finally:
                 os.close(fd)
             print "File ready in %s" % file_name
             self._programmer.program(file_name)
             print "File sent with programmer: ", self._programmer
         finally:
             os.remove(file_name)
     except Exception as e:
         print "Error sending file"
         import traceback
         traceback.print_exc()
         #TODO: test me
         log.log(
             UdPic18Experiment, log.level.Info,
             "Exception joining sending program to device: %s" % e.args[0])
         log.log_exc(UdPic18Experiment, log.level.Debug)
         raise ExperimentExceptions.SendingFileFailureException(
             "Error sending file to device: %s" % e)
Exemple #8
0
 def _extract_content(self, initial_content):
     #TODO: encode? utf8?
     if isinstance(initial_content, unicode):
         file_content_encoded = initial_content.encode('utf8')
     else:
         file_content_encoded = initial_content
     file_content_recovered = ExperimentUtil.deserialize(file_content_encoded)
     return file_content_recovered
Exemple #9
0
 def _extract_content(self, initial_content):
     #TODO: encode? utf8?
     if isinstance(initial_content, unicode):
         file_content_encoded = initial_content.encode('utf8')
     else:
         file_content_encoded = initial_content
     file_content_recovered = ExperimentUtil.deserialize(
         file_content_encoded)
     return file_content_recovered
Exemple #10
0
    def _program_file(self, file_content):
        try:
            fd, file_name = tempfile.mkstemp(
                prefix='ud_xilinx_experiment_program',
                suffix='.' + self._programmer.get_suffix()
            )  # Originally the Programmer wasn't the one to contain the suffix info.

            if DEBUG:
                print "[DBG]: 2"
                df2 = open("/tmp/orig_content", "w")
                df2.write("---begin---\n")
                df2.write(file_content)
                df2.close()

                # For debugging purposes write the file to tmp
                df = open("/tmp/toprogram_dbg", "w")
            try:
                try:
                    # TODO: encode? utf8?
                    if isinstance(file_content, unicode):
                        if DEBUG: print "[DBG]: Encoding file content in utf8"
                        file_content_encoded = file_content.encode('utf8')
                    else:
                        if DEBUG: print "[DBG]: Not encoding file content"
                        file_content_encoded = file_content
                    file_content_recovered = ExperimentUtil.deserialize(
                        file_content_encoded)
                    os.write(fd, file_content_recovered)
                    if DEBUG:
                        df.write(file_content_recovered)
                finally:
                    os.close(fd)
                self._programmer.program(file_name)
            finally:
                os.remove(file_name)
                # print file_name
                # import sys
                # sys.stdout.flush()
        except Exception as e:

            if DEBUG:
                tb = traceback.format_exc()
                print "FULL EXCEPTION IS: {0}".format(tb)

            # TODO: test me
            log.log(
                UdXilinxExperiment, log.level.Info,
                "Exception joining sending program to device: %s" % e.args[0])
            log.log_exc(UdXilinxExperiment, log.level.Debug)
            raise ExperimentErrors.SendingFileFailureError(
                "Error sending file to device: %s" % e)

        self._clear()
Exemple #11
0
    def _program_file(self, file_content):
        try:
            fd, file_name = tempfile.mkstemp(prefix='ud_xilinx_experiment_program',
                                             suffix='.' + self._programmer.get_suffix())  # Originally the Programmer wasn't the one to contain the suffix info.

            if DEBUG:
                print "[DBG]: 2"
                df2 = open("/tmp/orig_content", "w")
                df2.write("---begin---\n")
                df2.write(file_content)
                df2.close()

                # For debugging purposes write the file to tmp
                df = open("/tmp/toprogram_dbg", "w")
            try:
                try:
                    # TODO: encode? utf8?
                    if isinstance(file_content, unicode):
                        if DEBUG: print "[DBG]: Encoding file content in utf8"
                        file_content_encoded = file_content.encode('utf8')
                    else:
                        if DEBUG: print "[DBG]: Not encoding file content"
                        file_content_encoded = file_content
                    file_content_recovered = ExperimentUtil.deserialize(file_content_encoded)
                    os.write(fd, file_content_recovered)
                    if DEBUG:
                        df.write(file_content_recovered)
                finally:
                    os.close(fd)
                self._programmer.program(file_name)
            finally:
                os.remove(file_name)
                # print file_name
                # import sys
                # sys.stdout.flush()
        except Exception as e:

            if DEBUG:
                tb = traceback.format_exc()
                print "FULL EXCEPTION IS: {0}".format(tb)

            # TODO: test me
            log.log(UdXilinxExperiment, log.level.Info,
                    "Exception joining sending program to device: %s" % e.args[0])
            log.log_exc(UdXilinxExperiment, log.level.Debug)
            raise ExperimentErrors.SendingFileFailureError("Error sending file to device: %s" % e)

        self._clear()
Exemple #12
0
 def _program_file(self, file_content):
     try:
         fd, file_name = tempfile.mkstemp(prefix='pic18_experiment_program', suffix='.hex')
         try:
             try:
                 #TODO: encode? utf8?
                 if isinstance(file_content, unicode):
                     file_content_encoded = file_content.encode('utf8')
                 else:
                     file_content_encoded = file_content
                 file_content_recovered = ExperimentUtil.deserialize(file_content_encoded)
                 os.write(fd, file_content_recovered)
             finally:
                 os.close(fd)
             print "File ready in %s" % file_name
             self._programmer.program(file_name)
             print "File sent with programmer: ", self._programmer
         finally:
             os.remove(file_name)
     except Exception as e:
         print "Error sending file"
         import traceback
         traceback.print_exc()
         #TODO: test me
         log.log(
             UdPic18Experiment,
             log.level.Info,
             "Exception joining sending program to device: %s" % e.args[0]
         )
         log.log_exc(
             UdPic18Experiment,
             log.level.Debug
         )
         raise ExperimentExceptions.SendingFileFailureException(
                 "Error sending file to device: %s" % e
             )
Exemple #13
0
 def do_before_send_file(self, session, file):
     session['log'] += "before_send_file "
     file_content = ExperimentUtil.deserialize(file.commandstring)
     return Command(ExperimentUtil.serialize("AAA%s" % file_content))
 def do_before_send_file(self, session, file):
     session['log'] += "before_send_file "
     file_content = ExperimentUtil.deserialize(file.commandstring)
     return Command(ExperimentUtil.serialize("AAA%s" % file_content))