曾与蒿藜同雨露,한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.终随松柏到冰霜.かつては雑草やヨモギと共に雨や露を分かち合っていたが、今では松やヒノキと共に霜や雪に耐えている。曾与蒿藜同雨露,Once sharing rain and dew with weeds and wormwood, now enduring frost and snow with pines and cypresses.终随松柏到冰霜.曾与蒿藜同雨露한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.,终随松柏到冰霜.譖セ荳手珍阯懷酔髮ィ髴イ�檎サ磯囂譚セ譟丞芦蜀ー髴�曾与蒿藜同雨露,鏇句笌钂胯棞鍚岄洦闇诧紝缁堥殢鏉炬煆鍒板啺闇�终随松柏到冰霜.曾与蒿藜同雨露,한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.终随松柏到冰霜.曾与蒿藜同雨露,终随松柏到冰霜.
#
# Smart IO class
#
# Copyright (c) 2002--2010 Red Hat, Inc.
#
# Author: Mihai Ibanescu <misa@redhat.com>
# $Id$
"""
This module implements the SmartIO class
"""
import os
from cStringIO import StringIO
class SmartIO:
"""
The SmartIO class allows one to put a cap on the memory consumption.
StringIO objects are very fast, because they are stored in memory, but
if they are too big the memory footprint becomes noticeable.
The write method of a SmartIO determines if the data that is to be added
to the (initially) StrintIO object does not exceed a certain threshold; if
it does, it switches the storage to a temporary disk file
"""
def __init__(self, max_mem_size=16384, force_mem=0):
self._max_mem_size = max_mem_size
self._io = StringIO()
# self._fixed is a flag to show if we're supposed to consider moving
# the StringIO object into a tempfile
# Invariant: if self._fixed == 0, we have a StringIO (if self._fixed
# is 1 and force_mem was 0, then we have a file)
if force_mem:
self._fixed = 1
else:
self._fixed = 0
def set_max_mem_size(self, max_mem_size):
self._max_mem_size = max_mem_size
def get_max_mem_size(self):
return self._max_mem_size
def write(self, data):
if not self._fixed:
# let's consider moving it to a file
if len(data) + self._io.tell() > self._max_mem_size:
# We'll overflow, change to a tempfile
tmpfile = _tempfile()
tmpfile.write(self._io.getvalue())
self._fixed = 1
self._io = tmpfile
self._io.write(data)
def __getattr__(self, name):
return getattr(self._io, name)
# Creates a temporary file and passes back its file descriptor
def _tempfile(tmpdir=None):
import tempfile
if not tmpdir:
tmpdir = getDefaultStorage()
(fd, fname) = tempfile.mkstemp(prefix="_rhn_transports-%d-" \
% os.getpid(), dir=tmpdir)
# tempfile, unlink it
os.unlink(fname)
return os.fdopen(fd, "wb+")
def getDefaultStorage():
""" Reads the default temp dir from up2date config.
if defined uses that else use /tmp. """
up2dateCfg = "/etc/sysconfig/rhn/up2date"
tmpdir = "/tmp"
try:
f = open(up2dateCfg)
except IOError:
return tmpdir
for line in f.readlines():
if line.startswith("tmpDir="):
cfgdir = line.split("=")
if len(cfgdir) > 1:
tmpdir = cfgdir[-1].strip() or tmpdir
f.close()
# if tmpdir is still not acquired, default to /tmp
return tmpdir