Пример #1
0
    def decompressNewProject(self, rq):
        print "decompress"
        f = rq['data']
        name = f['name']
        contents = f['data']
        storageUnit = rq['storageUnit'] +"/"
        #print contents

        # get configuration from file
        confFile = weioConfig.getConfiguration()
        pathCurrentProject = "www/" + storageUnit

        projectName = name.split(".tar")[0]
        data = {}

        if (weioFiles.checkIfDirectoryExists(pathCurrentProject+projectName) is False) :
            #decode from base64, file is binary
            bb = contents
            bb = bb.split(",")[1] # split header, for example: "data:image/jpeg;base64,"
            weioFiles.saveRawContentToFile(pathCurrentProject+name, bb.decode("base64"))
            #print "save to ", pathCurrentProject+name
            weioFiles.createDirectory(pathCurrentProject+projectName)
            #print "mkdir ", pathCurrentProject+"userProjects/"+projectName
            weioFiles.unTarFile(pathCurrentProject+name, pathCurrentProject+projectName)
            #print "untar ", pathCurrentProject+"userProjects/"+projectName

            data['request'] = "changeProject"
            data['data'] = storageUnit+projectName

            self.changeProject(data)
        else :
            data['requested'] = 'status'
            data['status'] = "Error this projet already exists"
            self.broadcast(clients, json.dumps(data))
Пример #2
0
    def createTarForProject(self, rq):
        # TEST IF NAME IS OK FIRST
        # get configuration from file
        config = weioConfig.getConfiguration()
        data = {}
        data['requested'] = "status"
        data['status'] = "Making archive..."
        self.broadcast(clients, json.dumps(data))

        data['requested'] = rq['request']

        splitted = config["last_opened_project"].split("/")
        print "CHOOSE NAME", splitted
        lp = splitted[-1]

        if (weioFiles.checkIfDirectoryExists(config["last_opened_project"])):
            weioFiles.createTarfile(
                config["last_opened_project"] + "/" + lp + ".tar",
                config["last_opened_project"] + "/")

            data['status'] = "Project archived"
            print "project archived"
        else:
            data['status'] = "Error archiving project"

        self.broadcast(clients, json.dumps(data))
Пример #3
0
    def createTarForProject(self, rq):
        # TEST IF NAME IS OK FIRST
        # get configuration from file
        config = weioConfig.getConfiguration()
        data = {}
        data['requested'] = "status"
        data['status'] = "Making archive..."
        self.broadcast(clients, json.dumps(data))

        data['requested'] = rq['request']

        splitted = config["last_opened_project"].split("/")
        print "CHOOSE NAME", splitted
        lp = splitted[-1]


        if (weioFiles.checkIfDirectoryExists(config["last_opened_project"])):
            weioFiles.createTarfile(config["last_opened_project"] + "/" + lp + ".tar",
                    config["last_opened_project"]+"/")

            data['status'] = "Project archived"
            print "project archived"
        else :
            data['status'] = "Error archiving project"

        self.broadcast(clients, json.dumps(data))
Пример #4
0
    def decompressNewProject(self, rq):
        print "decompress"
        f = rq['data']
        name = f['name']
        contents = f['data']
        storageUnit = rq['storageUnit'] +"/"
        #print contents

        # get configuration from file
        confFile = weioConfig.getConfiguration()
        pathCurrentProject = "www/" + storageUnit

        projectName = name.split(".tar")[0]
        data = {}

        if (weioFiles.checkIfDirectoryExists(pathCurrentProject+projectName) is False) :
            #decode from base64, file is binary
            bb = contents
            bb = bb.split(",")[1] # split header, for example: "data:image/jpeg;base64,"
            weioFiles.saveRawContentToFile(pathCurrentProject+name, bb.decode("base64"))
            #print "save to ", pathCurrentProject+name
            weioFiles.createDirectory(pathCurrentProject+projectName)
            #print "mkdir ", pathCurrentProject+"userProjects/"+projectName
            weioFiles.unTarFile(pathCurrentProject+name, pathCurrentProject+projectName)
            #print "untar ", pathCurrentProject+"userProjects/"+projectName

            data['request'] = "changeProject"
            data['data'] = storageUnit+projectName

            self.changeProject(data)
        else :
            data['requested'] = 'status'
            data['status'] = "Error this projet already exists"
            self.broadcast(clients, json.dumps(data))
Пример #5
0
    def newProject(self, rq):
        config = weioConfig.getConfiguration()
        print "NEW PROJECT", rq
        data = {}
        data['requested'] = rq['request']
        path = ""
        storage = rq['storageUnit']

        path = "www/" + rq['storageUnit'] + "/" + rq['path']

        print "CREATE PROJECT", path
        if (len(path)>0):
            if (weioFiles.checkIfDirectoryExists(path)):
                print "ALREADY EXISTS"
                data['status'] = "Can't create project"
                data['error'] = "already exists"
                data['path'] = path
                self.broadcast(clients, json.dumps(data))
            else :
                weioFiles.createDirectory(path)
                # ADD HERE SOME DEFAULT FILES
                # adding __init__.py
                weioFiles.saveRawContentToFile(path + "/__init__.py", "")

                # make symlink to www/
                if (storage == "sd" or storage == "usbFlash"):
                    if (storage == "sd"):
                        if os.path.isdir(path):
                            if not (os.path.exists(path + "/www")):
                                print "COPYING TO ", path + "/www"
                                copytree(config["absolut_root_path"] + "/www/", path + "/www", ignore=ignore_patterns('sd', 'flash', 'examples', 'usbFlash'))
                                print "OK"
                    else:
                        if not (os.path.exists(path + "/www")):
                            print "COPYING TO ", path + "/www"
                            copytree(config["absolut_root_path"] + "/www/", path + "/www", ignore=ignore_patterns('sd', 'flash', 'examples', 'usbFlash'))
                            print "OK"
                else:
                    try:
                        os.remove(path + "/www")
                    except:
                        print "Symlink don't exist. Will create new one for this project"
                    os.symlink(config["absolut_root_path"] + "/www/", path + "/www")

                # copy all files from directory boilerplate to destination
                mypath = "www/libs/weio/boilerPlate/"
                onlyfiles = [ f for f in os.listdir(mypath) if isfile(join(mypath,f)) ]
                for f in onlyfiles:
                    copyfile(mypath+f, path +"/"+f)

                print "LASTOPENED new project", path
                config["last_opened_project"] = path
                weioConfig.saveConfiguration(config);

                data['status'] = "New project created"
                data['path'] = path
                self.broadcast(clients, json.dumps(data))
        else:
            print "BAD PATHNAME"
Пример #6
0
 def getTreeInHTML(self,rq):
     
     # get configuration from file
     config = weio_config.getConfiguration()
     
     data = {}
     data['requested'] = rq['request']
     up = config["user_projects_path"]
     lp = config["last_opened_project"]
     if (weioFiles.checkIfDirectoryExists(up+lp)):
         tree = weioFiles.getHtmlTree((up+lp))
         data['data'] = tree
     else:
         data['data'] = ""
     # Send connection information to the client
     self.send(json.dumps(data))
Пример #7
0
    def sendLastProjectName(self,rq):
        # get configuration from file
        config = weioConfig.getConfiguration()

        data = {}
        data['requested'] = rq['request']
        lp = os.path.basename( config["last_opened_project"].strip("/") )

        storage = config["last_opened_project"].split("/")[0]

        print "USER PRJ NAME", lp

        if (weioFiles.checkIfDirectoryExists(config["last_opened_project"])):
            print "PROJ NAME", config["last_opened_project"]
            data['data'] = config["last_opened_project"].split(storage+"/")[1]
        else :
            data['data'] = "Select project here"
        # Send connection information to the client
        self.broadcast(clients, json.dumps(data))
Пример #8
0
    def sendLastProjectName(self,rq):
        # get configuration from file
        config = weioConfig.getConfiguration()

        data = {}
        data['requested'] = rq['request']
        lp = os.path.basename( config["last_opened_project"].strip("/") )

        storage = config["last_opened_project"].split("/")[0]

        print "USER PRJ NAME", lp

        if (weioFiles.checkIfDirectoryExists(config["last_opened_project"])):
            print "PROJ NAME", config["last_opened_project"]
            data['data'] = config["last_opened_project"].split(storage+"/")[1]
        else :
            data['data'] = "Select project here"
        # Send connection information to the client
        self.broadcast(clients, json.dumps(data))
Пример #9
0
    def getFileTree(self,rq):
        # get configuration from file
        config = weioConfig.getConfiguration()

        data = {}
        data['requested'] = rq['request']
        lp = config["last_opened_project"]
        if (weioFiles.checkIfDirectoryExists(lp)):
            tree = weioFiles.getFileTree(lp)
            data['data'] = tree
            #data['projectRoot'] = lp.split("/")[0]
            print "PROJECT ROOT", lp
            path = lp.split("/")
            finalPath = ""
            for p in range(len(path)-1):
                finalPath =  finalPath + path[p] + "/"
            data['projectRoot'] = finalPath
            print "PROJECT ROOT", finalPath
        else:
            data['data'] = ""
            data['projectRoot'] = ""
        # Send connection information to the client
        self.broadcast(clients, json.dumps(data))
Пример #10
0
    def getFileTree(self, rq):
        # get configuration from file
        config = weioConfig.getConfiguration()

        data = {}
        data['requested'] = rq['request']
        lp = config["last_opened_project"]
        if (weioFiles.checkIfDirectoryExists(lp)):
            tree = weioFiles.getFileTree(lp)
            data['data'] = tree
            #data['projectRoot'] = lp.split("/")[0]
            print "PROJECT ROOT", lp
            path = lp.split("/")
            finalPath = ""
            for p in range(len(path) - 1):
                finalPath = finalPath + path[p] + "/"
            data['projectRoot'] = finalPath
            print "PROJECT ROOT", finalPath
        else:
            data['data'] = ""
            data['projectRoot'] = ""
        # Send connection information to the client
        self.broadcast(clients, json.dumps(data))
Пример #11
0
    def newProject(self, rq):
        config = weioConfig.getConfiguration()
        print "NEW PROJECT", rq
        data = {}
        data['requested'] = rq['request']
        path = ""
        storage = rq['storageUnit']

        path = "www/" + rq['storageUnit'] + "/" + rq['path']

        print "CREATE PROJECT", path
        if (len(path) > 0):
            if (weioFiles.checkIfDirectoryExists(path)):
                print "ALREADY EXISTS"
                data['status'] = "Can't create project"
                data['error'] = "already exists"
                data['path'] = path
                self.broadcast(clients, json.dumps(data))
            else:
                weioFiles.createDirectory(path)
                # ADD HERE SOME DEFAULT FILES
                # adding __init__.py
                weioFiles.saveRawContentToFile(path + "/__init__.py", "")

                # make symlink to www/
                if (storage == "sd" or storage == "usbFlash"):
                    if (storage == "sd"):
                        if os.path.isdir(path):
                            if not (os.path.exists(path + "/www")):
                                print "COPYING TO ", path + "/www"
                                copytree(config["absolut_root_path"] + "/www/",
                                         path + "/www",
                                         ignore=ignore_patterns(
                                             'sd', 'flash', 'examples',
                                             'usbFlash'))
                                print "OK"
                    else:
                        if not (os.path.exists(path + "/www")):
                            print "COPYING TO ", path + "/www"
                            copytree(config["absolut_root_path"] + "/www/",
                                     path + "/www",
                                     ignore=ignore_patterns(
                                         'sd', 'flash', 'examples',
                                         'usbFlash'))
                            print "OK"
                else:
                    try:
                        os.remove(path + "/www")
                    except:
                        print "Symlink don't exist. Will create new one for this project"
                    os.symlink(config["absolut_root_path"] + "/www/",
                               path + "/www")

                # copy all files from directory boilerplate to destination
                mypath = "www/libs/weio/boilerPlate/"
                onlyfiles = [
                    f for f in os.listdir(mypath) if isfile(join(mypath, f))
                ]
                for f in onlyfiles:
                    copyfile(mypath + f, path + "/" + f)

                print "LASTOPENED new project", path
                config["last_opened_project"] = path
                weioConfig.saveConfiguration(config)

                data['status'] = "New project created"
                data['path'] = path
                self.broadcast(clients, json.dumps(data))
        else:
            print "BAD PATHNAME"