def create(project, credentials): #pylint: disable=too-many-return-statements
        """Create project skeleton if it does not already exist (static method)"""

        if not settings.COMMAND:
            return flask.make_response("Projects disabled, no command configured",404)

        user, oauth_access_token = parsecredentials(credentials) #pylint: disable=unused-variable
        if not Project.validate(project):
            return withheaders(flask.make_response('Invalid project ID. Note that only alphanumerical characters are allowed.',403),headers={'allow_origin': settings.ALLOW_ORIGIN})
        printdebug("Checking if " + settings.ROOT + "projects/" + user + '/' + project + " exists")
        if not project:
            return withheaders(flask.make_response('No project name',403),headers={'allow_origin': settings.ALLOW_ORIGIN})
        if not os.path.isdir(settings.ROOT + "projects/" + user):
            printlog("Creating user directory '" + user + "'")
            os.makedirs(settings.ROOT + "projects/" + user)
            if not os.path.isdir(settings.ROOT + "projects/" + user): #verify:
                return withheaders(flask.make_response("Directory " + settings.ROOT + "projects/" + user + " could not be created succesfully",403),headers={'allow_origin': settings.ALLOW_ORIGIN})


        #checking user quota
        if settings.USERQUOTA > 0:
            _, totalsize = getprojects(user)
            if totalsize > settings.USERQUOTA:
                printlog("User " + user + " exceeded quota, refusing to create new project...")
                return withheaders(flask.make_response("Unable to create new project because you are exceeding your disk quota (max " + str(settings.USERQUOTA) + " MB, you now use " + str(totalsize) + " MB). Please delete some projects and try again.",403),headers={'allow_origin': settings.ALLOW_ORIGIN})

        if not os.path.isdir(settings.ROOT + "projects/" + user + '/' + project):
            printlog("Creating project '" + project + "'")
            os.makedirs(settings.ROOT + "projects/" + user + '/' + project)

        #project index will need to be regenerated, remove cache
        if os.path.exists(os.path.join(settings.ROOT + "projects/" + user,'.index')):
            os.unlink(os.path.join(settings.ROOT + "projects/" + user,'.index'))

        if not os.path.isdir(settings.ROOT + "projects/" + user + '/' + project + '/input/'):
            os.makedirs(settings.ROOT + "projects/" + user + '/' + project + "/input")
            if not os.path.isdir(settings.ROOT + "projects/" + user + '/' + project + '/input'):
                return withheaders(flask.make_response("Input directory " + settings.ROOT + "projects/" + user + '/' + project + "/input/  could not be created succesfully",403),headers={'allow_origin': settings.ALLOW_ORIGIN})
        if not os.path.isdir(settings.ROOT + "projects/" + user + '/' + project + '/output/'):
            os.makedirs(settings.ROOT + "projects/" + user + '/' + project + "/output")
            if not os.path.isdir(settings.ROOT + "projects/" + user + '/' + project + '/output'):
                return withheaders(flask.make_response("Output directory " + settings.ROOT + "projects/" + user + '/' + project + "/output/  could not be created succesfully",403),headers={'allow_origin': settings.ALLOW_ORIGIN})
        if not os.path.isdir(settings.ROOT + "projects/" + user + '/' + project + '/tmp/'):
            os.makedirs(settings.ROOT + "projects/" + user + '/' + project + "/tmp")
            if not os.path.isdir(settings.ROOT + "projects/" + user + '/' + project + '/tmp'):
                return withheaders(flask.make_response("tmp directory " + settings.ROOT + "projects/" + user + '/' + project + "/tmp/  could not be created succesfully",403),headers={'allow_origin': settings.ALLOW_ORIGIN})

        return None
def create ( project , credentials ) : if not settings . COMMAND : return flask . make_response ( "Projects disabled, no command configured" , 404 ) user , oauth_access_token = parsecredentials ( credentials ) if not Project . validate ( project ) : return withheaders ( flask . make_response ( 'Invalid project ID. Note that only alphanumerical characters are allowed.' , 403 ) , headers = { 'allow_origin' : settings . ALLOW_ORIGIN } ) printdebug ( "Checking if " + settings . ROOT + "projects/" + user + '/' + project + " exists" ) if not project : return withheaders ( flask . make_response ( 'No project name' , 403 ) , headers = { 'allow_origin' : settings . ALLOW_ORIGIN } ) if not os . path . isdir ( settings . ROOT + "projects/" + user ) : printlog ( "Creating user directory '" + user + "'" ) os . makedirs ( settings . ROOT + "projects/" + user ) if not os . path . isdir ( settings . ROOT + "projects/" + user ) : return withheaders ( flask . make_response ( "Directory " + settings . ROOT + "projects/" + user + " could not be created succesfully" , 403 ) , headers = { 'allow_origin' : settings . ALLOW_ORIGIN } ) if settings . USERQUOTA > 0 : _ , totalsize = getprojects ( user ) if totalsize > settings . USERQUOTA : printlog ( "User " + user + " exceeded quota, refusing to create new project..." ) return withheaders ( flask . make_response ( "Unable to create new project because you are exceeding your disk quota (max " + str ( settings . USERQUOTA ) + " MB, you now use " + str ( totalsize ) + " MB). Please delete some projects and try again." , 403 ) , headers = { 'allow_origin' : settings . ALLOW_ORIGIN } ) if not os . path . isdir ( settings . ROOT + "projects/" + user + '/' + project ) : printlog ( "Creating project '" + project + "'" ) os . makedirs ( settings . ROOT + "projects/" + user + '/' + project ) if os . path . exists ( os . path . join ( settings . ROOT + "projects/" + user , '.index' ) ) : os . unlink ( os . path . join ( settings . ROOT + "projects/" + user , '.index' ) ) if not os . path . isdir ( settings . ROOT + "projects/" + user + '/' + project + '/input/' ) : os . makedirs ( settings . ROOT + "projects/" + user + '/' + project + "/input" ) if not os . path . isdir ( settings . ROOT + "projects/" + user + '/' + project + '/input' ) : return withheaders ( flask . make_response ( "Input directory " + settings . ROOT + "projects/" + user + '/' + project + "/input/  could not be created succesfully" , 403 ) , headers = { 'allow_origin' : settings . ALLOW_ORIGIN } ) if not os . path . isdir ( settings . ROOT + "projects/" + user + '/' + project + '/output/' ) : os . makedirs ( settings . ROOT + "projects/" + user + '/' + project + "/output" ) if not os . path . isdir ( settings . ROOT + "projects/" + user + '/' + project + '/output' ) : return withheaders ( flask . make_response ( "Output directory " + settings . ROOT + "projects/" + user + '/' + project + "/output/  could not be created succesfully" , 403 ) , headers = { 'allow_origin' : settings . ALLOW_ORIGIN } ) if not os . path . isdir ( settings . ROOT + "projects/" + user + '/' + project + '/tmp/' ) : os . makedirs ( settings . ROOT + "projects/" + user + '/' + project + "/tmp" ) if not os . path . isdir ( settings . ROOT + "projects/" + user + '/' + project + '/tmp' ) : return withheaders ( flask . make_response ( "tmp directory " + settings . ROOT + "projects/" + user + '/' + project + "/tmp/  could not be created succesfully" , 403 ) , headers = { 'allow_origin' : settings . ALLOW_ORIGIN } ) return None
Create project skeleton if it does not already exist (static method)