def format_dt_display(dt): """Returns a local-time string representation of the datetime instance dt """ # Convert tz-aware datetime to local time zone if dt.tzinfo: dt = dt.astimezone(tzlocal()) if hasattr(locale, 'nl_langinfo'): # nl_langinfo "...is not available on all systems, and the set of # possible options might also vary across platforms" v = dt.strftime(locale.nl_langinfo(locale.D_T_FMT)) # strftime "...output may contain Unicode characters encoded using the # locale's default encoding" # locale.getlocale() is not the correct function to use - use # locale.getdefaultlocale() # encoding might be None language_code, encoding = get_default_locale() # Ignoring errors because I am paranoid about the behaviour of the # locale functions return v elif win32api: # https://msdn.microsoft.com/en-us/library/dd373901(v=vs.85).aspx LOCALE_USER_DEFAULT = 0x0400 DATE_LONGDATE = 2 time = win32api.GetTimeFormat(LOCALE_USER_DEFAULT, 0, dt) date = win32api.GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, dt) return '{0} {1}'.format(date, time) else: return dt.isoformat()
def Has_Save(self, Dir, Filename): Save = ["No", "", "N/A"] for extension in Config.Config["Save_Extensions"]: Save_Filename = os.path.join( Config.Config["Save_Dir_On_Cart"], os.path.splitext(Filename)[0] + extension) if os.path.isfile(Save_Filename): try: # fix for OSX FileDate = "%s %s" % ( win32api.GetDateFormat( win32api.GetSystemDefaultLCID(), 0, time.localtime( os.path.getmtime(Save_Filename))).lower(), win32api.GetTimeFormat( win32api.GetSystemDefaultLCID(), 0, time.localtime(os.path.getmtime(Save_Filename)))) except: FileDate = "" Save = ["Yes", Save_Filename, FileDate] break elif sys.platform == "win32": try: Short_Save_Filename = win32api.GetShortPathName( os.path.join(Config.Config["Save_Dir_On_Cart"], Filename)) Short_Save_Filename = os.path.join( Config.Config["Save_Dir_On_Cart"], os.path.splitext(Short_Save_Filename)[0] + Utils.Get_Save_Extension().upper()) if os.path.isfile(Short_Save_Filename): FileDate = "%s %s" % ( win32api.GetDateFormat( win32api.GetSystemDefaultLCID(), 0, time.localtime( os.path.getmtime( Short_Save_Filename))).lower(), win32api.GetTimeFormat( win32api.GetSystemDefaultLCID(), 0, time.localtime( os.path.getmtime(Short_Save_Filename)))) Save = ["Yes", Short_Save_Filename, FileDate] break except: pass return Save
def rawTimeFunc(dt, minutes=True, seconds=False): if seconds: # You can't include seconds without minutes flags = 0x0 else: if minutes: flags = 0x2 else: flags = 0x1 return operating_system.decodeSystemString(win32api.GetTimeFormat(0x400, flags, None if dt is None else pywintypes.Time(dt), None))
def TestTimeFormat(self): win32api.GetTimeFormat(0, 0, None) win32api.GetTimeFormat(0, 0, 0) win32api.GetTimeFormat(0, 0, datetime.datetime.now()) win32api.GetTimeFormat(0, 0, time.time())
def __LocalInit(self): self.SetSize(Config.Config["Statistics_Size"]) if Config.Config["Statistics_Position"][0] == -1: self.CentreOnScreen() else: self.SetPosition(Config.Config["Statistics_Position"]) self.Bind(wx.EVT_SIZE, self.On_Window_Size) self.Bind(wx.EVT_MOVE, self.On_Window_Move) SummaryText = _("Application Information") + " :\n\n" SummaryText += "RToolDS Version : v%s\n" % Config.Version_String SummaryText += _("Scene Dat File Version") + " : %04d\n" % ( MyROMS.Master_List_XML_Version) # SummaryText += "Scene Dat File Date : %s\n\n" % (time.strftime( "%d/%m/%Y %I:%M:%S %p", time.localtime( os.path.getmtime ( Config.Config ["AllXMLFilename"] ) ) ).lower()) try: SummaryText += _("Scene Dat File Date") + " : %s %s\n\n" % ( win32api.GetDateFormat( win32api.GetSystemDefaultLCID(), 0, time.localtime( os.path.getmtime( Config.Config["Master_XML_File"]))).lower(), win32api.GetTimeFormat( win32api.GetSystemDefaultLCID(), 0, time.localtime( os.path.getmtime(Config.Config["Master_XML_File"])))) except: SummaryText += _("Scene Dat File Date") + " : " + _( "Not Availabe") + "\n\n" SummaryText += _("Official ROM Information") + " :\n\n" self.Missing_Ctrl.InsertColumn(0, "ROM Name") self.MissingXXXX_Ctrl.InsertColumn(0, "ROM Name") XXXX = [] Size = 0 AllXXXX = 0 UnknownCount = 0 Current_Count = 0 MyROMS.Process_All = True for ROM in MyROMS: if ROM.Found: Current_Count += 1 if ROM.Comment[0].upper() == "U": UnknownCount += 1 continue if ROM.Comment.upper() == "XXXX": AllXXXX += 1 try: tmpROM = MyROMS.Lookup_ROM_CRC(ROM.ROM_CRC) Size += os.path.getsize(tmpROM.Archive_File) except: if ROM.Comment.upper() == "XXXX": XXXX.append(ROM.Comment + " - " + ROM.Title) else: self.Missing_Ctrl.InsertStringItem( sys.maxint, ROM.Comment + " - " + ROM.Title) MyROMS.Process_All = False XXXX.sort() for Item in XXXX: self.MissingXXXX_Ctrl.InsertStringItem(sys.maxint, Item) MyXXXX = AllXXXX - len(XXXX) SummaryText += _("Total ROMs Released") + " : %d\n" % ( MyROMS.Master_List_Count - UnknownCount) SummaryText += _("Game ROMs") + " : %d\n" % (MyROMS.Master_List_Count - AllXXXX - UnknownCount) SummaryText += _("Demo ROMs") + " (XXXX) : %d\n\n" % AllXXXX SummaryText += _("My Library") + " :\n\n" SummaryText += _("Total Official ROMs") + " : %d\n" % (Current_Count - UnknownCount) SummaryText += _("Official Game ROMs") + " : %d\n" % ( Current_Count - UnknownCount - MyXXXX) SummaryText += _("Official Demo ROMs") + " : %d\n" % (MyXXXX) SummaryText += _("Unknown ROMs") + " : %d\n\n" % (UnknownCount) SummaryText += _( "Official Missing ROMs : %d of which %d are Demo (XXXX) ROMs") % ( MyROMS.Master_List_Count - Current_Count, len(XXXX)) + "\n\n" SummaryText += _( "ROM Library Size") + " : %s" % (Utils.Format_Normal_Size(Size)) self.Summary_Text.AppendText(SummaryText) self.Statistics_Text.AppendText( _("ROMs In My Collection") + "\n\n" + _("ROMs by Region") + " :\n\n") Temp = {} for Key in Config.Config["Locations"].keys(): if Key != 255: Temp[Key] = 0 MyROMS.Process_All = True for ROM in MyROMS: if ROM.Found: try: Temp[ROM.Location] = Temp[ROM.Location] + 1 except: pass MyROMS.Process_All = False for Key in Temp.keys(): if Temp[Key] != 0: self.Statistics_Text.AppendText( "%s : %d\n" % (Config.Config["Locations"][Key], Temp[Key])) self.Statistics_Text.AppendText("\n" + _("ROMs by Language") + " :\n\n") Temp = {} for Key in Config.Config["Languages"].keys(): if Key != 0: Temp[Key] = 0 MyROMS.Process_All = True for ROM in MyROMS: if ROM.Found: try: if ROM.Language == 0: Temp[-1] += 1 else: for t in Temp.keys(): if t & ROM.Language and t != -1: Temp[t] = Temp[t] + 1 except: pass MyROMS.Process_All = False for Key in Temp.keys(): if Temp[Key] != 0: self.Statistics_Text.AppendText( "%s : %d\n" % (Config.Config["Languages"][Key], Temp[Key])) self.Statistics_Text.AppendText("\n" + _("ROMs by Genre") + " :\n") Temp = {} for Key in MyROMS.Genres: Temp[Key] = 0 Temp["Unknown"] = 0 MyROMS.Process_All = True for ROM in MyROMS: if ROM.Found: try: Temp[ROM.Genre] = Temp[ROM.Genre] + 1 except: pass MyROMS.Process_All = False unknown = Temp["Unknown"] del Temp["Unknown"] for Key in sorted(Temp.keys()): if Temp[Key] != 0: self.Statistics_Text.AppendText("\n%s : %d" % (Key, Temp[Key])) if unknown > 0: self.Statistics_Text.AppendText("\n%s : %d" % ("Unknown", unknown))