public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-catalyst] [PATCH] lint: avoid redefining builtins
@ 2015-10-06  4:23 Mike Frysinger
  2015-10-06  6:10 ` Brian Dolbec
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2015-10-06  4:23 UTC (permalink / raw
  To: gentoo-catalyst

It can be confusing to try and use builtins like str() when code is
also declaring variables named "str".  Avoid doing that everywhere.
---
 catalyst/base/genbase.py | 34 ++++++++++++++++++----------------
 catalyst/support.py      | 10 +++++-----
 targets/stage1/build.py  |  8 ++++----
 3 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/catalyst/base/genbase.py b/catalyst/base/genbase.py
index c05b36d..a163638 100644
--- a/catalyst/base/genbase.py
+++ b/catalyst/base/genbase.py
@@ -11,48 +11,50 @@ class GenBase(object):
 		self.settings = myspec
 
 
-	def gen_contents_file(self,file):
-		if os.path.exists(file+".CONTENTS"):
-			os.remove(file+".CONTENTS")
+	def gen_contents_file(self, path):
+		contents = path + ".CONTENTS"
+		if os.path.exists(contents):
+			os.remove(contents)
 		if "contents" in self.settings:
 			contents_map = self.settings["contents_map"]
-			if os.path.exists(file):
-				myf=open(file+".CONTENTS","w")
+			if os.path.exists(path):
+				myf = open(contents, "w")
 				keys={}
 				for i in self.settings["contents"].split():
 					keys[i]=1
 					array=keys.keys()
 					array.sort()
 				for j in array:
-					contents = contents_map.contents(file, j,
+					contents = contents_map.contents(path, j,
 						verbose="VERBOSE" in self.settings)
 					if contents:
 						myf.write(contents)
 				myf.close()
 
-	def gen_digest_file(self,file):
-		if os.path.exists(file+".DIGESTS"):
-			os.remove(file+".DIGESTS")
+	def gen_digest_file(self, path):
+		digests = path + ".DIGESTS"
+		if os.path.exists(digests):
+			os.remove(digests)
 		if "digests" in self.settings:
 			hash_map = self.settings["hash_map"]
-			if os.path.exists(file):
-				myf=open(file+".DIGESTS","w")
+			if os.path.exists(path):
+				myf=open(digests, "w")
 				keys={}
 				for i in self.settings["digests"].split():
 					keys[i]=1
 					array=keys.keys()
 					array.sort()
-				for f in [file, file+'.CONTENTS']:
+				for f in [path, path + '.CONTENTS']:
 					if os.path.exists(f):
 						if "all" in array:
 							for k in list(hash_map.hash_map):
-								hash = hash_map.generate_hash(f,hash_=k,
+								digest = hash_map.generate_hash(f,hash_=k,
 									verbose = "VERBOSE" in self.settings)
-								myf.write(hash)
+								myf.write(digest)
 						else:
 							for j in array:
-								hash = hash_map.generate_hash(f,hash_=j,
+								digest = hash_map.generate_hash(f,hash_=j,
 									verbose = "VERBOSE" in self.settings)
-								myf.write(hash)
+								myf.write(digest)
 				myf.close()
 
diff --git a/catalyst/support.py b/catalyst/support.py
index 1e3eeef..90c59eb 100644
--- a/catalyst/support.py
+++ b/catalyst/support.py
@@ -34,23 +34,23 @@ spawned_pids = []
 
 # a function to turn a string of non-printable characters
 # into a string of hex characters
-def hexify(str):
+def hexify(s):
 	hexStr = string.hexdigits
 	r = ''
-	for ch in str:
+	for ch in s:
 		i = ord(ch)
 		r = r + hexStr[(i >> 4) & 0xF] + hexStr[i & 0xF]
 	return r
 
 
-def read_from_clst(file):
+def read_from_clst(path):
 	line = ''
 	myline = ''
 	try:
-		myf=open(file,"r")
+		myf = open(path, "r")
 	except:
 		return -1
-		#raise CatalystError("Could not open file "+file)
+		#raise CatalystError("Could not open file " + path)
 	for line in myf.readlines():
 		#line = line.replace("\n", "") # drop newline
 		myline = myline + line
diff --git a/targets/stage1/build.py b/targets/stage1/build.py
index db6a93f..4143359 100755
--- a/targets/stage1/build.py
+++ b/targets/stage1/build.py
@@ -8,14 +8,14 @@ import portage
 # wrap it here to take care of the different
 # ways portage handles stacked profiles
 # last case is for portage-2.1_pre*
-def scan_profile(file):
+def scan_profile(path):
 	if "grab_stacked" in dir(portage):
-		return portage.grab_stacked(file, portage.settings.profiles, portage.grabfile, incremental_lines=1)
+		return portage.grab_stacked(path, portage.settings.profiles, portage.grabfile, incremental_lines=1)
 	else:
 		if "grab_multiple" in dir(portage):
-			return portage.stack_lists( portage.grab_multiple(file, portage.settings.profiles, portage.grabfile), incremental=1)
+			return portage.stack_lists( portage.grab_multiple(path, portage.settings.profiles, portage.grabfile), incremental=1)
 		else:
-			return portage.stack_lists( [portage.grabfile_package(os.path.join(x, file)) for x in portage.settings.profiles], incremental=1)
+			return portage.stack_lists( [portage.grabfile_package(os.path.join(x, path)) for x in portage.settings.profiles], incremental=1)
 
 # loaded the stacked packages / packages.build files
 pkgs = scan_profile("packages")
-- 
2.5.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-catalyst] [PATCH] lint: avoid redefining builtins
  2015-10-06  4:23 [gentoo-catalyst] [PATCH] lint: avoid redefining builtins Mike Frysinger
@ 2015-10-06  6:10 ` Brian Dolbec
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2015-10-06  6:10 UTC (permalink / raw
  To: gentoo-catalyst

On Tue,  6 Oct 2015 00:23:18 -0400
Mike Frysinger <vapier@gentoo.org> wrote:

> It can be confusing to try and use builtins like str() when code is
> also declaring variables named "str".  Avoid doing that everywhere.
> ---
>  catalyst/base/genbase.py | 34 ++++++++++++++++++----------------
>  catalyst/support.py      | 10 +++++-----
>  targets/stage1/build.py  |  8 ++++----
>  3 files changed, 27 insertions(+), 25 deletions(-)
> 
> diff --git a/catalyst/base/genbase.py b/catalyst/base/genbase.py
> index c05b36d..a163638 100644
> --- a/catalyst/base/genbase.py
> +++ b/catalyst/base/genbase.py
> @@ -11,48 +11,50 @@ class GenBase(object):
>  		self.settings = myspec
>  
>  
> -	def gen_contents_file(self,file):
> -		if os.path.exists(file+".CONTENTS"):
> -			os.remove(file+".CONTENTS")
> +	def gen_contents_file(self, path):
> +		contents = path + ".CONTENTS"
> +		if os.path.exists(contents):
> +			os.remove(contents)
>  		if "contents" in self.settings:
>  			contents_map = self.settings["contents_map"]
> -			if os.path.exists(file):
> -				myf=open(file+".CONTENTS","w")
> +			if os.path.exists(path):
> +				myf = open(contents, "w")
>  				keys={}
>  				for i in
> self.settings["contents"].split(): keys[i]=1
>  					array=keys.keys()
>  					array.sort()
>  				for j in array:
> -					contents =
> contents_map.contents(file, j,
> +					contents =
> contents_map.contents(path, j, verbose="VERBOSE" in self.settings)
>  					if contents:
>  						myf.write(contents)
>  				myf.close()
>  
> -	def gen_digest_file(self,file):
> -		if os.path.exists(file+".DIGESTS"):
> -			os.remove(file+".DIGESTS")
> +	def gen_digest_file(self, path):
> +		digests = path + ".DIGESTS"
> +		if os.path.exists(digests):
> +			os.remove(digests)
>  		if "digests" in self.settings:
>  			hash_map = self.settings["hash_map"]
> -			if os.path.exists(file):
> -				myf=open(file+".DIGESTS","w")
> +			if os.path.exists(path):
> +				myf=open(digests, "w")
>  				keys={}
>  				for i in
> self.settings["digests"].split(): keys[i]=1
>  					array=keys.keys()
>  					array.sort()
> -				for f in [file, file+'.CONTENTS']:
> +				for f in [path, path + '.CONTENTS']:
>  					if os.path.exists(f):
>  						if "all" in array:
>  							for k in
> list(hash_map.hash_map):
> -								hash
> = hash_map.generate_hash(f,hash_=k,
> +
> digest = hash_map.generate_hash(f,hash_=k, verbose = "VERBOSE" in
> self.settings)
> -
> myf.write(hash)
> +
> myf.write(digest) else:
>  							for j in
> array:
> -								hash
> = hash_map.generate_hash(f,hash_=j,
> +
> digest = hash_map.generate_hash(f,hash_=j, verbose = "VERBOSE" in
> self.settings)
> -
> myf.write(hash)
> +
> myf.write(digest) myf.close()
>  
> diff --git a/catalyst/support.py b/catalyst/support.py
> index 1e3eeef..90c59eb 100644
> --- a/catalyst/support.py
> +++ b/catalyst/support.py
> @@ -34,23 +34,23 @@ spawned_pids = []
>  
>  # a function to turn a string of non-printable characters
>  # into a string of hex characters
> -def hexify(str):
> +def hexify(s):
>  	hexStr = string.hexdigits
>  	r = ''
> -	for ch in str:
> +	for ch in s:
>  		i = ord(ch)
>  		r = r + hexStr[(i >> 4) & 0xF] + hexStr[i & 0xF]
>  	return r
>  
>  
> -def read_from_clst(file):
> +def read_from_clst(path):
>  	line = ''
>  	myline = ''
>  	try:
> -		myf=open(file,"r")
> +		myf = open(path, "r")
>  	except:
>  		return -1
> -		#raise CatalystError("Could not open file "+file)
> +		#raise CatalystError("Could not open file " + path)
>  	for line in myf.readlines():
>  		#line = line.replace("\n", "") # drop newline
>  		myline = myline + line
> diff --git a/targets/stage1/build.py b/targets/stage1/build.py
> index db6a93f..4143359 100755
> --- a/targets/stage1/build.py
> +++ b/targets/stage1/build.py
> @@ -8,14 +8,14 @@ import portage
>  # wrap it here to take care of the different
>  # ways portage handles stacked profiles
>  # last case is for portage-2.1_pre*
> -def scan_profile(file):
> +def scan_profile(path):
>  	if "grab_stacked" in dir(portage):
> -		return portage.grab_stacked(file,
> portage.settings.profiles, portage.grabfile, incremental_lines=1)
> +		return portage.grab_stacked(path,
> portage.settings.profiles, portage.grabfile, incremental_lines=1)
> else: if "grab_multiple" in dir(portage):
> -			return
> portage.stack_lists( portage.grab_multiple(file,
> portage.settings.profiles, portage.grabfile), incremental=1)
> +			return
> portage.stack_lists( portage.grab_multiple(path,
> portage.settings.profiles, portage.grabfile), incremental=1) else:
> -			return
> portage.stack_lists( [portage.grabfile_package(os.path.join(x, file))
> for x in portage.settings.profiles], incremental=1)
> +			return
> portage.stack_lists( [portage.grabfile_package(os.path.join(x, path))
> for x in portage.settings.profiles], incremental=1) # loaded the
> stacked packages / packages.build files pkgs =
> scan_profile("packages")


looks good, 

-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-06  6:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-06  4:23 [gentoo-catalyst] [PATCH] lint: avoid redefining builtins Mike Frysinger
2015-10-06  6:10 ` Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox