def sync_actions(self): # Register methods to the showtimebridge server wrapperclasses = LiveWrapper.__subclasses__() wrapperclasses.append(LiveWrapper) for cls in wrapperclasses: cls.register_methods() for action in LiveWrapper.incoming_methods().values(): Log.network("Adding %s to incoming callbacks" % action.methodName) self.add_incoming_action(action.methodName, action.callback) self.register_to_showtime(action.methodName, action.methodAccess, action.methodArgs) for action in LiveWrapper.outgoing_methods().values(): Log.network("Adding %s to outgoing callbacks" % action.methodName) self.register_to_showtime(action.methodName, action.methodAccess)
def event(self, event): if event.subject == NetworkPrefixes.HANDSHAKE: Log.network("TCP handshake received. Socket is %s" % self.socket) if self.connectionStatus == NetworkEndpoint.PIPE_CONNECTED: self.connectionStatus = NetworkEndpoint.HANDSHAKING for callback in self.clientHandshakeCallbacks: callback() return elif event.subject == NetworkPrefixes.HANDSHAKE_ACK: Log.network("TCP handshake ACK received") self.connectionStatus = NetworkEndpoint.HANDSHAKE_COMPLETE for callback in self.handshakeAckCallbacks: callback() return NetworkEndpoint.event(self, event)
def serve_forever(self): try: while self.active: sr, sw, se = select.select([self.sock], [], [self.sock]) if self.sock in se: try: self.sock.shutdown(2) self.sock.close() except socket.error, e: Log.logException() del self.sock self.active = False break if self.sock in sr: accdata = self.sock.accept() thread.start_new_thread(self.handle_request, accdata) except Exception, e: Log.logException()
def check_heartbeat(self): """Check if we've received a UDP heartbeat from a remote UDP endpoint""" if NetworkEndpoint.current_milli_time() > self.lastPeerHeartbeatTime + UDPEndpoint.HEARTBEAT_TIMEOUT: self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED Log.info("Heartbeat timeout") # Verify we're still talking to the same server if self.heartbeatID and self.lastReceivedHeartbeatID != self.heartbeatID: self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED Log.network( "Last heartbeat ID: %s. New heartbeat ID: %s" % (self.lastReceivedHeartbeatID, self.heartbeatID)) self.heartbeatID = self.lastReceivedHeartbeatID if self.connectionStatus == NetworkEndpoint.PIPE_DISCONNECTED: for callback in self.closingCallbacks: callback() return self.connectionStatus == NetworkEndpoint.PIPE_CONNECTED
def handle_request(self, sock, addr): Log(2, "Request received from %s:%d" % addr) try: server = HTTPServer.fromsocket(sock) while server.isactive(): request = server.readrequest() if request is None: server.close() break try: self.handler(server, request, addr) except Exception, e: Log.logException() if server.isactive(): server.writeresponse(500, hdr='Connection: close') server.close() break sock.shutdown(2) sock.close() print "CLOSE SERVER"
def event_received(self, event): self.requestLock = True # Lock the request loop Log.info("Received method " + event.subject[2:]) Log.info("Args are:" + str(event.msg)) try: self.incomingActions[event.subject](event.msg) except KeyError: Log.error("Nothing registered for incoming action " + event.subject)
def connect(self): self.create_socket() status = 0 retries = 5 while retries > 0: try: status = self.socket.connect(self.remoteAddr) except socket.error, e: if e[0] == NetworkErrors.EISCONN: Log.network("...TCP connected!") self.connectionStatus = NetworkEndpoint.PIPE_CONNECTED break elif e[0] == NetworkErrors.EAGAIN: Log.network("TCP connecting...") retries -= 1 elif e[0] == socket.timeout: Log.error("Timed out") self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED else: Log.error("Connection failed!") Log.error("Reason: " + str(e)) self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED break
def ensure_server_available(self): udpactive = self.udpEndpoint.check_heartbeat() if udpactive and self.tcpEndpoint.connectionStatus is NetworkEndpoint.PIPE_DISCONNECTED and not \ self.tcpEndpoint.hangup: Log.network("Heartbeat found! Reconnecting TCP to " + str(self.tcpEndpoint.remoteAddr)) if self.tcpEndpoint.connect(): self.inputSockets[self.tcpEndpoint.socket] = self.tcpEndpoint self.outputSockets[self.tcpEndpoint.socket] = self.tcpEndpoint Log.network("TCP connection established. Socket is %s" % self.tcpEndpoint.socket) else: Log.warn("TCP not up yet!") if not udpactive and self.tcpEndpoint.connectionStatus >= NetworkEndpoint.PIPE_CONNECTED: Log.network("Heartbeat lost. Closing TCP") self.tcpEndpoint.close() try: del self.inputSockets[self.tcpEndpoint.socket] del self.outputSockets[self.tcpEndpoint.socket] except KeyError: Log.error("TCP already removed from pollable sockets") if self.tcpEndpoint.connectionStatus == NetworkEndpoint.PIPE_CONNECTED: self.tcpEndpoint.send_handshake()
def send_message(self, message, args): args = args if args else {} retries = 5 success = False Log.info("Publishing message " + str(message)) while retries > 0: try: self.publish(message, args) success = True except Pyro.errors.ConnectionClosedError, e: Log.error(e) Log.error( "Rebinding to server. {0} retries left.".format(str(retries))) self.adapter.rebindURI() retries -= 1 if success: break
def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.cInstance = c_instance self._suppress_send_midi = True self.endpoint = None Log.set_logger(self.log_message) Log.set_log_level(Log.LOG_WARN) Log.set_log_network(True) Log.write("-----------------------") Log.write("ShowtimeBridge starting") Log.write("Python version " + sys.version) Log.info(sys.version) # Network endpoint self.endpoint = LiveNetworkEndpoint() self.endpoint.set_song_root_accessor(LiveUtils.getSong) LiveWrapper.set_endpoint(self.endpoint) # Midi clock to trigger incoming message check self.clock = LoopingEncoderElement(0, 119) self.refresh_state() self._suppress_send_midi = False
self.event.set() def handle_request(self, sock, addr): Log(2, "Request received from %s:%d" % addr) try: server = HTTPServer.fromsocket(sock) while server.isactive(): request = server.readrequest() if request is None: server.close() break try: self.handler(server, request, addr) except Exception, e: Log.logException() if server.isactive(): server.writeresponse(500, hdr='Connection: close') server.close() break sock.shutdown(2) sock.close() print "CLOSE SERVER" except Exception, e: Log.logException() ##class WebServer(WebServerStub, HTTPServer): ## ## def __init__(self, main, section, handler): ## WebServerStub.__init__(self, main, section) ## HTTPServer.__init__(self, (self.bindAddress, self.bindPort), handler)
def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.cInstance = c_instance self._suppress_send_midi = True Log.set_logger(self.log_message) Log.set_log_level(Log.LOG_WARN) Log.write("-----------------------") Log.write("ShowtimeBridge starting") Log.info(sys.version) self.initPyroServer() # Register methods to the showtimebridge server wrapperClasses = PyroWrapper.__subclasses__() wrapperClasses.append(PyroWrapper) for cls in wrapperClasses: cls.clear_instances() cls.register_methods() for action in cls.incoming_methods().values(): Log.info("Adding %s to incoming callbacks" % action.methodName) self.subscriber.add_incoming_action(action.methodName, cls, action.callback) self.publisher.register_to_showtime(action.methodName, action.methodAccess, action.methodArgs) for action in cls.outgoing_methods().values(): Log.info("Adding %s to outgoing methods" % action.methodName) self.publisher.register_to_showtime(action.methodName, action.methodAccess) # Midi clock to trigger incoming message check self.clock = PyroEncoderElement(0, 119) # Create the root wrapper PyroSong.add_instance(PyroSong(getSong())) self.refresh_state() self._suppress_send_midi = False
# # Make sure the Db will get closed correctly # try: ReturnCode = 0 CheckConflictOption(Opt) RunModule = None if Opt.PackFileToCreate: if Opt.PackageInformationDataFile: if not os.path.exists(Opt.PackageInformationDataFile): if not os.path.exists( os.path.join(WorkspaceDir, Opt.PackageInformationDataFile)): Logger.Error( "\nUPT", FILE_NOT_FOUND, ST.ERR_NO_TEMPLATE_FILE % Opt.PackageInformationDataFile) else: Opt.PackageInformationDataFile = os.path.join( WorkspaceDir, Opt.PackageInformationDataFile) else: Logger.Error("UPT", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_T_OPTION) if not Opt.PackFileToCreate.endswith('.dist'): Logger.Error("CreatePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToCreate) RunModule = MkPkg.Main
def InfUserExtensionParser(self, SectionString, InfSectionObject, FileName): UserExtensionContent = '' # # Parse section content # for Line in SectionString: LineContent = Line[0] # Comment the code to support user extension without any statement just the section header in [] # if LineContent.strip() == '': # continue UserExtensionContent += LineContent + DT.END_OF_LINE continue # # Current section UserId, IdString # IdContentList = [] LastItem = '' SectionLineNo = None for Item in self.LastSectionHeaderContent: UserId = Item[1] IdString = Item[2] Arch = Item[3] SectionLineNo = Item[4] if not IsValidArch(Arch): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Arch), File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo, ExtraData=None) if (UserId, IdString, Arch) not in IdContentList: # # To check the UserId and IdString valid or not. # if not IsValidUserId(UserId): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_UE_SECTION_USER_ID_ERROR % (Item[1]), File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo, ExtraData=None) if not IsValidIdString(IdString): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_UE_SECTION_ID_STRING_ERROR % (IdString), File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo, ExtraData=None) IdContentList.append((UserId, IdString, Arch)) else: # # Each UserExtensions section header must have a unique set # of UserId, IdString and Arch values. # This means that the same UserId can be used in more than one # section header, provided the IdString or Arch values are # different. The same IdString values can be used in more than # one section header if the UserId or Arch values are # different. The same UserId and the same IdString can be used # in a section header if the Arch values are different in each # of the section headers. # Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR % (IdString), File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo, ExtraData=None) LastItem = Item if not InfSectionObject.SetUserExtension(UserExtensionContent, IdContent=IdContentList, LineNo=SectionLineNo): Logger.Error\ ('InfParser', FORMAT_INVALID, \ ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[UserExtension]"), \ File=FileName, Line=LastItem[4])
def MacroParser(Line, FileName, SectionType, FileLocalMacros): MacroDefPattern = re.compile("^(DEFINE)[ \t]+") LineContent = Line[0] LineNo = Line[1] Match = MacroDefPattern.match(LineContent) if not Match: # # Not 'DEFINE/EDK_GLOBAL' statement, call decorated method # return None, None TokenList = GetSplitValueList(LineContent[Match.end(1):], \ DataType.TAB_EQUAL_SPLIT, 1) # # Syntax check # if not TokenList[0]: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_MACRONAME_NOGIVEN, ExtraData=LineContent, File=FileName, Line=LineNo) if len(TokenList) < 2: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_MACROVALUE_NOGIVEN, ExtraData=LineContent, File=FileName, Line=LineNo) Name, Value = TokenList # # DEFINE defined macros # if SectionType == DataType.MODEL_META_DATA_HEADER: FileLocalMacros[Name] = Value ReIsValidMacroName = re.compile(r"^[A-Z][A-Z0-9_]*$", re.DOTALL) if ReIsValidMacroName.match(Name) is None: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_MACRONAME_INVALID % (Name), ExtraData=LineContent, File=FileName, Line=LineNo) # Validate MACRO Value # # <MacroDefinition> ::= [<Comments>]{0,} # "DEFINE" <MACRO> "=" [{<PATH>} {<VALUE>}] <EOL> # <Value> ::= {<NumVal>} {<Boolean>} {<AsciiString>} {<GUID>} # {<CString>} {<UnicodeString>} {<CArray>} # # The definition of <NumVal>, <PATH>, <Boolean>, <GUID>, <CString>, # <UnicodeString>, <CArray> are subset of <AsciiString>. # ReIsValidMacroValue = re.compile(r"^[\x20-\x7e]*$", re.DOTALL) if ReIsValidMacroValue.match(Value) is None: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_MACROVALUE_INVALID % (Value), ExtraData=LineContent, File=FileName, Line=LineNo) return Name, Value
def SetGuid(self, GuidList, Arch=None): __SupportArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem is None): ArchItem = 'COMMON' __SupportArchList.append(ArchItem) for Item in GuidList: # # Get Comment content of this protocol # CommentsList = None if len(Item) == 3: CommentsList = Item[1] CurrentLineOfItem = Item[2] Item = Item[0] InfGuidItemObj = InfGuidItem() if len(Item) >= 1 and len(Item) <= 2: # # Only GuildName contained # if not IsValidCVariableName(Item[0]): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_INVALID_CNAME % (Item[0]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if (Item[0] != ''): InfGuidItemObj.SetName(Item[0]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_CNAME_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if len(Item) == 2: # # Contained CName and Feature Flag Express # <statements> ::= <CName> ["|" <FeatureFlagExpress>] # For GUID entry. # if Item[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Validate Feature Flag Express # FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip()) if not FeatureFlagRtv[0]: Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) InfGuidItemObj.SetFeatureFlagExp(Item[1]) if len(Item) != 1 and len(Item) != 2: # # Invalid format of GUID statement # Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) InfGuidItemObj = ParseGuidComment(CommentsList, InfGuidItemObj) InfGuidItemObj.SetSupArchList(__SupportArchList) # # Determine GUID name duplicate. Follow below rule: # # A GUID must not be duplicated within a [Guids] section. # A GUID may appear in multiple architectural [Guids] # sections. A GUID listed in an architectural [Guids] # section must not be listed in the common architectural # [Guids] section. # # NOTE: This check will not report error now. # for Item in self.Guids: if Item.GetName() == InfGuidItemObj.GetName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for GuidItemObjArch in __SupportArchList: if ItemArch == GuidItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper( ) == 'COMMON' or GuidItemObjArch.upper( ) == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if (InfGuidItemObj) in self.Guids: GuidList = self.Guids[InfGuidItemObj] GuidList.append(InfGuidItemObj) self.Guids[InfGuidItemObj] = GuidList else: GuidList = [] GuidList.append(InfGuidItemObj) self.Guids[InfGuidItemObj] = GuidList return True
def InfDepexParser(self, SectionString, InfSectionObject, FileName): DepexContent = [] DepexComment = [] ValueList = [] # # Parse section content # for Line in SectionString: LineContent = Line[0] LineNo = Line[1] # # Found comment # if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): DepexComment.append((LineContent, LineNo)) continue # # Replace with [Defines] section Macro # LineContent = InfExpandMacro(LineContent, (FileName, LineContent, Line[1]), self.FileLocalMacros, None, True) CommentCount = LineContent.find(DT.TAB_COMMENT_SPLIT) if CommentCount > -1: DepexComment.append((LineContent[CommentCount:], LineNo)) LineContent = LineContent[:CommentCount - 1] CommentCount = -1 DepexContent.append((LineContent, LineNo)) TokenList = GetSplitValueList(LineContent, DT.TAB_COMMENT_SPLIT) ValueList[0:len(TokenList)] = TokenList # # Current section archs # KeyList = [] LastItem = '' for Item in self.LastSectionHeaderContent: LastItem = Item if (Item[1], Item[2], Item[3]) not in KeyList: KeyList.append((Item[1], Item[2], Item[3])) NewCommentList = [] FormatCommentLn = -1 ReFormatComment = re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL) for CommentItem in DepexComment: CommentContent = CommentItem[0] if ReFormatComment.match(CommentContent) is not None: FormatCommentLn = CommentItem[1] + 1 continue if CommentItem[1] != FormatCommentLn: NewCommentList.append(CommentContent) else: FormatCommentLn = CommentItem[1] + 1 if not InfSectionObject.SetDepex( DepexContent, KeyList=KeyList, CommentList=NewCommentList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Depex]"), File=FileName, Line=LastItem[3])
Expected = '# Comment Line 1\n' self.assertEqual(Result, Expected) def testNormalCase2(self): CommentLines = '\n' Result = GenGenericCommentF(CommentLines) Expected = '#\n' self.assertEqual(Result, Expected) def testNormalCase3(self): CommentLines = '\n\n\n' Result = GenGenericCommentF(CommentLines) Expected = '#\n#\n#\n' self.assertEqual(Result, Expected) def testNormalCase4(self): CommentLines = 'coment line 1\n' Result = GenGenericCommentF(CommentLines) Expected = '# coment line 1\n' self.assertEqual(Result, Expected) def testNormalCase5(self): CommentLines = 'coment line 1\n coment line 2\n' Result = GenGenericCommentF(CommentLines) Expected = '# coment line 1\n# coment line 2\n' self.assertEqual(Result, Expected) if __name__ == '__main__': Logger.Initialize() unittest.main()
class HANDLER(Protocol): def __init__(self): self.CONNOBJ = None self.logger = Log("FeslClient", "\033[33;1m") self.logger_err = Log("FeslClient", "\033[33;1;41m") self.packetData = "" def connectionMade(self): self.ip, self.port = self.transport.client self.transport.setTcpNoDelay(True) self.logger.new_message( "[" + self.ip + ":" + str(self.port) + "] connected", 1) if self.CONNOBJ is None: self.CONNOBJ = Client() self.CONNOBJ.ipAddr = self.ip self.CONNOBJ.networkInt = self.transport Clients.append(self.CONNOBJ) def connectionLost(self, reason): self.logger.new_message( "[" + self.ip + ":" + str(self.port) + "] disconnected ", 1) if self.CONNOBJ is not None: self.CONNOBJ.IsUp = False Clients.remove(self.CONNOBJ) del self return def dataReceived(self, data): packet_type = data[:4] packet_checksum = data.split(data[12:])[0].split(packet_type)[1] packet_id = Packet(None).getPacketID(packet_checksum[:4]) packet_length = packet_checksum[4:] packet_data = data.split(packet_type + packet_checksum)[1] self.logger.new_message( "[" + self.ip + ":" + str(self.port) + "]<-- " + repr(data), 3) dataObj = Packet(packet_data).dataInterpreter() try: dataEncrypted = dataObj.get("PacketData", "data") self.packetData += dataEncrypted.replace("%3d", "=") if len(self.packetData) == int(dataObj.get("PacketData", "size")): dataObj = Packet(b64decode(self.packetData) + "\x00").dataInterpreter() self.packetData = "" isValidPacket = True self.CONNOBJ.plasmaPacketID += 1 else: isValidPacket = False except: if packet_id == 0x80000000: # Don't count it pass else: self.CONNOBJ.plasmaPacketID += 1 isValidPacket = True if Packet(data).verifyPacketLength(packet_length) and isValidPacket: TXN = dataObj.get("PacketData", "TXN") if packet_type == "fsys": fsys.ReceivePacket(self, dataObj, TXN) elif packet_type == "acct": acct.ReceivePacket(self, dataObj, TXN) elif packet_type == "rank": rank.ReceivePacket(self, dataObj, TXN) elif packet_type == "pnow": pnow.ReceiveRequest(self, dataObj, TXN) else: self.logger_err.new_message( "[" + self.ip + ":" + str(self.port) + ']<-- Got unknown message type (' + packet_type + ")", 2) elif not isValidPacket: pass else: self.CONNOBJ.plasmaPacketID += 1 self.logger_err.new_message( "Warning: Packet Length is diffirent than the received data length! (" + self.ip + ":" + str(self.port) + "). Ignoring that packet...", 2)
def __init__(self): self.CONNOBJ = None self.logger = Log("FeslClient", "\033[33;1m") self.logger_err = Log("FeslClient", "\033[33;1;41m") self.packetData = ""
def MainApp(): Log("Init", "\033[37m").new_message( "Initializing Battlefield Heroes Master Server Emulator...", 0) try: ssl_key = readFromConfig("SSL", "priv_key_path") ssl_cert = readFromConfig("SSL", "cert_file_path") fesl_client_port = int(readFromConfig("connection", "fesl_client_port")) fesl_server_port = int(readFromConfig("connection", "fesl_server_port")) theater_client_port = int( readFromConfig("connection", "theater_client_port")) theater_server_port = int( readFromConfig("connection", "theater_server_port")) http_server_port = int(readFromConfig("connection", "http_server_port")) https_server_port = int( readFromConfig("connection", "https_server_port")) except: Log("Init", "\033[37;41m").new_message( "Fatal Error!\n" "Failed to load certain values in the config.ini, be sure that EVERY " "option has a valid value and try it again.") sys.exit(2) try: Database(True) except Exception as DatabaseError: Log("Database", "\033[37;1;41m").new_message( "Fatal Error! Cannot initialize database!\n\n" "Additional error info:\n" + str(DatabaseError), 0) sys.exit(3) try: SSLContext = ssl.DefaultOpenSSLContextFactory(ssl_key, ssl_cert) Log("Init", "\033[37m").new_message("Successfully created SSL Context!", 2) except Exception as SSLErr: Log("Init", "\033[37;41m").new_message( "Fatal Error!\n" "Failed to create SSL Context!\n" "Make sure that you installed all required modules using\n" "`pip install -r requirements.txt`\n" "Also check if you specified correct SSL Cert and/or key in " "`config.ini`\n " "Additional error info:\n" + str(SSLErr), 0) sys.exit(4) try: factory = Factory() factory.protocol = FeslClient.HANDLER reactor.listenSSL(fesl_client_port, factory, SSLContext) Log("FeslClient", "\033[33;1m").new_message( "Created TCP Socket (now listening on port " + str(fesl_client_port) + ")", 1) except Exception as BindError: Log("Init", "\033[33;1;41m").new_message( "Fatal Error! Cannot bind socket to port: " + str(fesl_client_port) + "\n" "Make sure that this port aren't used by another program!\n\n" "Additional error info:\n" + str(BindError), 0) sys.exit(5) try: factory = Factory() factory.protocol = FeslServer.HANDLER reactor.listenSSL(fesl_server_port, factory, SSLContext) Log("FeslServer", "\033[32;1m").new_message( "Created TCP Socket (now listening on port " + str(fesl_server_port) + ")", 1) except Exception as BindError: Log("Init", "\033[33;1;41m").new_message( "Fatal Error! Cannot bind socket to port: " + str(fesl_server_port) + "\n" "Make sure that this port aren't used by another program!\n\n" "Additional error info:\n" + str(BindError), 0) sys.exit(5) try: factoryTCP = Factory() factoryTCP.protocol = TheaterClient.TCPHandler reactor.listenTCP(theater_client_port, factoryTCP) Log("TheaterClient", "\033[35;1m").new_message( "Created TCP Socket (now listening on port " + str(theater_client_port) + ")", 1) reactor.listenUDP(theater_client_port, TheaterClient.UDPHandler()) Log("TheaterClient", "\033[35;1m").new_message( "Created UDP Socket (now listening on port " + str(theater_client_port) + ")", 1) except Exception as BindError: Log("Init", "\033[35;1;41m").new_message( "Fatal Error! Cannot bind socket to port: " + str(theater_client_port) + "\n" "Make sure that this port aren't used by another program!\n\n" "Additional error info:\n" + str(BindError), 0) sys.exit(5) try: factoryTCP = Factory() factoryTCP.protocol = TheaterServer.TCPHandler reactor.listenTCP(theater_server_port, factoryTCP) Log("TheaterServer", "\033[36;1m").new_message( "Created TCP Socket (now listening on port " + str(theater_server_port) + ")", 1) reactor.listenUDP(theater_server_port, TheaterServer.UDPHandler()) Log("TheaterServer", "\033[36;1m").new_message( "Created UDP Socket (now listening on port " + str(theater_server_port) + ")", 1) except Exception as BindError: Log("Init", "\033[35;1;41m").new_message( "Fatal Error! Cannot bind socket to port: " + str(theater_server_port) + "\n" "Make sure that this port aren't used by another program!\n\n" "Additional error info:\n" + str(BindError), 0) sys.exit(5) try: site = Site(WebServer.Handler()) reactor.listenTCP(http_server_port, site) Log("WebServer", "\033[36m").new_message( "Created TCP Socket (now listening on port " + str(http_server_port) + ")", 1) except Exception as BindError: Log("Init", "\033[35;1;41m").new_message( "Fatal Error! Cannot bind socket to port: " + str(http_server_port) + "\n" "Make sure that this port aren't used by another program!\n\n" "Additional error info:\n" + str(BindError), 0) sys.exit(5) try: site = Site(SecureWebServer.Handler()) reactor.listenSSL(https_server_port, site, SSLContext) Log("WebServer", "\033[36m").new_message( "Created TCP Socket (now listening on port " + str(https_server_port) + ")", 1) except Exception as BindError: Log("Init", "\033[35;1;41m").new_message( "Fatal Error! Cannot bind socket to port: " + str(https_server_port) + "\n" "Make sure that this port aren't used by another program!\n\n" "Additional error info:\n" + str(BindError), 0) sys.exit(5) Log("Init", "\033[37m").new_message( "Finished initialization! Ready for receiving incoming connections...", 0) reactor.run()
#! python2.7 import sys from Config import readFromConfig from Database import Database from Network import * from Logger import Log Log(None, None).clean_log() try: from twisted.internet import ssl, reactor from twisted.internet.protocol import Factory, Protocol from twisted.web.server import Site from OpenSSL import SSL except ImportError as importErr: Log("Init", "\033[37;41m").new_message( "Fatal Error!\n" "Cannot import Twisted modules!\n" "Please install all required dependencies using\n" "`pip install -r requirements.txt`\n\n" "Additional error info:\n" + str(importErr), 0) sys.exit(1) def MainApp(): Log("Init", "\033[37m").new_message( "Initializing Battlefield Heroes Master Server Emulator...", 0) try:
def ReplaceMacro(String, MacroDefinitions=None, SelfReplacement=False, Line=None, FileName=None, Flag=False): LastString = String if MacroDefinitions is None: MacroDefinitions = {} while MacroDefinitions: QuotedStringList = [] HaveQuotedMacroFlag = False if not Flag: MacroUsed = gMACRO_PATTERN.findall(String) else: ReQuotedString = re.compile('\"') QuotedStringList = ReQuotedString.split(String) if len(QuotedStringList) >= 3: HaveQuotedMacroFlag = True Count = 0 MacroString = "" for QuotedStringItem in QuotedStringList: Count += 1 if Count % 2 != 0: MacroString += QuotedStringItem if Count == len(QuotedStringList) and Count % 2 == 0: MacroString += QuotedStringItem MacroUsed = gMACRO_PATTERN.findall(MacroString) # # no macro found in String, stop replacing # if len(MacroUsed) == 0: break for Macro in MacroUsed: if Macro not in MacroDefinitions: if SelfReplacement: String = String.replace("$(%s)" % Macro, '') Logger.Debug( 5, "Delete undefined MACROs in file %s line %d: %s!" % (FileName, Line[1], Line[0])) continue if not HaveQuotedMacroFlag: String = String.replace("$(%s)" % Macro, MacroDefinitions[Macro]) else: Count = 0 for QuotedStringItem in QuotedStringList: Count += 1 if Count % 2 != 0: QuotedStringList[Count - 1] = QuotedStringList[ Count - 1].replace("$(%s)" % Macro, MacroDefinitions[Macro]) elif Count == len(QuotedStringList) and Count % 2 == 0: QuotedStringList[Count - 1] = QuotedStringList[ Count - 1].replace("$(%s)" % Macro, MacroDefinitions[Macro]) RetString = '' if HaveQuotedMacroFlag: Count = 0 for QuotedStringItem in QuotedStringList: Count += 1 if Count != len(QuotedStringList): RetString += QuotedStringList[Count - 1] + "\"" else: RetString += QuotedStringList[Count - 1] String = RetString # # in case there's macro not defined # if String == LastString: break LastString = String return String
if outputready: for s in outputready: endpoint = self.outputSockets[s] try: while 1: msg = endpoint.outgoingMailbox.get_nowait() endpoint.send(msg) except Queue.Empty: pass # Remove output socket from select once it's done sending # del self.outputSockets[endpoint.socket] requestcounter += 1 self.requestLock = True if requestcounter > 10: Log.warn(str(requestcounter) + " loops to clear queue") def ensure_server_available(self): udpactive = self.udpEndpoint.check_heartbeat() if udpactive and self.tcpEndpoint.connectionStatus is NetworkEndpoint.PIPE_DISCONNECTED and not \ self.tcpEndpoint.hangup: Log.network("Heartbeat found! Reconnecting TCP to " + str(self.tcpEndpoint.remoteAddr)) if self.tcpEndpoint.connect(): self.inputSockets[self.tcpEndpoint.socket] = self.tcpEndpoint self.outputSockets[self.tcpEndpoint.socket] = self.tcpEndpoint Log.network("TCP connection established. Socket is %s" % self.tcpEndpoint.socket) else: Log.warn("TCP not up yet!") if not udpactive and self.tcpEndpoint.connectionStatus >= NetworkEndpoint.PIPE_CONNECTED:
# # Install distribution # InstallDp(ToBeInstalledDist[0], ToBeInstalledDist[2], ToBeInstalledDist[1], Options, Dep, WorkspaceDir, DataBase) ReturnCode = 0 except FatalError, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except KeyboardInterrupt: ReturnCode = ABORT_ERROR if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except: ReturnCode = CODE_ERROR Logger.Error( "\nInstallPkg", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.PackageFile, ExtraData=ST.MSG_SEARCH_FOR_HELP, RaiseError=False ) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) finally: Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED)
def send_handshake_ack(self): Log.network("Sending TCP handshake ACK on %s" % self.socket) self.send_msg(SimpleMessage(NetworkPrefixes.HANDSHAKE_ACK, None))
def GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList): # # ModulePathList will keep track of the standalone module path that # we just installed. If a new module's path in that list # (only multiple INF in one directory will be so), we will # install them directly. If not, we will try to create a new directory # for it. # ModulePathList = [] # # Check module exist and install # Module = None NewDict = Sdict() for Guid, Version, Name, Path in DistPkg.ModuleSurfaceArea: ModulePath = Path Module = DistPkg.ModuleSurfaceArea[Guid, Version, Name, Path] Logger.Info(ST.MSG_INSTALL_MODULE % Module.GetName()) if Dep.CheckModuleExists(Guid, Version, Name, Path): Logger.Quiet(ST.WRN_MODULE_EXISTED %Path) # # here check for the multiple inf share the same module path cases: # they should be installed into the same directory # ModuleFullPath = \ os.path.normpath(os.path.join(WorkspaceDir, ModulePath)) if ModuleFullPath not in ModulePathList: NewModulePath = InstallNewModule(WorkspaceDir, ModulePath, ModulePathList) NewModuleFullPath = os.path.normpath(os.path.join(WorkspaceDir, NewModulePath)) ModulePathList.append(NewModuleFullPath) else: NewModulePath = ModulePath InstallModuleContent(ModulePath, NewModulePath, '', Module, ContentZipFile, WorkspaceDir, ModuleList, None, DistPkg.Header.ReadOnly) # # Update module # Module.SetModulePath(Module.GetModulePath().replace(Path, NewModulePath, 1)) NewDict[Guid, Version, Name, Module.GetModulePath()] = Module # # generate all inf for modules # for (Module, Package) in ModuleList: CheckCNameInModuleRedefined(Module, DistPkg) FilePath = ModuleToInf(Module, Package, DistPkg.Header) Md5Sigature = md5.new(__FileHookOpen__(str(FilePath), 'rb').read()) Md5Sum = Md5Sigature.hexdigest() if Package: if (FilePath, Md5Sum) not in Package.FileList: Package.FileList.append((FilePath, Md5Sum)) else: if (FilePath, Md5Sum) not in Module.FileList: Module.FileList.append((FilePath, Md5Sum)) # # append the module unicode files to Package FileList # for (FilePath, Md5Sum) in Module.FileList: if str(FilePath).endswith('.uni') and Package and (FilePath, Md5Sum) not in Package.FileList: Package.FileList.append((FilePath, Md5Sum)) return NewDict
def Main(): Logger.Initialize() Parser = OptionParser(version=(MSG_VERSION + ' Build ' + gBUILD_VERSION), description=MSG_DESCRIPTION, prog="UPT.exe", usage=MSG_USAGE) Parser.add_option("-d", "--debug", action="store", type="int", dest="debug_level", help=ST.HLP_PRINT_DEBUG_INFO) Parser.add_option("-v", "--verbose", action="store_true", dest="opt_verbose", help=ST.HLP_PRINT_INFORMATIONAL_STATEMENT) Parser.add_option("-s", "--silent", action="store_true", dest="opt_slient", help=ST.HLP_RETURN_NO_DISPLAY) Parser.add_option("-q", "--quiet", action="store_true", dest="opt_quiet", help=ST.HLP_RETURN_AND_DISPLAY) Parser.add_option("-i", "--install", action="append", type="string", dest="Install_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_INSTALL) Parser.add_option("-c", "--create", action="store", type="string", dest="Create_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_CREATE) Parser.add_option("-r", "--remove", action="store", type="string", dest="Remove_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_REMOVE) Parser.add_option("-t", "--template", action="store", type="string", dest="Package_Information_Data_File", help=ST.HLP_SPECIFY_TEMPLATE_NAME_CREATE) Parser.add_option("-p", "--dec-filename", action="append", type="string", dest="EDK2_DEC_Filename", help=ST.HLP_SPECIFY_DEC_NAME_CREATE) Parser.add_option("-m", "--inf-filename", action="append", type="string", dest="EDK2_INF_Filename", help=ST.HLP_SPECIFY_INF_NAME_CREATE) Parser.add_option("-l", "--list", action="store_true", dest="List_Dist_Installed", help=ST.HLP_LIST_DIST_INSTALLED) Parser.add_option("-f", "--force", action="store_true", dest="Yes", help=ST.HLP_DISABLE_PROMPT) Parser.add_option("-n", "--custom-path", action="store_true", dest="CustomPath", help=ST.HLP_CUSTOM_PATH_PROMPT) Parser.add_option("-x", "--free-lock", action="store_true", dest="SkipLock", help=ST.HLP_SKIP_LOCK_CHECK) Parser.add_option("-u", "--replace", action="store", type="string", dest="Replace_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_REPLACE) Parser.add_option("-o", "--original", action="store", type="string", dest="Original_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_TO_BE_REPLACED) Parser.add_option("--use-guided-paths", action="store_true", dest="Use_Guided_Paths", help=ST.HLP_USE_GUIDED_PATHS) Parser.add_option("-j", "--test-install", action="append", type="string", dest="Test_Install_Distribution_Package_Files", help=ST.HLP_TEST_INSTALL) Opt = Parser.parse_args()[0] Var2Var = [ ("PackageInformationDataFile", Opt.Package_Information_Data_File), ("PackFileToInstall", Opt.Install_Distribution_Package_File), ("PackFileToCreate", Opt.Create_Distribution_Package_File), ("PackFileToRemove", Opt.Remove_Distribution_Package_File), ("PackageFileList", Opt.EDK2_DEC_Filename), ("ModuleFileList", Opt.EDK2_INF_Filename), ("InventoryWs", Opt.List_Dist_Installed), ("PackFileToReplace", Opt.Replace_Distribution_Package_File), ("PackFileToBeReplaced", Opt.Original_Distribution_Package_File), ("UseGuidedPkgPath", Opt.Use_Guided_Paths), ("TestDistFiles", Opt.Test_Install_Distribution_Package_Files) ] for Var in Var2Var: setattr(Opt, Var[0], Var[1]) try: GlobalData.gWORKSPACE, GlobalData.gPACKAGE_PATH = GetWorkspace() except FatalError as XExcept: if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) return XExcept.args[0] # Support WORKSPACE is a long path # Only works for windows system if pf.system() == 'Windows': Vol = 'B:' for Index in range(90, 65, -1): Vol = chr(Index) + ':' if not os.path.isdir(Vol): os.system('subst %s "%s"' % (Vol, GlobalData.gWORKSPACE)) break GlobalData.gWORKSPACE = '%s\\' % Vol WorkspaceDir = GlobalData.gWORKSPACE SetLogLevel(Opt) Mgr = FileHook.RecoverMgr(WorkspaceDir) FileHook.SetRecoverMgr(Mgr) GlobalData.gDB = IpiDatabase(os.path.normpath(os.path.join(WorkspaceDir, \ "Conf/DistributionPackageDatabase.db")), WorkspaceDir) GlobalData.gDB.InitDatabase(Opt.SkipLock) # # Make sure the Db will get closed correctly # try: ReturnCode = 0 CheckConflictOption(Opt) RunModule = None if Opt.PackFileToCreate: if Opt.PackageInformationDataFile: if not os.path.exists(Opt.PackageInformationDataFile): if not os.path.exists( os.path.join(WorkspaceDir, Opt.PackageInformationDataFile)): Logger.Error( "\nUPT", FILE_NOT_FOUND, ST.ERR_NO_TEMPLATE_FILE % Opt.PackageInformationDataFile) else: Opt.PackageInformationDataFile = os.path.join( WorkspaceDir, Opt.PackageInformationDataFile) else: Logger.Error("UPT", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_T_OPTION) if not Opt.PackFileToCreate.endswith('.dist'): Logger.Error("CreatePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToCreate) RunModule = MkPkg.Main elif Opt.PackFileToInstall: AbsPath = [] for Item in Opt.PackFileToInstall: if not Item.endswith('.dist'): Logger.Error("InstallPkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Item) AbsPath.append(GetFullPathDist(Item, WorkspaceDir)) if not AbsPath: Logger.Error("InstallPkg", FILE_NOT_FOUND, ST.ERR_INSTALL_DIST_NOT_FOUND % Item) Opt.PackFileToInstall = AbsPath setattr(Opt, 'PackageFile', Opt.PackFileToInstall) RunModule = InstallPkg.Main elif Opt.PackFileToRemove: if not Opt.PackFileToRemove.endswith('.dist'): Logger.Error("RemovePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToRemove) head, tail = os.path.split(Opt.PackFileToRemove) if head or not tail: Logger.Error("RemovePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_FILENAME_ONLY_FOR_REMOVE % Opt.PackFileToRemove) setattr(Opt, 'DistributionFile', Opt.PackFileToRemove) RunModule = RmPkg.Main elif Opt.InventoryWs: RunModule = InventoryWs.Main elif Opt.PackFileToBeReplaced and not Opt.PackFileToReplace: Logger.Error("ReplacePkg", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_U_OPTION) elif Opt.PackFileToReplace: if not Opt.PackFileToReplace.endswith('.dist'): Logger.Error("ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToReplace) if not Opt.PackFileToBeReplaced: Logger.Error("ReplacePkg", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_O_OPTION) if not Opt.PackFileToBeReplaced.endswith('.dist'): Logger.Error("ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToBeReplaced) head, tail = os.path.split(Opt.PackFileToBeReplaced) if head or not tail: Logger.Error( "ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_FILENAME_ONLY_FOR_REPLACE_ORIG % Opt.PackFileToBeReplaced) AbsPath = GetFullPathDist(Opt.PackFileToReplace, WorkspaceDir) if not AbsPath: Logger.Error( "ReplacePkg", FILE_NOT_FOUND, ST.ERR_REPLACE_DIST_NOT_FOUND % Opt.PackFileToReplace) Opt.PackFileToReplace = AbsPath RunModule = ReplacePkg.Main elif Opt.Test_Install_Distribution_Package_Files: for Dist in Opt.Test_Install_Distribution_Package_Files: if not Dist.endswith('.dist'): Logger.Error("TestInstall", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Dist) setattr(Opt, 'DistFiles', Opt.Test_Install_Distribution_Package_Files) RunModule = TestInstall.Main else: Parser.print_usage() return OPTION_MISSING ReturnCode = RunModule(Opt) except FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc()) finally: try: if ReturnCode != 0 and ReturnCode != UPT_ALREADY_INSTALLED_ERROR: Logger.Quiet(ST.MSG_RECOVER_START) GlobalData.gDB.RollBack() Mgr.rollback() Logger.Quiet(ST.MSG_RECOVER_DONE) else: GlobalData.gDB.Commit() Mgr.commit() except Exception: Logger.Quiet(ST.MSG_RECOVER_FAIL) GlobalData.gDB.CloseDb() if pf.system() == 'Windows': os.system('subst %s /D' % GlobalData.gWORKSPACE.replace('\\', '')) return ReturnCode
def InstallModuleContent(FromPath, NewPath, ModulePath, Module, ContentZipFile, WorkspaceDir, ModuleList, Package = None, ReadOnly = False): if NewPath.startswith("\\") or NewPath.startswith("/"): NewPath = NewPath[1:] if not IsValidInstallPath(NewPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%NewPath) NewModuleFullPath = os.path.normpath(os.path.join(WorkspaceDir, NewPath, ConvertPath(ModulePath))) Module.SetFullPath(os.path.normpath(os.path.join(NewModuleFullPath, ConvertPath(Module.GetName()) + '.inf'))) Module.FileList = [] for MiscFile in Module.GetMiscFileList(): if not MiscFile: continue for Item in MiscFile.GetFileList(): File = Item.GetURI() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%File) FromFile = os.path.join(FromPath, ModulePath, File) Executable = Item.GetExecutable() ToFile = os.path.normpath(os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) for Item in Module.GetSourceFileList(): File = Item.GetSourceFile() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%File) FromFile = os.path.join(FromPath, ModulePath, File) ToFile = os.path.normpath(os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) for Item in Module.GetBinaryFileList(): FileNameList = Item.GetFileNameList() for FileName in FileNameList: File = FileName.GetFilename() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%File) FromFile = os.path.join(FromPath, ModulePath, File) ToFile = os.path.normpath(os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly, ModuleList)
def InfSourceParser(self, SectionString, InfSectionObject, FileName): SectionMacros = {} ValueList = [] SourceList = [] StillCommentFalg = False HeaderComments = [] LineComment = None SectionContent = '' for Line in SectionString: SrcLineContent = Line[0] SrcLineNo = Line[1] if SrcLineContent.strip() == '': continue # # Found Header Comments # if SrcLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): # # Last line is comments, and this line go on. # if StillCommentFalg: HeaderComments.append(Line) SectionContent += SrcLineContent + DT.END_OF_LINE continue # # First time encounter comment # else: # # Clear original data # HeaderComments = [] HeaderComments.append(Line) StillCommentFalg = True SectionContent += SrcLineContent + DT.END_OF_LINE continue else: StillCommentFalg = False if len(HeaderComments) >= 1: LineComment = InfLineCommentObject() LineCommentContent = '' for Item in HeaderComments: LineCommentContent += Item[0] + DT.END_OF_LINE LineComment.SetHeaderComments(LineCommentContent) # # Find Tail comment. # if SrcLineContent.find(DT.TAB_COMMENT_SPLIT) > -1: TailComments = SrcLineContent[SrcLineContent. find(DT.TAB_COMMENT_SPLIT):] SrcLineContent = SrcLineContent[:SrcLineContent. find(DT.TAB_COMMENT_SPLIT)] if LineComment is None: LineComment = InfLineCommentObject() LineComment.SetTailComments(TailComments) # # Find Macro # Name, Value = MacroParser((SrcLineContent, SrcLineNo), FileName, DT.MODEL_EFI_SOURCE_FILE, self.FileLocalMacros) if Name is not None: SectionMacros[Name] = Value LineComment = None HeaderComments = [] continue # # Replace with Local section Macro and [Defines] section Macro. # SrcLineContent = InfExpandMacro( SrcLineContent, (FileName, SrcLineContent, SrcLineNo), self.FileLocalMacros, SectionMacros) TokenList = GetSplitValueList(SrcLineContent, DT.TAB_VALUE_SPLIT, 4) ValueList[0:len(TokenList)] = TokenList # # Store section content string after MACRO replaced. # SectionContent += SrcLineContent + DT.END_OF_LINE SourceList.append((ValueList, LineComment, (SrcLineContent, SrcLineNo, FileName))) ValueList = [] LineComment = None TailComments = '' HeaderComments = [] continue # # Current section archs # ArchList = [] for Item in self.LastSectionHeaderContent: if Item[1] not in ArchList: ArchList.append(Item[1]) InfSectionObject.SetSupArchList(Item[1]) InfSectionObject.SetAllContent(SectionContent) if not InfSectionObject.SetSources(SourceList, Arch=ArchList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Sources]"), File=FileName, Line=Item[3])
class TCPEndpoint(NetworkEndpoint): """Network endpoint using TCP""" def __init__(self, localport, remoteport, threaded=True, isserversocket=True, existingsocket=None): self.serverSocket = isserversocket self.hangup = False self.clientHandshakeCallbacks = set() self.handshakeAckCallbacks = set() if existingsocket: self.socket = existingsocket NetworkEndpoint.__init__(self, localport, remoteport, threaded) def close(self): self.hangup = True NetworkEndpoint.close(self) def create_socket(self): self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.settimeout(5) if self.serverSocket: self.socket.bind(self.localAddr) self.socket.listen(2) if not self.threaded: self.socket.setblocking(0) else: self.socket.setblocking(1) def connect(self): self.create_socket() status = 0 retries = 5 while retries > 0: try: status = self.socket.connect(self.remoteAddr) except socket.error, e: if e[0] == NetworkErrors.EISCONN: Log.network("...TCP connected!") self.connectionStatus = NetworkEndpoint.PIPE_CONNECTED break elif e[0] == NetworkErrors.EAGAIN: Log.network("TCP connecting...") retries -= 1 elif e[0] == socket.timeout: Log.error("Timed out") self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED else: Log.error("Connection failed!") Log.error("Reason: " + str(e)) self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED break if status == 0: self.connectionStatus = NetworkEndpoint.PIPE_CONNECTED else: Log.error("Connection failed with error %s" % status) return self.connectionStatus
def Main(): Logger.Initialize() Parser = OptionParser(version=(MSG_VERSION + ' Build ' + gBUILD_VERSION), description=MSG_DESCRIPTION, prog="UPT.exe", usage=MSG_USAGE) Parser.add_option("-d", "--debug", action="store", type="int", dest="debug_level", help=ST.HLP_PRINT_DEBUG_INFO) Parser.add_option("-v", "--verbose", action="store_true", dest="opt_verbose", help=ST.HLP_PRINT_INFORMATIONAL_STATEMENT) Parser.add_option("-s", "--silent", action="store_true", dest="opt_slient", help=ST.HLP_RETURN_NO_DISPLAY) Parser.add_option("-q", "--quiet", action="store_true", dest="opt_quiet", help=ST.HLP_RETURN_AND_DISPLAY) Parser.add_option("-i", "--install", action="store", type="string", dest="Install_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_INSTALL) Parser.add_option("-c", "--create", action="store", type="string", dest="Create_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_CREATE) Parser.add_option("-r", "--remove", action="store", type="string", dest="Remove_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_REMOVE) Parser.add_option("-t", "--template", action="store", type="string", dest="Package_Information_Data_File", help=ST.HLP_SPECIFY_TEMPLATE_NAME_CREATE) Parser.add_option("-p", "--dec-filename", action="append", type="string", dest="EDK2_DEC_Filename", help=ST.HLP_SPECIFY_DEC_NAME_CREATE) Parser.add_option("-m", "--inf-filename", action="append", type="string", dest="EDK2_INF_Filename", help=ST.HLP_SPECIFY_INF_NAME_CREATE) Parser.add_option("-l", "--list", action="store_true", dest="List_Dist_Installed", help=ST.HLP_LIST_DIST_INSTALLED) Parser.add_option("-f", "--force", action="store_true", dest="Yes", help=ST.HLP_DISABLE_PROMPT) Parser.add_option("-n", "--custom-path", action="store_true", dest="CustomPath", help=ST.HLP_CUSTOM_PATH_PROMPT) Parser.add_option("-x", "--free-lock", action="store_true", dest="SkipLock", help=ST.HLP_SKIP_LOCK_CHECK) Parser.add_option("-u", "--replace", action="store", type="string", dest="Replace_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_REPLACE) Parser.add_option("-o", "--original", action="store", type="string", dest="Original_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_TO_BE_REPLACED) Parser.add_option("--use-guided-paths", action="store_true", dest="Use_Guided_Paths", help=ST.HLP_USE_GUIDED_PATHS) Parser.add_option("-j", "--test-install", action="append", type="string", dest="Test_Install_Distribution_Package_Files", help=ST.HLP_TEST_INSTALL) Opt = Parser.parse_args()[0] Var2Var = [ ("PackageInformationDataFile", Opt.Package_Information_Data_File), ("PackFileToInstall", Opt.Install_Distribution_Package_File), ("PackFileToCreate", Opt.Create_Distribution_Package_File), ("PackFileToRemove", Opt.Remove_Distribution_Package_File), ("PackageFileList", Opt.EDK2_DEC_Filename), ("ModuleFileList", Opt.EDK2_INF_Filename), ("InventoryWs", Opt.List_Dist_Installed), ("PackFileToReplace", Opt.Replace_Distribution_Package_File), ("PackFileToBeReplaced", Opt.Original_Distribution_Package_File), ("UseGuidedPkgPath", Opt.Use_Guided_Paths), ("TestDistFiles", Opt.Test_Install_Distribution_Package_Files) ] for Var in Var2Var: setattr(Opt, Var[0], Var[1]) try: GlobalData.gWORKSPACE, GlobalData.gPACKAGE_PATH = GetWorkspace() except FatalError, XExcept: if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) return XExcept.args[0]
def Wait(): MIN = 1 MAX = 3 sec = random.randint(MIN, MAX) Log.log("Wait for " + str(sec) + " secs.") time.sleep(sec)
def InfGuidParser(self, SectionString, InfSectionObject, FileName): # # Macro defined in this section # SectionMacros = {} ValueList = [] GuidList = [] CommentsList = [] CurrentLineVar = None # # Parse section content # for Line in SectionString: LineContent = Line[0] LineNo = Line[1] if LineContent.strip() == '': CommentsList = [] continue if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): CommentsList.append(Line) continue else: # # Encounter a GUID entry # if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1: CommentsList.append( (LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):], LineNo)) LineContent = \ LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)] if LineContent != '': # # Find Macro # Name, Value = MacroParser((LineContent, LineNo), FileName, DT.MODEL_EFI_GUID, self.FileLocalMacros) if Name != None: SectionMacros[Name] = Value CommentsList = [] ValueList = [] continue TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1) ValueList[0:len(TokenList)] = TokenList # # Replace with Local section Macro and [Defines] section Macro. # ValueList = [ InfExpandMacro(Value, (FileName, LineContent, LineNo), self.FileLocalMacros, SectionMacros, True) for Value in ValueList ] CurrentLineVar = (LineContent, LineNo, FileName) if len(ValueList) >= 1: GuidList.append((ValueList, CommentsList, CurrentLineVar)) CommentsList = [] ValueList = [] continue # # Current section archs # ArchList = [] LineIndex = -1 for Item in self.LastSectionHeaderContent: LineIndex = Item[3] if Item[1] not in ArchList: ArchList.append(Item[1]) if not InfSectionObject.SetGuid(GuidList, Arch=ArchList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Guid]"), File=FileName, Line=LineIndex)
def SetPpi(self, PpiList, Arch = None): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem is None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) for Item in PpiList: # # Get Comment content of this protocol # CommentsList = None if len(Item) == 3: CommentsList = Item[1] CurrentLineOfItem = Item[2] Item = Item[0] InfPpiItemObj = InfPpiItem() if len(Item) >= 1 and len(Item) <= 2: # # Only CName contained # if not IsValidCVariableName(Item[0]): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if (Item[0] != ''): InfPpiItemObj.SetName(Item[0]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_CNAME_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Have FeatureFlag information # if len(Item) == 2: # # Contained CName and Feature Flag Express # <statements> ::= <CName> ["|" <FeatureFlagExpress>] # Item[1] should not be empty # if Item[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Validate Feature Flag Express for PPI entry # Item[1] contain FFE information # FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) InfPpiItemObj.SetFeatureFlagExp(Item[1]) if len(Item) != 1 and len(Item) != 2: # # Invalid format of Ppi statement # Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Get/Set Usage and HelpString for PPI entry # if CommentsList is not None and len(CommentsList) != 0: InfPpiItemObj = ParsePpiComment(CommentsList, InfPpiItemObj) else: CommentItemIns = InfPpiItemCommentContent() CommentItemIns.SetUsage(DT.ITEM_UNDEFINED) CommentItemIns.SetNotify(DT.ITEM_UNDEFINED) InfPpiItemObj.SetCommentList([CommentItemIns]) InfPpiItemObj.SetSupArchList(__SupArchList) # # Determine PPI name duplicate. Follow below rule: # # A PPI must not be duplicated within a [Ppis] section. # A PPI may appear in multiple architectural [Ppis] # sections. A PPI listed in an architectural [Ppis] # section must not be listed in the common architectural # [Ppis] section. # # NOTE: This check will not report error now. # for Item in self.Ppis: if Item.GetName() == InfPpiItemObj.GetName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for PpiItemObjArch in __SupArchList: if ItemArch == PpiItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper() == 'COMMON' or PpiItemObjArch.upper() == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if (InfPpiItemObj) in self.Ppis: PpiList = self.Ppis[InfPpiItemObj] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList else: PpiList = [] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList return True
RemoveDist(OrigDpGuid, OrigDpVersion, StoredDistFile, DataBase, WorkspaceDir, Options.Yes) # # Install the new distribution # InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir, DataBase) ReturnCode = 0 except FatalError, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except KeyboardInterrupt: ReturnCode = ABORT_ERROR if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except: ReturnCode = CODE_ERROR Logger.Error( "\nReplacePkg", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_REPLACE_ERR % (Options.PackFileToReplace, Options.PackFileToBeReplaced), ExtraData=ST.MSG_SEARCH_FOR_HELP, RaiseError=False ) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) finally:
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # For questions regarding this module contact # Rob King <*****@*****.**> or visit http://www.e-mu.org """ try: import Live from _Framework.Debug import debug_print except ImportError, e: from Logger import Log Log.warn("Live library not available!") def getSong(): """Gets a the current Song instance""" return Live.Application.get_application().get_document() def continuePlaying(): """Continues Playing""" getSong().continue_playing() def playSelection(): """Plays the current selection""" getSong().play_selection()
def __init__(self, filename): self.byNumber = {} self.byName = {} # read the text file sig_found = False text = '' Log.log(1, "Reading message template %s" % filename) fd = open(filename, 'r') linecount = 0 for line in fd: line = line.split('//')[0] # remove comments line = line.strip() # remove leading and trailing whitespace line = line.replace('\t', ' ') # replace tabs for spaces while 1: # coalesce spaces new = line.replace(' ', ' ') if new == line: break line = new line = line.replace(' {', '{') # strip spaces before opening brackets line = line.replace('{ ', '{') # strip spaces after opening brackets line = line.replace(' }', '}') # strip spaces before closing brackets line = line.replace('} ', '}') # strip spaces after closing brackets if not sig_found and line.startswith('version'): sig_found = True if line != 'version 2.0': raise SLException, "Uncompatible message template format: %s" % line continue # skip the version line text += line linecount += 1 ########################### ## firstSlice = 'RpcChannelRequest' ## lastSlice = 'RpcScriptReplyInbound' ## slicingNow = False ########################### # message definition msgcount_low = 0 msgcount_medium = 0 msgcount_high = 0 msgcount_fixed = 0 while text: if text[0] == '}': break if text[0] != '{': raise SLException, "Parsing error" text = text[1:] p = text.find('{') q = text.find('}') if p == -1: raise SLException, "Parsing error" # message has no blocks if p > q: header = text[:q] text = text[q+1:] name, freq, number, trust, encoding = header.split(' ') ########################### ## if not slicingNow: ## if name == firstSlice: ## slicingNow = True ## else: ## print "%s," % name, ## if name == lastSlice: ## slicingNow = False #### if name.lower().find('god') != -1: #### print "%s," % name, ########################### if freq not in self.freqLabels: raise SLException, "Bad frequency label: %s" % freq if trust not in self.trustLabels: raise SLException, "Bad trust label: %s" % freq if encoding not in self.encodingLabels: raise SLException, "Bad encoding label: %s" % freq if freq == 'Low': msgcount_low += 1 elif freq == 'Medium': msgcount_medium += 1 elif freq == 'High': msgcount_high += 1 elif freq == 'Fixed': msgcount_fixed += 1 snumber = number if snumber[:2] == '0x': number = long(snumber, 0x10) else: number = long(snumber) if number == 0: raise SLException, "Bad message number: %s" % snumber if freq in ('High', 'Fixed'): msgnum = number elif freq == 'Medium': msgnum = number + 0xFF00L elif freq == 'Low': msgnum = number + 0xFFFF0000L msg = SLMessageTemplate(name, freq, msgnum, trust, encoding) self.byNumber[msgnum] = msg self.byName[name] = msg continue # message has blocks header = text[:p] text = text[p:] name, freq, number, trust, encoding = header.split(' ') ########################### ## if not slicingNow: ## if name == firstSlice: ## slicingNow = True ## else: ## print "%s," % name, ## if name == lastSlice: ## slicingNow = False #### if name.lower().find('god') != -1: #### print "%s," % name, ########################### if freq not in self.freqLabels: raise SLException, "Bad frequency label: %s" % freq if trust not in self.trustLabels: raise SLException, "Bad trust label: %s" % freq if encoding not in self.encodingLabels: raise SLException, "Bad encoding label: %s" % freq if freq == 'Low': msgcount_low += 1 elif freq == 'Medium': msgcount_medium += 1 elif freq == 'High': msgcount_high += 1 elif freq == 'Fixed': msgcount_fixed += 1 snumber = number if snumber[:2] == '0x': number = long(snumber[2:], 0x10) else: number = long(snumber) if number == 0: raise SLException, "Bad message number: %s" % snumber if freq in ('High', 'Fixed'): msgnum = number elif freq == 'Medium': msgnum = number + 0xFF00L elif freq == 'Low': msgnum = number + 0xFFFF0000L msg = SLMessageTemplate(name, freq, msgnum, trust, encoding) self.byNumber[msgnum] = msg self.byName[name] = msg # block definitions while 1: if text[0] == '}': break if text[0] != '{': raise SLException, "Parsing error" text = text[1:] p = text.find('{') q = text.find('}') if p == -1 or p > q: raise SLException, "Parsing error" header = text[:p] text = text[p:] header = header.split(' ') name = header[0] bltype = header[1] if bltype not in self.blockTypes: raise SLException, "Bad block type: %s" % bltype if bltype == 'Multiple': if len(header) != 3: raise SLException, "Parsing error" count = long(header[2]) if count == 0: raise SLException, "Bad block count: %s" % header[2] else: if len(header) != 2: raise SLException, "Parsing error" count = 1 blk = SLBlockTemplate(name, bltype, count) msg.blocks.append(blk) # parameter definitions while 1: if text[0] == '}': break if text[0] != '{': raise SLException, "Parsing error" text = text[1:] p = text.find('{') q = text.find('}') if p < q and p != -1: print text[:100] raise SLException, "Parsing error" header = text[:q] text = text[q+1:] header = header.split(' ') name = header[0] ptype = header[1] if ptype in ('Fixed', 'Variable'): if len(header) != 3: raise SLException, "Parsing error" size = long(header[2]) if size == 0: raise SLException, "Bad parameter count: %s" % header[2] else: if len(header) != 2: raise SLException, "Parsing error" size = None try: pclass = getattr(SLTypes, ptype) except SLException, e: raise SLException, "Bad parameter type: %s" % ptype prm = SLParameterTemplate(name, ptype, pclass, size) blk.parameters.append(prm) # closing bracket of each block definition if text[0] != '}': raise SLException, "Parsing error" text = text[1:] # closing bracket of each message definition if text[0] != '}': raise SLException, "Parsing error" text = text[1:]
def InfSpecialCommentParser(self, SpecialSectionList, InfSectionObject, ContainerFile, SectionType): ReFindSpecialCommentRe = re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL) ReFindHobArchRe = re.compile(r"""[Hh][Oo][Bb]\.([^,]*)""", re.DOTALL) if self.FileName: pass SpecialObjectList = [] ArchList = [] if SectionType == DT.TYPE_EVENT_SECTION: TokenDict = DT.EVENT_TOKENS elif SectionType == DT.TYPE_HOB_SECTION: TokenDict = DT.HOB_TOKENS else: TokenDict = DT.BOOTMODE_TOKENS for List in SpecialSectionList: # # Hob has Arch attribute, need to be handled specially here # if SectionType == DT.TYPE_HOB_SECTION: MatchObject = ReFindSpecialCommentRe.search(List[0][0]) HobSectionStr = MatchObject.group(1) ArchList = [] for Match in ReFindHobArchRe.finditer(HobSectionStr): Arch = Match.groups(1)[0].upper() ArchList.append(Arch) CommentSoFar = '' for Index in xrange(1, len(List)): Result = ParseComment(List[Index], DT.ALL_USAGE_TOKENS, TokenDict, [], False) Usage = Result[0] Type = Result[1] HelpText = Result[3] if Usage == DT.ITEM_UNDEFINED and Type == DT.ITEM_UNDEFINED: if HelpText is None: HelpText = '' if not HelpText.endswith('\n'): HelpText += '\n' CommentSoFar += HelpText else: if HelpText: CommentSoFar += HelpText if SectionType == DT.TYPE_EVENT_SECTION: SpecialObject = InfEventObject() SpecialObject.SetEventType(Type) SpecialObject.SetUsage(Usage) SpecialObject.SetHelpString(CommentSoFar) elif SectionType == DT.TYPE_HOB_SECTION: SpecialObject = InfHobObject() SpecialObject.SetHobType(Type) SpecialObject.SetUsage(Usage) SpecialObject.SetHelpString(CommentSoFar) if len(ArchList) >= 1: SpecialObject.SetSupArchList(ArchList) else: SpecialObject = InfBootModeObject() SpecialObject.SetSupportedBootModes(Type) SpecialObject.SetUsage(Usage) SpecialObject.SetHelpString(CommentSoFar) SpecialObjectList.append(SpecialObject) CommentSoFar = '' if not InfSectionObject.SetSpecialComments(SpecialObjectList, SectionType): Logger.Error( 'InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (SectionType), ContainerFile)
def build_midi_map(self, midi_map_handle): Log.info("Building midi map...") ControlSurface.build_midi_map(self, midi_map_handle)
def IsRequiredItemListNull(ItemDict, XmlTreeLevel): for Key in ItemDict: if not ItemDict[Key]: Msg = "->".join(Node for Node in XmlTreeLevel) ErrorMsg = ERR_XML_PARSER_REQUIRED_ITEM_MISSING % (Key, Msg) Logger.Error('\nUPT', PARSER_ERROR, ErrorMsg, RaiseError=True)
def InstallPackageContent(FromPath, ToPath, Package, ContentZipFile, Dep, WorkspaceDir, ModuleList, ReadOnly = False): if Dep: pass Package.FileList = [] if ToPath.startswith("\\") or ToPath.startswith("/"): ToPath = ToPath[1:] if not IsValidInstallPath(ToPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%ToPath) if FromPath.startswith("\\") or FromPath.startswith("/"): FromPath = FromPath[1:] if not IsValidInstallPath(FromPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FromPath) PackageFullPath = os.path.normpath(os.path.join(WorkspaceDir, ToPath)) for MiscFile in Package.GetMiscFileList(): for Item in MiscFile.GetFileList(): FileName = Item.GetURI() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName) FromFile = os.path.join(FromPath, FileName) Executable = Item.GetExecutable() ToFile = (os.path.join(PackageFullPath, ConvertPath(FileName))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable) if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) PackageIncludeArchList = [] for Item in Package.GetPackageIncludeFileList(): FileName = Item.GetFilePath() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName) FromFile = os.path.join(FromPath, FileName) ToFile = os.path.normpath(os.path.join(PackageFullPath, ConvertPath(FileName))) RetFile = ContentZipFile.UnpackFile(FromFile, ToFile) if RetFile == '': # # a non-exist path in Zipfile will return '', which means an include directory in our case # save the information for later DEC creation usage and also create the directory # PackageIncludeArchList.append([Item.GetFilePath(), Item.GetSupArchList()]) CreateDirectory(ToFile) continue if ReadOnly: chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH) else: chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH) Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read()) Md5Sum = Md5Sigature.hexdigest() if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) Package.SetIncludeArchList(PackageIncludeArchList) for Item in Package.GetStandardIncludeFileList(): FileName = Item.GetFilePath() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName) FromFile = os.path.join(FromPath, FileName) ToFile = os.path.normpath(os.path.join(PackageFullPath, ConvertPath(FileName))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) # # Update package # Package.SetPackagePath(Package.GetPackagePath().replace(FromPath, ToPath, 1)) Package.SetFullPath(os.path.normpath(os.path.join(PackageFullPath, ConvertPath(Package.GetName()) + '.dec'))) # # Install files in module # Module = None ModuleDict = Package.GetModuleDict() for ModuleGuid, ModuleVersion, ModuleName, ModulePath in ModuleDict: Module = ModuleDict[ModuleGuid, ModuleVersion, ModuleName, ModulePath] InstallModuleContent(FromPath, ToPath, ModulePath, Module, ContentZipFile, WorkspaceDir, ModuleList, Package, ReadOnly)
def send_handshake(self): Log.network("Sending TCP handshake") self.send_msg(SimpleMessage(NetworkPrefixes.HANDSHAKE, None)) self.connectionStatus = NetworkEndpoint.HANDSHAKING
def handshake_complete(self): Log.network("Handshake completed") self.sync_actions() # Add wrappers to Live objects LiveSong.add_instance(LiveSong(self.getsong()))
def _GenInfDefineStateMent(HeaderComment, Name, Value, TailComment): Logger.Debug(5, HeaderComment + TailComment) Statement = '%s = %s' % (Name, Value) return Statement
def poll(self): self.ensure_server_available() # Loop through all messages in the socket till it's empty # If the lock is active, then the queue is not empty requestcounter = 0 while self.requestLock: self.requestLock = False badsockets = [] inputready = None outputready = None try: inputready, outputready, exceptready = select.select( self.inputSockets.keys(), self.outputSockets.keys(), badsockets, 0) except socket.error, e: if e[0] == NetworkErrors.EBADF: Log.error("Bad file descriptor! Probably a dead socket passed to select") Log.debug(self.inputSockets.keys()) Log.debug(self.outputSockets.keys()) if badsockets: Log.error("Bad sockets: %s" % badsockets) if inputready: for s in inputready: endpoint = self.inputSockets[s] try: endpoint.recv_msg() except (ReadError, RuntimeError), e: Log.error("Socket receive error! Closing %s. Reason: %s" % (endpoint, e)) endpoint.close() try: del self.inputSockets[endpoint.socket] del self.outputSockets[endpoint.socket] try: outputready.remove(endpoint.socket) except ValueError: pass except KeyError: Log.network("Socket missing. In input hangup") continue
def GenBinaryData(BinaryData, BinaryObj, BinariesDict, AsBuildIns, BinaryFileObjectList, \ SupArchList, BinaryModule, DecObjList=None): if BinaryModule: pass OriSupArchList = SupArchList for Item in BinaryData: ItemObj = BinaryObj[Item][0][0] if ItemObj.GetType( ) not in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST: TagName = ItemObj.GetTagName() Family = ItemObj.GetFamily() else: TagName = '' Family = '' FFE = ItemObj.GetFeatureFlagExp() # # If have architecturie specified, then use the specified architecturie; # If the section tag does not have an architecture modifier or the modifier is "common" (case in-sensitive), # and the VALID_ARCHITECTURES comment exists, the list from the VALID_ARCHITECTURES comment # can be used for the attribute. # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty. # SupArchList = sorted(ConvertArchList(ItemObj.GetSupArchList())) if len(SupArchList) == 1 and SupArchList[0] == 'COMMON': if not (len(OriSupArchList) == 1 or OriSupArchList[0] == 'COMMON'): SupArchList = OriSupArchList else: SupArchList = ['COMMON'] FileNameObj = CommonObject.FileNameObject() FileNameObj.SetFileType(ItemObj.GetType()) FileNameObj.SetFilename(ItemObj.GetFileName()) FileNameObj.SetFeatureFlag(FFE) # # Get GUID value of the GUID CName in the DEC file # if ItemObj.GetType() == DT.SUBTYPE_GUID_BINARY_FILE_TYPE: if not CheckGuidRegFormat(ItemObj.GetGuidValue()): if not DecObjList: if DT.TAB_HORIZON_LINE_SPLIT in ItemObj.GetGuidValue() or \ DT.TAB_COMMA_SPLIT in ItemObj.GetGuidValue(): Logger.Error("\nMkPkg", FORMAT_INVALID, ST.ERR_DECPARSE_DEFINE_PKGGUID, ExtraData=ItemObj.GetGuidValue(), RaiseError=True) else: Logger.Error("\nMkPkg", FORMAT_INVALID, ST.ERR_UNI_SUBGUID_VALUE_DEFINE_DEC_NOT_FOUND % \ (ItemObj.GetGuidValue()), RaiseError=True) else: for DecObj in DecObjList: for GuidObj in DecObj.GetGuidList(): if GuidObj.GetCName() == ItemObj.GetGuidValue(): FileNameObj.SetGuidValue(GuidObj.GetGuid()) break if not FileNameObj.GetGuidValue(): Logger.Error("\nMkPkg", FORMAT_INVALID, ST.ERR_DECPARSE_CGUID_NOT_FOUND % \ (ItemObj.GetGuidValue()), RaiseError=True) else: FileNameObj.SetGuidValue(ItemObj.GetGuidValue().strip()) FileNameObj.SetSupArchList(SupArchList) FileNameList = [FileNameObj] BinaryFile = BinaryFileObject() BinaryFile.SetFileNameList(FileNameList) BinaryFile.SetAsBuiltList(AsBuildIns) BinaryFileObjectList.append(BinaryFile) SupArchStr = ' '.join(SupArchList) Key = (ItemObj.GetFileName(), ItemObj.GetType(), FFE, SupArchStr) ValueItem = (ItemObj.GetTarget(), Family, TagName, '') if Key in BinariesDict: ValueList = BinariesDict[Key] ValueList.append(ValueItem) BinariesDict[Key] = ValueList else: BinariesDict[Key] = [ValueItem] return BinariesDict, AsBuildIns, BinaryFileObjectList
def event(self, event): self.requestLock = True # Lock the request loop Log.info("Received method " + event.subject[2:]) Log.info("Args are:" + str(event.msg)) self.incomingSubscriptions[event.subject]["function"](event.msg)
def SectionHeaderParser(self, SectionString, FileName, LineNo): _Scope = [] _SectionName = '' ArchList = set() _ValueList = [] _PcdNameList = [ DT.TAB_INF_FIXED_PCD.upper(), DT.TAB_INF_FEATURE_PCD.upper(), DT.TAB_INF_PATCH_PCD.upper(), DT.TAB_INF_PCD.upper(), DT.TAB_INF_PCD_EX.upper() ] SectionString = SectionString.strip() for Item in GetSplitValueList(SectionString[1:-1], DT.TAB_COMMA_SPLIT): if Item == '': Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (""), File=FileName, Line=LineNo, ExtraData=SectionString) ItemList = GetSplitValueList(Item, DT.TAB_SPLIT) # # different section should not mix in one section # Allow different PCD type sections mixed together # if _SectionName.upper() not in _PcdNameList: if _SectionName != '' and _SectionName.upper( ) != ItemList[0].upper(): Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_SECTION_NAME_DUPLICATE, File=FileName, Line=LineNo, ExtraData=SectionString) elif _PcdNameList[1] in [_SectionName.upper(), ItemList[0].upper()] and \ (_SectionName.upper()!= ItemList[0].upper()): Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (""), File=FileName, Line=LineNo, ExtraData=SectionString) _SectionName = ItemList[0] if _SectionName.upper() in gINF_SECTION_DEF: self._SectionType = gINF_SECTION_DEF[_SectionName.upper()] else: self._SectionType = DT.MODEL_UNKNOWN Logger.Error("Parser", FORMAT_INVALID, ST.ERR_INF_PARSER_UNKNOWN_SECTION, File=FileName, Line=LineNo, ExtraData=SectionString) # # Get Arch # Str1, ArchList = GetArch(ItemList, ArchList, FileName, LineNo, SectionString) # # For [Defines] section, do special check. # if ItemList[0].upper() == DT.TAB_COMMON_DEFINES.upper(): if len(ItemList) != 1: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (SectionString), File=FileName, Line=LineNo, ExtraData=SectionString) # # For [UserExtension] section, do special check. # if ItemList[0].upper() == DT.TAB_USER_EXTENSIONS.upper(): RetValue = ProcessUseExtHeader(ItemList) if not RetValue[0]: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (SectionString), File=FileName, Line=LineNo, ExtraData=SectionString) else: ItemList = RetValue[1] if len(ItemList) == 3: ItemList.append('COMMON') Str1 = ItemList[1] # # For Library classes, need to check module type. # if ItemList[0].upper() == DT.TAB_LIBRARY_CLASSES.upper() and len( ItemList) == 3: if ItemList[2] != '': ModuleTypeList = GetSplitValueList(ItemList[2], DT.TAB_VALUE_SPLIT) for Item in ModuleTypeList: if Item.strip() not in DT.MODULE_LIST: Logger.Error( 'Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID % (Item), File=FileName, Line=LineNo, ExtraData=SectionString) # # GetSpecialStr2 # Str2 = GetSpecialStr2(ItemList, FileName, LineNo, SectionString) _Scope.append([Str1, Str2]) _NewValueList = [] _AppendFlag = True if _SectionName.upper() in _PcdNameList: for ValueItem in _ValueList: if _SectionName.upper() == ValueItem[0].upper( ) and Str1.upper() not in ValueItem[1].split(): ValueItem[1] = ValueItem[1] + " " + Str1 _AppendFlag = False elif _SectionName.upper() == ValueItem[0].upper( ) and Str1.upper() in ValueItem[1].split(): _AppendFlag = False _NewValueList.append(ValueItem) _ValueList = _NewValueList if _AppendFlag: if not ItemList[0].upper() == DT.TAB_USER_EXTENSIONS.upper(): _ValueList.append([_SectionName, Str1, Str2, LineNo]) else: if len(ItemList) == 4: _ValueList.append( [_SectionName, Str1, Str2, ItemList[3], LineNo]) self.SectionHeaderContent = deepcopy(_ValueList)