コード例 #1
0
ファイル: conman.py プロジェクト: kollivier/brightwriter
 def NewPub(self, name, lang, directory=''):
     self.directory = directory
     mycontent = self.content.AddItem(utils.getUUID(), self.language)
     mycontent.metadata.name = name
     mynode = ConNode(utils.getUUID(), mycontent, None)
     mynode.dir = directory
     self.CurrentNode = mynode
     self.name = name 
     self.nodes.append(mynode)
     return mynode
コード例 #2
0
ファイル: conman.py プロジェクト: kollivier/brightwriter
 def AddChild(self, id, content, dir):
     if id == "":
         id = utils.getUUID()
     mynode = ConNode(id, content, self)
     mynode.dir = dir
     self.children.append(mynode)
     return mynode
コード例 #3
0
ファイル: conman.py プロジェクト: kollivier/brightwriter
 def AddItem(self, id, lang):
     myitem = None
     if id == "":
         id = utils.getUUID()
     myitem = Content(id, lang)
     self.content.append(myitem)
     return myitem
コード例 #4
0
 def uni_man_client_protocol_speech_transcribe(self,
                                               event=None,
                                               call_uuid=None,
                                               udp_port=None,
                                               speech_data=None):
     """
     It is send command unicast manager to ivr program.
     :param event: jsonnode message.
     :param call_uuid: call uuid.
     :param udp_port: udp port.
     :param speech_data: speech transcribed message.
     :return: defer callback.
     """
     log.debug(' Send Command "speech_transcribe" : %s' % event)
     msg = jsonnode.NodeMessage()
     msg["timestamp"] = time.time()
     msg["msg"] = "Reply >> speech transcribe"
     msg["Reply-Text"] = "+OK"
     msg["msg-uuid"] = utils.getUUID()
     msg['call_uuid'] = event['call_uuid']
     msg['udp_port'] = event['udp_port']
     msg['command'] = 'speech_transcribe'
     msg['speech_data'] = event['speech_data']
     # msg = {}
     df = self.sendCommand(msg)
     df.addCallback(self.command_success_respone)
     df.addErrback(self.command_error_response)
     self.transport.loseConnection()
     return df
コード例 #5
0
 def sendMessage(self, msg):
     """Write NodeMessage object on wire"""
     if not 'msg-uuid' in msg:
         msg['msg-uuid'] = utils.getUUID()
     m = msg.as_string()
     if __debug__:
         log.debug("Sending msg out :%r" % m)
     if self.connected:
         # self.transport.write(m, self.addr)
         self.transport.write(m + self.delimiter, self.addr)
コード例 #6
0
 def sendMessage(self, msg):
     """Write NodeMessage object on wire"""
     if not 'msg-uuid' in msg:
         msg['msg-uuid'] = utils.getUUID()
     m = msg.as_string()
     if __debug__:
         log.debug("Sending msg out :%r" % m)
     if self.connected:
         # old NodeMessage class returned string with delimiter included which is not good
         # self.transport.write(m)
         self.sendLine(m)
コード例 #7
0
ファイル: ptero.py プロジェクト: Helioss-Minecraft/Fish-Bot
    async def resetspawn(self, ctx: commands.Context, node: str, server: str,
                         username: str):
        await ctx.send("Resetting player " + username + " to spawn...")
        if node == "london":
            serverid = utils.londonids[server]
        elif node == "canada":
            serverid = utils.canadaids[server]
        elif node == "germany":
            serverid = utils.germanyids[server]
        uuid = utils.getUUID(username)
        if uuid:
            if not os.path.exists(uuid + ".dat"):
                url = serverid + "/world/playerdata/" + uuid + ".dat"
                print(("Downloading " + url + "..."))
                utils.download(url, uuid + ".dat", node)
            dir_path = os.getcwd()
            nbtfile = nbtlib.load(dir_path + "/" + uuid + ".dat")

            url = serverid + "/world/level.dat"

            print(("Downloading " + url + "..."))
            utils.download(url, "level.dat", node)
            worldfile = nbtlib.load(dir_path + "/" + "level.dat")
            xCoord = worldfile.root["Data"]["SpawnX"]
            yCoord = worldfile.root["Data"]["SpawnY"]
            zCoord = worldfile.root["Data"]["SpawnZ"]

            print(
                ("Resetting " + username + "\'s coordinates to " +
                 str(xCoord) + "," + str(yCoord) + "," + str(zCoord) + "..."))
            await ctx.send("Original coords: " + str(nbtfile.root["Pos"][0]) +
                           ", " + str(nbtfile.root["Pos"][1]) + ", " +
                           str(nbtfile.root["Pos"][2]) + " in dim " +
                           str(nbtfile.root["Dimension"]))
            nbtfile.root["Pos"][0] = Double(xCoord)
            nbtfile.root["Pos"][1] = Double(yCoord)
            nbtfile.root["Pos"][2] = Double(zCoord)
            nbtfile.root["Dimension"] = Int(0)
            nbtfile.save()
            await ctx.send("New coords: " + str(nbtfile.root["Pos"][0]) +
                           ", " + str(nbtfile.root["Pos"][1]) + ", " +
                           str(nbtfile.root["Pos"][2]) + " in dim " +
                           str(nbtfile.root["Dimension"]))
            print("Uploading to server...")
            utils.upload(dir_path + "/" + uuid + ".dat",
                         serverid + "/world/playerdata/" + uuid + ".dat", node)
            print("Uploaded!")
            os.unlink(dir_path + "/" + uuid + ".dat")
            os.unlink(dir_path + "/" + "level.dat")
            await ctx.send("Done!")
コード例 #8
0
 def get_free_port(self, call_uuid=None, udp_port=None):
     # Something like this
     msg = jsonnode.NodeMessage()
     msg['msg'] = None
     msg["timestamp"] = time.time()
     msg["msg-uuid"] = utils.getUUID()
     msg['command'] = 'get_free_port'
     msg['call_uuid'] = call_uuid
     msg['udp_port'] = udp_port
     # msg = {}
     df = self.sendCommand(msg)
     df.addCallback(self.command_success_respone)
     df.addErrback(self.command_error_response)
     return df
コード例 #9
0
 def sendCommand(self, msg):
     """Send a command request to other side of the connection"""
     if not self.authed:
         if __debug__:
             log.debug("Not authenticated yet dropping sendCommand")
         return
     df = defer.Deferred()
     uuid = utils.getUUID()
     self.pendingJobs[uuid] = df
     del msg['Content-Type']
     msg['Content-Type'] = 'command/request'
     del msg['msg-uuid']
     msg['msg-uuid'] = uuid
     self.sendMessage(msg)
     return df
コード例 #10
0
ファイル: conman.py プロジェクト: kollivier/brightwriter
 def __init__(self, id, content, parent):
     if id == "":
         self.id = utils.getUUID()
     else:
         self.id = id
     #contentid variable makes it possible to have several nodes pointing to the same resource - NYI
     if content == None:
         self.content = Content(id, "")
     else:
         self.content = content
     self.parent = parent
     self.pub = None
     self.children = []
     if self.parent:
         self.dir = self.parent.dir
     else:
         self.dir = ""
コード例 #11
0
ファイル: core.py プロジェクト: juggernate/maya-pymetanode
def encodeMetaDataValue(value):
    """
    Encode and return a meta data value. Handles special
    data types like Maya nodes.

    Args:
        value: Any python value to be encoded
    """
    if isinstance(value, dict):
        result = {}
        for k, v in value.iteritems():
            result[k] = encodeMetaDataValue(v)
        return result
    elif isinstance(value, (list, tuple)):
        return value.__class__([encodeMetaDataValue(v) for v in value])
    elif isinstance(value, pm.nt.DependNode):
        return utils.getUUID(value)
    else:
        return value
コード例 #12
0
 def curtum_speech_transcribe(self,
                              call_uuid=None,
                              udp_port=None,
                              speech_data=None):
     log.debug(' Receive Command "uni_man_speech_transcribe"')
     msg = jsonnode.NodeMessage()
     msg['msg'] = None
     msg["timestamp"] = time.time()
     msg["msg-uuid"] = utils.getUUID()
     msg['command'] = 'uni_man_speech_transcribe'
     msg['call_uuid'] = call_uuid
     msg['speech_data'] = speech_data
     msg['udp_port'] = udp_port
     # msg = {}
     df = self.sendCommand(msg)
     df.addCallback(self.command_success_respone)
     df.addErrback(self.command_error_response)
     self.transport.loseConnection()
     return df
コード例 #13
0
 def check_port(self, call_uuid=None, udp_port=None):
     """
     It send command check_port to unicast reader program from unicast manager.
     :param call_uuid: call uuid.
     :param udp_port: port number.
     :return: defer callback.
     """
     log.debug(' Send Command "check_port" for call uuid : %s' % call_uuid)
     msg = jsonnode.NodeMessage()
     msg['msg'] = None
     msg["timestamp"] = time.time()
     msg["msg-uuid"] = utils.getUUID()
     msg['command'] = 'check_port'
     msg['call_uuid'] = call_uuid
     msg['udp_port'] = udp_port
     # msg = {}
     df = self.sendCommand(msg)
     df.addCallback(self.command_success_respone)
     df.addErrback(self.command_error_response)
     return df
コード例 #14
0
ファイル: ptero.py プロジェクト: Helioss-Minecraft/Fish-Bot
 async def resetcoords(self, ctx: commands.Context, node: str, server: str,
                       player: str, x: int, y: int, z: int, dim: int):
     """Reset a player's coords"""
     await ctx.send("Resetting player " + player + " to coords: " + str(x) +
                    ", " + str(y) + ", " + str(z) + " " + "in dimension " +
                    str(dim) + "...")
     if node == "london":
         serverid = utils.londonids[server]
     elif node == "canada":
         serverid = utils.canadaids[server]
     elif node == "germany":
         serverid = utils.germanyids[server]
     uuid = utils.getUUID(player)
     if uuid:
         url = serverid + "/world/playerdata/" + uuid + ".dat"
         print("Downloading " + url + "...")
         utils.download(url, uuid + ".dat", node)
         dir_path = cwd = os.getcwd()
         nbtfile = nbtlib.load(dir_path + "/" + uuid + ".dat")
         print("Resetting " + player + "\'s coordinates to " + str(x) +
               "," + str(y) + "," + str(z) + "...")
         await ctx.send("Original coords: " + str(nbtfile.root["Pos"][0]) +
                        ", " + str(nbtfile.root["Pos"][1]) + ", " +
                        str(nbtfile.root["Pos"][2]) + " in dim " +
                        str(nbtfile.root["Dimension"]))
         nbtfile.root["Pos"][0] = x
         nbtfile.root["Pos"][1] = y
         nbtfile.root["Pos"][2] = z
         nbtfile.root["Dimension"] = Int(dim)
         nbtfile.save()
         await ctx.send("New coords: " + str(nbtfile.root["Pos"][0]) +
                        ", " + str(nbtfile.root["Pos"][1]) + ", " +
                        str(nbtfile.root["Pos"][2]) + " in dim " +
                        str(nbtfile.root["Dimension"]))
         print("Uploading to server...")
         utils.upload(dir_path + "/" + uuid + ".dat",
                      serverid + "/world/playerdata/" + uuid + ".dat", node)
         print("Uploaded!")
         os.unlink(dir_path + "/" + uuid + ".dat")
     await ctx.send("Done!")
コード例 #15
0
parser.add_argument("node", nargs=1, type=checkNode)
parser.add_argument("server", nargs=1, type=checkServer)
parser.add_argument("player", nargs=1, type=str)
parser.add_argument("xCoord", nargs=1, type=float)
parser.add_argument("yCoord", nargs=1, type=float)
parser.add_argument("zCoord", nargs=1, type=float)
parser.add_argument("dim", nargs=1, type=int)
args = parser.parse_args()

if args.node[0] == "london":
    serverid = utils.londonids[args.server[0]]
elif args.node[0] == "canada":
    serverid = utils.canadaids[args.server[0]]
elif args.node[0] == "germany":
    serverid = utils.germanyids[args.server[0]]
uuid = utils.getUUID(args.player[0])
if uuid:
    url = serverid + "/world/playerdata/" + uuid + ".dat"
    print("Downloading " + url + "...")
    utils.download(url, uuid + ".dat", args.node[0])
    dir_path = cwd = os.getcwd()
    nbtfile = nbtlib.load(dir_path + "/" + uuid + ".dat")
    print("Resetting " + args.player[0] + "\'s coordinates to " +
          str(args.xCoord[0]) + "," + str(args.yCoord[0]) + "," +
          str(args.zCoord[0]) + "...")
    nbtfile.root["Pos"][0] = args.xCoord[0]
    nbtfile.root["Pos"][1] = args.yCoord[0]
    nbtfile.root["Pos"][2] = args.zCoord[0]
    nbtfile.root["Dimension"] = Int(args.dim[0])
    nbtfile.save()
    print("Uploading to server...")
コード例 #16
0
ファイル: conman.py プロジェクト: kollivier/brightwriter
    def LoadFromXML(self, filename):
        self.filename = filename
        self.directory = os.path.split(filename)[0]
        if os.path.exists(os.path.join(self.directory, "settings.xml")):
            self.settings.LoadFromXML(os.path.join(self.directory, "settings.xml"))
        self.content = ContentList()
        self.updatedids = {}
        self.nodes = []
        try: 
            myfile = utils.openFile(filename)
            data = myfile.read()
            myfile.close()
            
            if data.find("\x92") != -1 or data.find("\x93") != -1 or data.find("\x94") != -1:
                data = data.replace("encoding=\"iso8859-1\"", "encoding=\"cp1252\"")
                myfile = utils.openFile(filename, "w")
                myfile.write(data)
                myfile.close()
                print "Ugh, smart quotes..."
                
            if USE_MINIDOM:
                doc = minidom.parse(utils.openFile(filename))
            else:
                doc = FromXmlFile(filename)
        except:
            return "The EClass project file cannot be loaded. The error message is: " + `sys.exc_value.args`

        manifest = doc.getElementsByTagName("manifest")[0]
        if manifest.attributes:
            for i in range(0, len(manifest.attributes)):
                attr = manifest.attributes.item(i)
                if attr.name == "identifier" and string.find(attr.value, self.namespace) != -1:
                    self.id = string.replace(attr.value, self.namespace, "")
                    self.id = string.replace(self.id, "-", "")

            if self.id == "":
                self.id = utils.getUUID()
                    
        metadata = doc.getElementsByTagName("metadata")[0]
        if metadata.childNodes:
            if metadata.getElementsByTagName("PublicationID"):
                if metadata.getElementsByTagName("PublicationID")[0].childNodes:
                    self.pubid = metadata.getElementsByTagName("PublicationID")[0].childNodes[0].nodeValue
                    #print self.pubid
            else:
                self.pubid = ""
            imsmetadata = doc.getElementsByTagName("imsmd:General")
            self._GetMetadata(metadata)
        resources = doc.getElementsByTagName("resource")
        self._GetResources(resources)
        toc = doc.getElementsByTagName("tableofcontents")
        if not toc:
            toc = doc.getElementsByTagName("organization")
            if toc:
                toc = toc[0]
        else:
            toc = toc[0]
        if toc.attributes:
            for i in range(0, len(toc.attributes)):
                attr = toc.attributes.item(i)
                if attr.name == "identifier" and string.find(attr.value, self.namespace) != -1:
                    self.orgid = string.replace(attr.value, self.namespace, "")
                    self.orgid = string.replace(self.orgid, "-", "")

            if self.orgid == "":
                self.orgid = utils.getUUID()
        items = doc.getElementsByTagName("item")[0]
        self._GetNodes(items, None)
        self.CurrentNode = self.nodes[0]
        return ""
コード例 #17
0
ファイル: conman.py プロジェクト: kollivier/brightwriter
def CopyContent(oldcontent):
    newcontent = Content(utils.getUUID(), "en")
    import copy
    newcontent.metadata = copy.copy(oldcontent.metadata)
    return newcontent
コード例 #18
0
ファイル: conman.py プロジェクト: kollivier/brightwriter
    def _GetNodes(self, root, parent):
        id = ""
        contentid = ""
        name = ""
        keywords = ""
        description = ""
        template = ""
        public = "true"
        mycontent = None
        if root.attributes:
            for i in range(0, len(root.attributes)):
                attr = root.attributes.item(i)
                if attr.name == "identifier":
                    id = XMLAttrToText(attr.value)
                    id = string.replace(id, self.namespace, "")
                    id = string.replace(id, "-", "")
                    if len(id) < 32: #Not a UUID, used previous ID system
                        id = utils.getUUID()
                elif attr.name == "identifierref":
                    contentid = XMLAttrToText(attr.value)
                    contentid = string.replace(contentid, self.namespace, "")
                    contentid = string.replace(contentid, "-", "")
                elif attr.name == "title":
                    name = XMLAttrToText(attr.value)
                elif attr.name == "description":
                    description = XMLAttrToText(attr.value)
                elif attr.name == "keywords":
                    keywords = XMLAttrToText(attr.value)
                elif attr.name == "template":
                    template = XMLAttrToText(attr.value)
                elif attr.name == "public":
                    public = XMLAttrToText(attr.value) 

            #later versions of IMS make title an tag rather than an 
            #attribute, so override title here. 
            titleNode = root.getElementsByTagName("title")
            if titleNode:
                if titleNode[0].childNodes:
                    name = titleNode[0].childNodes[0].nodeValue

            #Content should already be loaded, so try to get the item first             
            if self.updatedids.has_key(contentid):
                mycontent = self.content.GetItem(self.updatedids[contentid], self.language)
                #mycontent.id = self.updatedids[contentid]
            else:
                mycontent = self.content.GetItem(contentid, self.language) 

            if mycontent == None:
                mycontent = self.content.AddItem(contentid, self.language)

            if mycontent.metadata.name == "": #we're an old course
                mycontent.metadata.name = name
                mycontent.metadata.keywords = keywords
                mycontent.metadata.description = description
            mycontent.template = template
            mycontent.public = public
            
            #Test to make sure the first element isn't added as a child
            if parent:
                mynode = parent.AddChild(id, mycontent, self.directory)
                if not string.find(mycontent.filename, "imsmanifest.xml") == -1:
                    mypub = ConMan()
                    mypub.LoadFromXML(mycontent.filename)
                    mynode.pub = mypub
                self.CurrentNode = mynode 
            else:                       
                mynode = ConNode(id, mycontent, None)
                mynode.dir = self.directory
                self.nodes = []
                self.nodes.append(mynode)
                self.CurrentNode = mynode

            for node in root.childNodes:
                self._GetNodes(node, mynode)