本文整理汇总了Python中sos.archive.TarFileArchive类的典型用法代码示例。如果您正苦于以下问题:Python TarFileArchive类的具体用法?Python TarFileArchive怎么用?Python TarFileArchive使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TarFileArchive类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _set_archive
def _set_archive(self):
if self.opts.compression_type not in ('auto', 'zip', 'bzip2', 'gzip', 'xz'):
raise Exception("Invalid compression type specified. Options are: auto, zip, bzip2, gzip and xz")
archive_name = os.path.join(self.opts.tmp_dir,self.policy.get_archive_name())
if self.opts.compression_type == 'auto':
auto_archive = self.policy.preferred_archive_name()
self.archive = auto_archive(archive_name)
elif self.opts.compression_type == 'zip':
self.archive = ZipFileArchive(archive_name)
else:
self.archive = TarFileArchive(archive_name)
开发者ID:nigeljonez,项目名称:sosreport,代码行数:11,代码来源:sosreport.py
示例2: _set_archive
def _set_archive(self):
archive_name = os.path.join(self.tmpdir,
self.policy.get_archive_name())
if self.opts.compression_type == 'auto':
auto_archive = self.policy.get_preferred_archive()
self.archive = auto_archive(archive_name, self.tmpdir)
elif self.opts.compression_type == 'zip':
self.archive = ZipFileArchive(archive_name, self.tmpdir)
else:
self.archive = TarFileArchive(archive_name, self.tmpdir)
self.archive.set_debug(True if self.opts.debug else False)
开发者ID:goern,项目名称:sos,代码行数:11,代码来源:sosreport.py
示例3: _set_archive
def _set_archive(self):
if self.opts.compression_type not in ("auto", "zip", "bzip2", "gzip", "xz"):
raise Exception("Invalid compression type specified. Options are:" + "auto, zip, bzip2, gzip and xz")
archive_name = os.path.join(self.tmpdir, self.policy.get_archive_name())
if self.opts.compression_type == "auto":
auto_archive = self.policy.preferred_archive_name()
self.archive = auto_archive(archive_name, self.tmpdir)
elif self.opts.compression_type == "zip":
self.archive = ZipFileArchive(archive_name, self.tmpdir)
else:
self.archive = TarFileArchive(archive_name, self.tmpdir)
开发者ID:portante,项目名称:sosreport,代码行数:11,代码来源:sosreport.py
示例4: setUp
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tf = TarFileArchive('test', self.tmpdir)
开发者ID:freyes,项目名称:sos,代码行数:3,代码来源:archive_tests.py
示例5: TarFileArchiveTest
class TarFileArchiveTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tf = TarFileArchive('test', self.tmpdir)
def tearDown(self):
shutil.rmtree(self.tmpdir)
def check_for_file(self, filename):
rtf = tarfile.open(os.path.join(self.tmpdir, 'test.tar'))
rtf.getmember(filename)
rtf.close()
def test_create(self):
self.tf.finalize('auto')
self.assertTrue(os.path.exists(os.path.join(self.tmpdir,
'test.tar')))
def test_add_file(self):
self.tf.add_file('tests/ziptest')
self.tf.finalize('auto')
self.check_for_file('test/tests/ziptest')
def test_add_node_dev_null(self):
st = os.lstat('/dev/null')
dev_maj = os.major(st.st_rdev)
dev_min = os.minor(st.st_rdev)
self.tf.add_node('/dev/null', st.st_mode, os.makedev(dev_maj, dev_min))
# when the string comes from tail() output
def test_add_string_from_file(self):
self.copy_strings = []
testfile = tempfile.NamedTemporaryFile(dir=self.tmpdir, delete=False)
testfile.write(six.b("*" * 1000))
testfile.flush()
testfile.close()
self.copy_strings.append((tail(testfile.name, 100), 'string_test.txt'))
self.tf.add_string(self.copy_strings[0][0], 'tests/string_test.txt')
self.tf.finalize('auto')
# Since commit 179d9bb add_file does not support recursive directory
# addition. Disable this test for now.
# def test_add_dir(self):
# self.tf.add_file('tests/')
# self.tf.close()
#
# self.check_for_file('test/tests/ziptest')
def test_add_renamed(self):
self.tf.add_file('tests/ziptest', dest='tests/ziptest_renamed')
self.tf.finalize('auto')
self.check_for_file('test/tests/ziptest_renamed')
# Since commit 179d9bb add_file does not support recursive directory
# addition. Disable this test for now.
# def test_add_renamed_dir(self):
# self.tf.add_file('tests/', 'tests_renamed/')
# self.tf.close()
#
# self.check_for_file('test/tests_renamed/ziptest')
def test_add_string(self):
self.tf.add_string('this is content', 'tests/string_test.txt')
self.tf.finalize('auto')
self.check_for_file('test/tests/string_test.txt')
def test_get_file(self):
self.tf.add_string('this is my content', 'tests/string_test.txt')
afp = self.tf.open_file('tests/string_test.txt')
self.assertEquals('this is my content', afp.read())
def test_overwrite_file(self):
self.tf.add_string('this is my content', 'tests/string_test.txt')
self.tf.add_string('this is my new content', 'tests/string_test.txt')
afp = self.tf.open_file('tests/string_test.txt')
self.assertEquals('this is my new content', afp.read())
def test_make_link(self):
self.tf.add_file('tests/ziptest')
self.tf.add_link('tests/ziptest', 'link_name')
self.tf.finalize('auto')
self.check_for_file('test/link_name')
def test_compress(self):
self.tf.finalize("auto")
开发者ID:freyes,项目名称:sos,代码行数:94,代码来源:archive_tests.py
示例6: SoSReport
class SoSReport(object):
def __init__(self, args):
self.loaded_plugins = deque()
self.skipped_plugins = deque()
self.all_options = deque()
self.xml_report = XmlReport()
self.global_plugin_options = {}
try:
import signal
signal.signal(signal.SIGTERM, self.get_exit_handler())
except Exception:
pass # not available in java, but we don't care
self.opts = self.parse_options(args)[0]
self.tempfile_util = TempFileUtil(tmp_dir=self.opts.tmp_dir)
self._set_debug()
self._read_config()
self.policy = sos.policies.load()
self._is_root = self.policy.is_root()
self._set_directories()
def print_header(self):
self.ui_log.info("\n%s\n" % _("sosreport (version %s)" % (__version__,)))
def get_commons(self):
return {
'cmddir': self.cmddir,
'logdir': self.logdir,
'rptdir': self.rptdir,
'tmpdir': self.opts.tmp_dir,
'soslog': self.soslog,
'proflog' : self.proflog,
'policy': self.policy,
'verbosity': self.opts.verbosity,
'xmlreport': self.xml_report,
'cmdlineopts': self.opts,
'config': self.config,
'global_plugin_options': self.global_plugin_options,
}
def get_temp_file(self):
return self.tempfile_util.new()
def _set_archive(self):
if self.opts.compression_type not in ('auto', 'zip', 'bzip2', 'gzip', 'xz'):
raise Exception("Invalid compression type specified. Options are: auto, zip, bzip2, gzip and xz")
archive_name = os.path.join(self.opts.tmp_dir,self.policy.get_archive_name())
if self.opts.compression_type == 'auto':
auto_archive = self.policy.preferred_archive_name()
self.archive = auto_archive(archive_name)
elif self.opts.compression_type == 'zip':
self.archive = ZipFileArchive(archive_name)
else:
self.archive = TarFileArchive(archive_name)
def _set_directories(self):
self.cmddir = 'sos_commands'
self.logdir = 'sos_logs'
self.rptdir = 'sos_reports'
def _set_debug(self):
if self.opts.debug:
sys.excepthook = self._exception
self.raise_plugins = True
else:
self.raise_plugins = False
@staticmethod
def _exception(etype, eval_, etrace):
""" Wrap exception in debugger if not in tty """
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(etype, eval_, etrace)
else:
import traceback, pdb
# we are NOT in interactive mode, print the exception...
traceback.print_exception(etype, eval_, etrace, limit=2, file=sys.stdout)
print
# ...then start the debugger in post-mortem mode.
pdb.pm()
def _exit(self, error=0):
raise SystemExit()
# sys.exit(error)
def get_exit_handler(self):
def exit_handler(signum, frame):
self._exit()
return exit_handler
def _read_config(self):
self.config = ConfigParser.ConfigParser()
if self.opts.config_file:
config_file = self.opts.config_file
else:
config_file = '/etc/sos.conf'
#.........这里部分代码省略.........
开发者ID:nigeljonez,项目名称:sosreport,代码行数:101,代码来源:sosreport.py
示例7: SoSReport
class SoSReport(object):
"""The main sosreport class"""
def __init__(self, args):
self.loaded_plugins = deque()
self.skipped_plugins = deque()
self.all_options = deque()
self.xml_report = XmlReport()
self.global_plugin_options = {}
self.archive = None
self.tempfile_util = None
try:
import signal
signal.signal(signal.SIGTERM, self.get_exit_handler())
except Exception:
pass # not available in java, but we don't care
self.opts = SoSOptions(args)
self._set_debug()
self._read_config()
try:
self.policy = sos.policies.load()
except KeyboardInterrupt:
self._exit(0)
self._is_root = self.policy.is_root()
self.tmpdir = os.path.abspath(
self.policy.get_tmp_dir(self.opts.tmp_dir))
if not os.path.isdir(self.tmpdir) \
or not os.access(self.tmpdir, os.W_OK):
# write directly to stderr as logging is not initialised yet
sys.stderr.write("temporary directory %s " % self.tmpdir
+ "does not exist or is not writable\n")
self._exit(1)
self.tempfile_util = TempFileUtil(self.tmpdir)
self._set_directories()
def print_header(self):
self.ui_log.info("\n%s\n" % _("sosreport (version %s)" %
(__version__,)))
def get_commons(self):
return {
'cmddir': self.cmddir,
'logdir': self.logdir,
'rptdir': self.rptdir,
'tmpdir': self.tmpdir,
'soslog': self.soslog,
'policy': self.policy,
'verbosity': self.opts.verbosity,
'xmlreport': self.xml_report,
'cmdlineopts': self.opts,
'config': self.config,
'global_plugin_options': self.global_plugin_options,
}
def get_temp_file(self):
return self.tempfile_util.new()
def _set_archive(self):
archive_name = os.path.join(self.tmpdir,
self.policy.get_archive_name())
if self.opts.compression_type == 'auto':
auto_archive = self.policy.get_preferred_archive()
self.archive = auto_archive(archive_name, self.tmpdir)
elif self.opts.compression_type == 'zip':
self.archive = ZipFileArchive(archive_name, self.tmpdir)
else:
self.archive = TarFileArchive(archive_name, self.tmpdir)
self.archive.set_debug(True if self.opts.debug else False)
def _make_archive_paths(self):
self.archive.makedirs(self.cmddir, 0o755)
self.archive.makedirs(self.logdir, 0o755)
self.archive.makedirs(self.rptdir, 0o755)
def _set_directories(self):
self.cmddir = 'sos_commands'
self.logdir = 'sos_logs'
self.rptdir = 'sos_reports'
def _set_debug(self):
if self.opts.debug:
sys.excepthook = self._exception
self.raise_plugins = True
else:
self.raise_plugins = False
@staticmethod
def _exception(etype, eval_, etrace):
""" Wrap exception in debugger if not in tty """
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(etype, eval_, etrace)
else:
import pdb
#.........这里部分代码省略.........
开发者ID:goern,项目名称:sos,代码行数:101,代码来源:sosreport.py
示例8: TarFileArchiveTest
class TarFileArchiveTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tf = TarFileArchive('test', self.tmpdir)
def tearDown(self):
shutil.rmtree(self.tmpdir)
def check_for_file(self, filename):
rtf = tarfile.open(os.path.join(self.tmpdir, 'test.tar'))
rtf.getmember(filename)
rtf.close()
def test_create(self):
self.tf.finalize('auto')
self.assertTrue(os.path.exists(os.path.join(self.tmpdir,
'test.tar')))
def test_add_file(self):
self.tf.add_file('tests/ziptest')
self.tf.finalize('auto')
self.check_for_file('test/tests/ziptest')
# Since commit 179d9bb add_file does not support recursive directory
# addition. Disable this test for now.
# def test_add_dir(self):
# self.tf.add_file('tests/')
# self.tf.close()
#
# self.check_for_file('test/tests/ziptest')
def test_add_renamed(self):
self.tf.add_file('tests/ziptest', dest='tests/ziptest_renamed')
self.tf.finalize('auto')
self.check_for_file('test/tests/ziptest_renamed')
# Since commit 179d9bb add_file does not support recursive directory
# addition. Disable this test for now.
# def test_add_renamed_dir(self):
# self.tf.add_file('tests/', 'tests_renamed/')
# self.tf.close()
#
# self.check_for_file('test/tests_renamed/ziptest')
def test_add_string(self):
self.tf.add_string('this is content', 'tests/string_test.txt')
self.tf.finalize('auto')
self.check_for_file('test/tests/string_test.txt')
def test_get_file(self):
self.tf.add_string('this is my content', 'tests/string_test.txt')
afp = self.tf.open_file('tests/string_test.txt')
self.assertEquals('this is my content', afp.read())
def test_overwrite_file(self):
self.tf.add_string('this is my content', 'tests/string_test.txt')
self.tf.add_string('this is my new content', 'tests/string_test.txt')
afp = self.tf.open_file('tests/string_test.txt')
self.assertEquals('this is my new content', afp.read())
def test_make_link(self):
self.tf.add_file('tests/ziptest')
self.tf.add_link('tests/ziptest', 'link_name')
self.tf.finalize('auto')
self.check_for_file('test/link_name')
def test_compress(self):
self.tf.finalize("auto")
开发者ID:battlemidget,项目名称:sosreport,代码行数:75,代码来源:archive_tests.py
示例9: setUp
def setUp(self):
self.tf = TarFileArchive('test')
开发者ID:Nick-Harvey,项目名称:sosreport,代码行数:2,代码来源:archive_tests.py
示例10: setUp
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
enc = {'encrypt': False}
self.tf = TarFileArchive('test', self.tmpdir, Policy(), 1, enc)
开发者ID:TurboTurtle,项目名称:sos,代码行数:4,代码来源:archive_tests.py
注:本文中的sos.archive.TarFileArchive类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论