def _fileFeatures(filePath): """ From a filepath, construct a dictionary of file features. """ # pylint: disable=W0702 log_debug(3, filePath) if not filePath: raise rhnFault(17, "While looking for file: `%s'" % os.path.basename(filePath)) try: s = os.stat(filePath) except: s = None if not s: l = 0 lastModified = 0 else: l = s[stat.ST_SIZE] lastModified = s[stat.ST_MTIME] del s # Build the result hash result = {} result['name'] = os.path.basename(filePath) result['length'] = l result['path'] = filePath if lastModified: result['lastModified'] = rfc822time(lastModified) else: result['lastModified'] = None return result
def test_rfc822time_japan_locale(self): "rfc822time: Test result in ja_JP locale." test_arg = 1138371125 target = "Fri, 27 Jan 2006 14:12:05 GMT" old_locale = locale.getlocale(locale.LC_TIME) locale.setlocale(locale.LC_TIME, 'ja_JP') result = rhnLib.rfc822time(test_arg) locale.setlocale(locale.LC_TIME, old_locale) self.assertEqual(result, target, result + " != " + target)
def _set_last_modified(last_modified, extra_headers=None): log_debug(4, last_modified) if not last_modified: return None # Set a field with the name of the header transport = rhnFlags.get('outputTransportOptions') if last_modified: # Put the last-modified info too if isinstance(last_modified, (usix.IntType, usix.FloatType)): last_modified = rfc822time(last_modified) transport['Last-Modified'] = last_modified if extra_headers: for k, v in list(extra_headers.items()): transport[str(k)] = str(v) return transport
def getObsoletes(self, version): """ Returns a list of packages that obsolete other packages """ log_debug(3, self.channelName, version) # Check to see if the version they are requesting is the latest # check the validity of what the client thinks about this channel # or blow up self.__check_channel(version) obsoletes = rhnChannel.list_obsoletes(self.channelName) # Set the transport options transportOptions = rhnFlags.get('outputTransportOptions') transportOptions['Last-Modified'] = rfc822time(timestamp(version)) rhnFlags.set("compress_response", 1) return obsoletes
def listAllPackagesComplete(self, version): """ Creates and/or serves up a cached copy of all the packages for this channel including requires, obsoletes, conflicts, etc. """ log_debug(3, self.channelName, version) # Check to see if the version they are requesting is the latest # check the validity of what the client thinks about this channel # or blow up self.__check_channel(version) packages = rhnChannel.list_all_packages_complete(self.channelName) # transport options... transportOptions = rhnFlags.get('outputTransportOptions') transportOptions['Last-Modified'] = rfc822time(timestamp(version)) rhnFlags.set("compress_response", 1) return packages
def test_rfc822time_normal_float(self): "rfc822time: Simple call using a valid float argument." test_arg = 1138371125 target = "Fri, 27 Jan 2006 14:12:05 GMT" result = rhnLib.rfc822time(test_arg) self.assertEqual(result, target, result + " != " + target)
def test_rfc822time_normal_list(self): "rfc822time: Simple call using a valid list argument." test_arg = [2006, 1, 27, int(14 - TIMEZONE_SHIFT), 12, 5, 4, 27, -1] target = "Fri, 27 Jan 2006 14:12:05 GMT" result = rhnLib.rfc822time(test_arg) self.assertEqual(result, target, result + " != " + target)