Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST Tango /open don't return Files list #137

Open
ghost opened this issue Sep 8, 2017 · 1 comment
Open

REST Tango /open don't return Files list #137

ghost opened this issue Sep 8, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 8, 2017

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
@zyx-billy
Copy link
Member

Thanks for pointing this out! I believe the behavior was modified in #113. Instead of computing hashes of files in open, restful-tango just has the client upload all its files, and it simply ignores the ones it already have.
However, it seems this would result in more md5 computations server-side, as well as many unnecessary uploads. I'm going to make a fix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants