commit: cd8a1249340c70ea0fce5fd9a1fb7f02a3dcf511
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Sep 12 18:17:49 2015 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Sep 12 21:01:00 2015 +0000
URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=cd8a1249
grs/HashIt.py: make into inheritable class.
grs/{TarIt.py => HashIt.py} | 46 +++++++++---------------------------------
grs/TarIt.py | 49 ++++++++-------------------------------------
grs/__init__.py | 3 ++-
3 files changed, 20 insertions(+), 78 deletions(-)
diff --git a/grs/TarIt.py b/grs/HashIt.py
similarity index 51%
copy from grs/TarIt.py
copy to grs/HashIt.py
index b63258b..817364a 100644
--- a/grs/TarIt.py
+++ b/grs/HashIt.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# TarIt.py: this file is part of the GRS suite
+# HashIt.py: this file is part of the GRS suite
# Copyright (C) 2015 Anthony G. Basile
#
# This program is free software: you can redistribute it and/or modify
@@ -17,39 +17,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
-from datetime import datetime
-from grs.Constants import CONST
from grs.Execute import Execute
-class TarIt():
- """ Create a tarball of the system and generate the hash values. """
-
- def __init__(self, name, portage_configroot = CONST.PORTAGE_CONFIGROOT,
logfile = CONST.LOGFILE):
- self.portage_configroot = portage_configroot
- self.logfile = logfile
- # Prepare a year, month and day for a tarball name timestamp.
- self.year = str(datetime.now().year).zfill(4)
- self.month = str(datetime.now().month).zfill(2)
- self.day = str(datetime.now().day).zfill(2)
- self.tarball_name = '%s-%s%s%s.tar.xz' % (name, self.year, self.month,
self.day)
- self.digest_name = '%s.DIGESTS' % self.tarball_name
-
-
- def tarit(self, alt_name = None):
- # Create the tarball with the default name unless an alt_name is given.
- if alt_name:
- self.tarball_name = '%s-%s%s%s.tar.xz' % (alt_name, self.year,
self.month, self.day)
- self.digest_name = '%s.DIGESTS' % self.tarball_name
- # We have to cd into the system's portage configroot and then out
again.
- cwd = os.getcwd()
- os.chdir(self.portage_configroot)
- tarball_path = os.path.join('..', self.tarball_name)
- # TODO: This needs to be generalized for systems that don't support
xattrs
- xattr_opts = '--xattrs --xattrs-include=security.capability
--xattrs-include=user.pax.flags'
- cmd = 'tar %s -Jcf %s .' % (xattr_opts, tarball_path)
- Execute(cmd, timeout=None, logfile=self.logfile)
- os.chdir(cwd)
-
+class HashIt():
+ """ Create a DIGEST file for certain tarballs, or ISOs. This class must
+ be inherited by a class which sets the medium_name and digest_name,
+ else we'll get an AttributeError exception.
+ """
def hashit(self):
""" Generate various hash values. We hijack the 'logfile' which will
@@ -64,22 +38,22 @@ class TarIt():
# Note: this first cmd clobbers the contents
cmd = 'echo "# MD5 HASH"'
Execute(cmd, logfile=self.digest_name)
- cmd = 'md5sum %s' % self.tarball_name
+ cmd = 'md5sum %s' % self.medium_name
Execute(cmd, timeout=60, logfile=self.digest_name)
cmd = 'echo "# SHA1 HASH"'
Execute(cmd, logfile=self.digest_name)
- cmd = 'sha1sum %s' % self.tarball_name
+ cmd = 'sha1sum %s' % self.medium_name
Execute(cmd, timeout=60, logfile=self.digest_name)
cmd = 'echo "# SHA512 HASH"'
Execute(cmd, logfile=self.digest_name)
- cmd = 'sha512sum %s' % self.tarball_name
+ cmd = 'sha512sum %s' % self.medium_name
Execute(cmd, timeout=60, logfile=self.digest_name)
cmd = 'echo "# WHIRLPOOL HASH"'
Execute(cmd, logfile=self.digest_name)
- cmd = 'whirlpooldeep %s' % self.tarball_name
+ cmd = 'whirlpooldeep %s' % self.medium_name
Execute(cmd, timeout=60, logfile=self.digest_name)
os.chdir(cwd)
diff --git a/grs/TarIt.py b/grs/TarIt.py
index b63258b..d421cf2 100644
--- a/grs/TarIt.py
+++ b/grs/TarIt.py
@@ -20,9 +20,10 @@ import os
from datetime import datetime
from grs.Constants import CONST
from grs.Execute import Execute
+from grs.HashIt import HashIt
-class TarIt():
- """ Create a tarball of the system and generate the hash values. """
+class TarIt(HashIt):
+ """ Create a tarball of the system. """
def __init__(self, name, portage_configroot = CONST.PORTAGE_CONFIGROOT,
logfile = CONST.LOGFILE):
self.portage_configroot = portage_configroot
@@ -31,55 +32,21 @@ class TarIt():
self.year = str(datetime.now().year).zfill(4)
self.month = str(datetime.now().month).zfill(2)
self.day = str(datetime.now().day).zfill(2)
- self.tarball_name = '%s-%s%s%s.tar.xz' % (name, self.year, self.month,
self.day)
- self.digest_name = '%s.DIGESTS' % self.tarball_name
+ self.medium_name = '%s-%s%s%s.tar.xz' % (name, self.year, self.month,
self.day)
+ self.digest_name = '%s.DIGESTS' % self.medium_name
def tarit(self, alt_name = None):
# Create the tarball with the default name unless an alt_name is given.
if alt_name:
- self.tarball_name = '%s-%s%s%s.tar.xz' % (alt_name, self.year,
self.month, self.day)
- self.digest_name = '%s.DIGESTS' % self.tarball_name
+ self.medium_name = '%s-%s%s%s.tar.xz' % (alt_name, self.year,
self.month, self.day)
+ self.digest_name = '%s.DIGESTS' % self.medium_name
# We have to cd into the system's portage configroot and then out
again.
cwd = os.getcwd()
os.chdir(self.portage_configroot)
- tarball_path = os.path.join('..', self.tarball_name)
+ tarball_path = os.path.join('..', self.medium_name)
# TODO: This needs to be generalized for systems that don't support
xattrs
xattr_opts = '--xattrs --xattrs-include=security.capability
--xattrs-include=user.pax.flags'
cmd = 'tar %s -Jcf %s .' % (xattr_opts, tarball_path)
Execute(cmd, timeout=None, logfile=self.logfile)
os.chdir(cwd)
-
-
- def hashit(self):
- """ Generate various hash values. We hijack the 'logfile' which will
- actually be the file containing the hashes.
- """
- # We need to be in the parent of the system's portage configroot
because
- # that's where we created the above tarball. This should be the
workdir,
- # but its probably safer to be pedantic here.
- cwd = os.getcwd()
- os.chdir(os.path.join(self.portage_configroot, '..'))
-
- # Note: this first cmd clobbers the contents
- cmd = 'echo "# MD5 HASH"'
- Execute(cmd, logfile=self.digest_name)
- cmd = 'md5sum %s' % self.tarball_name
- Execute(cmd, timeout=60, logfile=self.digest_name)
-
- cmd = 'echo "# SHA1 HASH"'
- Execute(cmd, logfile=self.digest_name)
- cmd = 'sha1sum %s' % self.tarball_name
- Execute(cmd, timeout=60, logfile=self.digest_name)
-
- cmd = 'echo "# SHA512 HASH"'
- Execute(cmd, logfile=self.digest_name)
- cmd = 'sha512sum %s' % self.tarball_name
- Execute(cmd, timeout=60, logfile=self.digest_name)
-
- cmd = 'echo "# WHIRLPOOL HASH"'
- Execute(cmd, logfile=self.digest_name)
- cmd = 'whirlpooldeep %s' % self.tarball_name
- Execute(cmd, timeout=60, logfile=self.digest_name)
-
- os.chdir(cwd)
diff --git a/grs/__init__.py b/grs/__init__.py
index a011b2e..2ed47f7 100644
--- a/grs/__init__.py
+++ b/grs/__init__.py
@@ -16,10 +16,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from grs.TarIt import TarIt
from grs.Constants import CONST
from grs.Daemon import Daemon
from grs.Execute import Execute
+from grs.HashIt import HashIt
from grs.Interpret import Interpret
from grs.Log import Log
from grs.Kernel import Kernel
@@ -30,4 +30,5 @@ from grs.Rotator import Rotator
from grs.RunScript import RunScript
from grs.Synchronize import Synchronize
from grs.Seed import Seed
+from grs.TarIt import TarIt
from grs.WorldConf import WorldConf