8000 REST Tango /open don't return Files list · Issue #137 · autolab/Tango · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
REST Tango /open don't return Files list #137
Open
@ghost

Description

Expected Behavior

According to documentation, when I am getting into /open I suppose to see:
{
"statusMsg": ,
"statusId": ,
"files": { : , : ... },
}

Actual Behavior

When getting into /open request, it returns only StatusMsg and StatusId, Files are always empty even if there is any file in courselab directory:

{
"statusMsg": "Found directory",
"statusId": "0"
"files": { },
}

Steps to Reproduce the Behavior

Just add few lines of code in Open method and add CoumputeMD5 method:
DIR: tango/restful-tango/tangoREST.py

    def computeMD5(self, directory):
        """ computeMD5 - Computes the MD5 hash of given files in the
        given directory
        """
        result = {}
        for elem in os.listdir(directory):
            try:
                body = open("%s/%s" % (directory, elem)).read()
                md5hash = hashlib.md5(body).hexdigest()
                result[elem] = md5hash
            except IOError:
                continue
        return result

      def open(self, key, courselab):
        """ open - Return a dict of md5 hashes for each input file in the
        key-courselab directory and make one if the directory doesn't exist
        """
        self.log.debug("Received open request(%s, %s)" % (key, courselab))
        if self.validateKey(key):
            labPath = self.getDirPath(key, courselab)
            try:
                if os.path.exists(labPath):
                    self.log.info(
                        "Found directory for (%s, %s)" % (key, courselab))
                    statusObj = self.status.found_dir
                    statusObj['files'] = self.computeMD5(labPath)
                    return statusObj
                else:
                    outputPath = self.getOutPath(key, courselab)
                    os.makedirs(outputPath)
                    self.log.info(
                        "Created directory for (%s, %s)" % (key, courselab))
                    statusObj = self.status.made_dir
                    statusObj["files"] = {}
                    return statusObj
            except Exception as e:
                self.log.error("open request failed: %s" % str(e))
                return self.status.create(-1, str(e))
        else:
            self.log.info("Key not recognized: %s" % key)
            return self.status.wrong_key

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0