Beispiel #1
0
    def createNewFile(self, rq):
        data = {}
        # this function is similar to saveFile

        # echo given request
        data['requested'] = rq['request']

        # don't echo given data to spare unnecessary communication, just return name
        f = rq['data']
        name = f['name']
        contents = f['data']

        # get configuration from file
        confFile = weioConfig.getConfiguration()
        print "WILL BE SAVED IN ", name

        if ((".html" in name) or (".py" in name) or (".json" in name) or
            (".css" in name) or (".txt" in name) or (".js" in name) or
            (".md" in name) or (".svg" in name) or (".xml" in name) or
            (".less" in name) or (".coffee" in name)):

            weioFiles.saveRawContentToFile(confFile["last_opened_project"] + "/" + name, contents)
        else :

            #decode from base64, file is binary
            bin = contents
            bin = bin.split(",")[1] # split header, for example: "data:image/jpeg;base64,"
            weioFiles.saveRawContentToFile(confFile["last_opened_project"] + "/" + name, bin.decode("base64"))

        #print (pathCurrentProject+pathname)

        data['status'] = name + " has been created"
        self.broadcast(clients, json.dumps(data))
Beispiel #2
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))
Beispiel #3
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))
Beispiel #4
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"
Beispiel #5
0
 def saveFile(self, rq):
     #print "DATA ", rq
     data = {}
     # echo given request
     data['requested'] = rq['request']
     
     f = rq['data']
     contents = f['data']
     path = f['path']
     name = rq['data']['name'] 
     
     #print "NAME " + rq['data']['name']
     weioFiles.saveRawContentToFile(path, contents)
                
     data['status'] = name + " saved!"
     self.send(json.dumps(data))
Beispiel #6
0
    def saveFile(self, rq):
        print "DATA ", rq
        data = {}
        # echo given request
        data['requested'] = rq['request']

        f = rq['data']
        contents = f['data']
        path = f['path']
        name = rq['data']['name']

        #print "NAME " + rq['data']['name']
        #utfContents = urllib2.unquote(urllib2.quote(contents)).decode("utf8")
        #utfContents = urllib2.unquote(s).decode('utf8')

        weioFiles.saveRawContentToFile(path, contents)

        data['status'] = name + " saved!"
        self.broadcast(clients, json.dumps(data))
Beispiel #7
0
    def saveFile(self, rq):
        print "DATA ", rq
        data = {}
        # echo given request
        data['requested'] = rq['request']

        f = rq['data']
        contents = f['data']
        path = f['path']
        name = rq['data']['name']

        #print "NAME " + rq['data']['name']
        #utfContents = urllib2.unquote(urllib2.quote(contents)).decode("utf8")
        #utfContents = urllib2.unquote(s).decode('utf8')

        weioFiles.saveRawContentToFile(path, contents.encode('utf-8'))

        data['status'] = name + " saved!"
        self.broadcast(clients, json.dumps(data))
Beispiel #8
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):
            weioFiles.createDirectory(path)
            # ADD HERE SOME DEFAULT FILES
            # adding __init__.py
            weioFiles.saveRawContentToFile(path + "/__init__.py", "")
            
            
            # make symlink to www/
            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"
Beispiel #9
0
    def createNewFile(self, rq):
        data = {}
        # this function is similar to saveFile

        # echo given request
        data['requested'] = rq['request']

        # don't echo given data to spare unnecessary communication, just return name
        f = rq['data']
        name = f['name']
        contents = f['data']

        # get configuration from file
        confFile = weioConfig.getConfiguration()
        print "WILL BE SAVED IN ", name

        if ((".html" in name) or (".py" in name) or (".json" in name)
                or (".css" in name) or (".txt" in name) or (".js" in name)
                or (".md" in name) or (".svg" in name) or (".xml" in name)
                or (".less" in name) or (".coffee" in name)
                or (".sh" in name)):

            weioFiles.saveRawContentToFile(
                confFile["last_opened_project"] + "/" + name,
                contents.encode('utf-8'))
        else:

            #decode from base64, file is binary
            bin = contents
            bin = bin.split(",")[
                1]  # split header, for example: "data:image/jpeg;base64,"
            weioFiles.saveRawContentToFile(
                confFile["last_opened_project"] + "/" + name,
                bin.decode("base64"))

        #print (pathCurrentProject+pathname)

        data['status'] = name + " has been created"
        self.broadcast(clients, json.dumps(data))
Beispiel #10
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"