當前位置: 首頁>>代碼示例>>Python>>正文


Python archive.TarFileArchive類代碼示例

本文整理匯總了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;未經允許,請勿轉載。