* [gentoo-catalyst] [PATCH 1/4] hash_utils: convert to log module
@ 2015-10-09 19:36 Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 2/4] fileops: " Mike Frysinger
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Mike Frysinger @ 2015-10-09 19:36 UTC (permalink / raw
To: gentoo-catalyst
This has the nice side-effect of not needing the verbose param anymore,
so the prototypes & callers all get updated to stop passing that around.
---
catalyst/base/genbase.py | 6 ++----
catalyst/base/stagebase.py | 6 ++----
catalyst/hash_utils.py | 24 +++++++++---------------
catalyst/targets/stage2.py | 3 +--
4 files changed, 14 insertions(+), 25 deletions(-)
diff --git a/catalyst/base/genbase.py b/catalyst/base/genbase.py
index 32459b4..a33f924 100644
--- a/catalyst/base/genbase.py
+++ b/catalyst/base/genbase.py
@@ -48,13 +48,11 @@ class GenBase(object):
if os.path.exists(f):
if "all" in array:
for k in list(hash_map.hash_map):
- digest = hash_map.generate_hash(f,hash_=k,
- verbose=self.settings["VERBOSE"])
+ digest = hash_map.generate_hash(f, hash_=k)
myf.write(digest)
else:
for j in array:
- digest = hash_map.generate_hash(f,hash_=j,
- verbose=self.settings["VERBOSE"])
+ digest = hash_map.generate_hash(f, hash_=j)
myf.write(digest)
myf.close()
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index bffafb7..88d71ba 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -435,8 +435,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
self.settings["source_path_hash"] = \
self.settings["hash_map"].generate_hash(
self.settings["source_path"],
- hash_ = self.settings["hash_function"],
- verbose = False)
+ hash_=self.settings["hash_function"])
print "Source path set to "+self.settings["source_path"]
if os.path.isdir(self.settings["source_path"]):
print "\tIf this is not desired, remove this directory or turn off"
@@ -464,8 +463,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
self.settings["snapshot_path_hash"] = \
self.settings["hash_map"].generate_hash(
self.settings["snapshot_path"],
- hash_ = self.settings["hash_function"],
- verbose = False)
+ hash_=self.settings["hash_function"])
def set_snapcache_path(self):
self.settings["snapshot_cache_path"]=\
diff --git a/catalyst/hash_utils.py b/catalyst/hash_utils.py
index 0262422..3db61f1 100644
--- a/catalyst/hash_utils.py
+++ b/catalyst/hash_utils.py
@@ -3,6 +3,7 @@ import os
from collections import namedtuple
from subprocess import Popen, PIPE
+from catalyst import log
from catalyst.support import CatalystError
@@ -65,32 +66,28 @@ class HashMap(object):
del obj
- def generate_hash(self, file_, hash_="crc32", verbose=False):
+ def generate_hash(self, file_, hash_="crc32"):
'''Prefered method of generating a hash for the passed in file_
@param file_: the file to generate the hash for
@param hash_: the hash algorythm to use
- @param verbose: boolean
@returns the hash result
'''
try:
return getattr(self, self.hash_map[hash_].func)(
file_,
- hash_,
- verbose
- )
+ hash_)
except:
raise CatalystError("Error generating hash, is appropriate " + \
"utility installed on your system?", traceback=True)
- def calc_hash(self, file_, hash_, verbose=False):
+ def calc_hash(self, file_, hash_):
'''
Calculate the hash for "file_"
@param file_: the file to generate the hash for
@param hash_: the hash algorythm to use
- @param verbose: boolean
@returns the hash result
'''
_hash = self.hash_map[hash_]
@@ -101,36 +98,33 @@ class HashMap(object):
mylines = source.communicate()[0]
mylines=mylines[0].split()
result=mylines[0]
- if verbose:
- print _hash.id + " (%s) = %s" % (file_, result)
+ log.info('%s (%s) = %s', _hash.id, file_, result)
return result
- def calc_hash2(self, file_, hash_type, verbose=False):
+ def calc_hash2(self, file_, hash_type):
'''
Calculate the hash for "file_"
@param file_: the file to generate the hash for
@param hash_: the hash algorythm to use
- @param verbose: boolean
@returns the hash result
'''
_hash = self.hash_map[hash_type]
args = [_hash.cmd]
args.extend(_hash.args)
args.append(file_)
- #print("DEBUG: calc_hash2; args =", args)
+ log.debug('args = %r', args)
source = Popen(args, stdout=PIPE)
output = source.communicate()
lines = output[0].split('\n')
- #print("DEBUG: calc_hash2; output =", output)
+ log.debug('output = %s', output)
header = lines[0]
h_f = lines[1].split()
hash_result = h_f[0]
short_file = os.path.split(h_f[1])[1]
result = header + "\n" + hash_result + " " + short_file + "\n"
- if verbose:
- print header + " (%s) = %s" % (short_file, result)
+ log.info('%s (%s) = %s', header, short_file, result)
return result
diff --git a/catalyst/targets/stage2.py b/catalyst/targets/stage2.py
index e6965cc..786aaa4 100644
--- a/catalyst/targets/stage2.py
+++ b/catalyst/targets/stage2.py
@@ -29,8 +29,7 @@ class stage2(StageBase):
self.settings["source_path_hash"] = \
self.settings["hash_map"].generate_hash(
self.settings["source_path"],\
- hash_=self.settings["hash_function"],
- verbose=False)
+ hash_=self.settings["hash_function"])
print "Source path set to "+self.settings["source_path"]
if os.path.isdir(self.settings["source_path"]):
print "\tIf this is not desired, remove this directory or turn off seedcache in the options of catalyst.conf"
--
2.5.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-catalyst] [PATCH 2/4] fileops: convert to log module
2015-10-09 19:36 [gentoo-catalyst] [PATCH 1/4] hash_utils: convert to log module Mike Frysinger
@ 2015-10-09 19:36 ` Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 3/4] snapshot: " Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 4/4] config: " Mike Frysinger
2 siblings, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2015-10-09 19:36 UTC (permalink / raw
To: gentoo-catalyst
---
catalyst/fileops.py | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index 2aa39f6..8fb2a36 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -20,6 +20,8 @@ from stat import ST_UID, ST_GID, ST_MODE
from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs,
pjoin, listdir_files)
# pylint: enable=unused-import
+
+from catalyst import log
from catalyst.support import CatalystError
@@ -61,31 +63,31 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False):
@remove: boolean, passed through to clear_dir()
@return boolean
'''
- #print "fileops.clear_dir()"
+ log.debug('start: %s', target)
if not target:
- #print "fileops.clear_dir(), no target... returning"
+ log.debug('no target... returning')
return False
if os.path.isdir(target):
- print "Emptying directory" , target
+ log.info('Emptying directory: %s', target)
# stat the dir, delete the dir, recreate the dir and set
# the proper perms and ownership
try:
- #print "fileops.clear_dir(), os.stat()"
+ log.debug('os.stat()')
mystat=os.stat(target)
# There's no easy way to change flags recursively in python
if chg_flags and os.uname()[0] == "FreeBSD":
os.system("chflags -R noschg " + target)
- #print "fileops.clear_dir(), shutil.rmtree()"
+ log.debug('shutil.rmtree()')
shutil.rmtree(target)
if not remove:
- #print "fileops.clear_dir(), ensure_dirs()"
+ log.debug('ensure_dirs()')
ensure_dirs(target, mode=mode)
os.chown(target, mystat[ST_UID], mystat[ST_GID])
os.chmod(target, mystat[ST_MODE])
- except Exception as e:
- print CatalystError("clear_dir(); Exeption: %s" % str(e))
+ except Exception:
+ log.error('clear_dir failed', exc_info=True)
return False
else:
- print "fileops.clear_dir(), %s is not a directory" % (target)
- #print "fileops.clear_dir(), DONE, returning True"
+ log.info('clear_dir failed: %s: is not a directory', target)
+ log.debug('DONE, returning True')
return True
--
2.5.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-catalyst] [PATCH 3/4] snapshot: convert to log module
2015-10-09 19:36 [gentoo-catalyst] [PATCH 1/4] hash_utils: convert to log module Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 2/4] fileops: " Mike Frysinger
@ 2015-10-09 19:36 ` Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 4/4] config: " Mike Frysinger
2 siblings, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2015-10-09 19:36 UTC (permalink / raw
To: gentoo-catalyst
---
catalyst/targets/snapshot.py | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py
index e1ca7b7..d19f4ef 100644
--- a/catalyst/targets/snapshot.py
+++ b/catalyst/targets/snapshot.py
@@ -8,6 +8,7 @@ from stat import ST_UID, ST_GID, ST_MODE
from DeComp.compress import CompressMap
+from catalyst import log
from catalyst.support import normpath, cmd
from catalyst.base.targetbase import TargetBase
from catalyst.base.genbase import GenBase
@@ -49,8 +50,8 @@ class snapshot(TargetBase, GenBase):
success = True
self.setup()
- print "Creating Portage tree snapshot "+self.settings["version_stamp"]+\
- " from "+self.settings["portdir"]+"..."
+ log.notice('Creating Portage tree snapshot %s from %s ...',
+ self.settings['version_stamp'], self.settings['portdir'])
mytmp=self.settings["tmp_path"]
ensure_dirs(mytmp)
@@ -61,7 +62,7 @@ class snapshot(TargetBase, GenBase):
target_snapshot,
"Snapshot failure", env=self.env)
- print "Compressing Portage snapshot tarball..."
+ log.notice('Compressing Portage snapshot tarball ...')
compressor = CompressMap(self.settings["compress_definitions"],
env=self.env, default_mode=self.settings['compression_mode'])
infodict = compressor.create_infodict(
@@ -74,17 +75,17 @@ class snapshot(TargetBase, GenBase):
)
if not compressor.compress(infodict):
success = False
- print "Snapshot compression failure"
+ log.error('Snapshot compression failure')
else:
filename = '.'.join([self.settings["snapshot_path"],
compressor.extension(self.settings["compression_mode"])])
- print "COMPRESSOR success!!!! filename", filename
+ log.notice('Snapshot successfully written to %s', filename)
self.gen_contents_file(filename)
self.gen_digest_file(filename)
self.cleanup()
if success:
- print "snapshot: complete!"
+ log.info('snapshot: complete!')
return success
def kill_chroot_pids(self):
@@ -92,12 +93,12 @@ class snapshot(TargetBase, GenBase):
@staticmethod
def cleanup():
- print "Cleaning up..."
+ log.info('Cleaning up ...')
def purge(self):
myemp=self.settings["tmp_path"]
if os.path.isdir(myemp):
- print "Emptying directory",myemp
+ log.notice('Emptying directory %s', myemp)
# stat the dir, delete the dir, recreate the dir and set
# the proper perms and ownership
mystat=os.stat(myemp)
--
2.5.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-catalyst] [PATCH 4/4] config: convert to log module
2015-10-09 19:36 [gentoo-catalyst] [PATCH 1/4] hash_utils: convert to log module Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 2/4] fileops: " Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 3/4] snapshot: " Mike Frysinger
@ 2015-10-09 19:36 ` Mike Frysinger
2015-10-09 20:38 ` Brian Dolbec
2 siblings, 1 reply; 5+ messages in thread
From: Mike Frysinger @ 2015-10-09 19:36 UTC (permalink / raw
To: gentoo-catalyst
---
catalyst/config.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/catalyst/config.py b/catalyst/config.py
index ffad9b3..db81a96 100644
--- a/catalyst/config.py
+++ b/catalyst/config.py
@@ -1,5 +1,7 @@
import re
+
+from catalyst import log
from catalyst.support import CatalystError
class ParserBase(object):
@@ -98,7 +100,7 @@ class ParserBase(object):
for x in values.keys():
# Delete empty key pairs
if not values[x]:
- print "\n\tWARNING: No value set for key " + x + "...deleting"
+ log.warning('No value set for key "%s"; deleting', x)
del values[x]
self.values = values
--
2.5.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [gentoo-catalyst] [PATCH 4/4] config: convert to log module
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 4/4] config: " Mike Frysinger
@ 2015-10-09 20:38 ` Brian Dolbec
0 siblings, 0 replies; 5+ messages in thread
From: Brian Dolbec @ 2015-10-09 20:38 UTC (permalink / raw
To: gentoo-catalyst
On Fri, 9 Oct 2015 15:36:07 -0400
Mike Frysinger <vapier@gentoo.org> wrote:
> ---
> catalyst/config.py | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/catalyst/config.py b/catalyst/config.py
> index ffad9b3..db81a96 100644
> --- a/catalyst/config.py
> +++ b/catalyst/config.py
> @@ -1,5 +1,7 @@
>
> import re
> +
> +from catalyst import log
> from catalyst.support import CatalystError
>
> class ParserBase(object):
> @@ -98,7 +100,7 @@ class ParserBase(object):
> for x in values.keys():
> # Delete empty key pairs
> if not values[x]:
> - print "\n\tWARNING: No value
> set for key " + x + "...deleting"
> + log.warning('No value set
> for key "%s"; deleting', x) del values[x]
>
> self.values = values
you have a go for all 4 in this series :)
--
Brian Dolbec <dolsen>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-10-09 20:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-09 19:36 [gentoo-catalyst] [PATCH 1/4] hash_utils: convert to log module Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 2/4] fileops: " Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 3/4] snapshot: " Mike Frysinger
2015-10-09 19:36 ` [gentoo-catalyst] [PATCH 4/4] config: " Mike Frysinger
2015-10-09 20:38 ` Brian Dolbec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox