From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 3C7401381F3 for ; Wed, 3 Jul 2013 22:54:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8E7A1E09C9; Wed, 3 Jul 2013 22:54:39 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DC99DE0983 for ; Wed, 3 Jul 2013 22:54:38 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E2E7B33E855 for ; Wed, 3 Jul 2013 22:54:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 5940EE5468 for ; Wed, 3 Jul 2013 22:54:35 +0000 (UTC) From: "Jauhien Piatlicki" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Jauhien Piatlicki" Message-ID: <1372892074.299f2edd32b6f026189403563f074ce48ce78e98.jauhien@gentoo> Subject: [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/ X-VCS-Repository: proj/g-sorcery X-VCS-Files: g_sorcery/fileutils.py X-VCS-Directories: g_sorcery/ X-VCS-Committer: jauhien X-VCS-Committer-Name: Jauhien Piatlicki X-VCS-Revision: 299f2edd32b6f026189403563f074ce48ce78e98 X-VCS-Branch: master Date: Wed, 3 Jul 2013 22:54:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 7423e797-440c-4c0a-a84d-6a90f5a57b77 X-Archives-Hash: 9c4c45ec47ce02fa4efd54e614a8b118 commit: 299f2edd32b6f026189403563f074ce48ce78e98 Author: Jauhien Piatlicki (jauhien) gmail com> AuthorDate: Wed Jul 3 22:54:34 2013 +0000 Commit: Jauhien Piatlicki gmail com> CommitDate: Wed Jul 3 22:54:34 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=299f2edd g_sorcery/fileutils: hiding pylint swearing --- g_sorcery/fileutils.py | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py index 37591b3..ed68f65 100644 --- a/g_sorcery/fileutils.py +++ b/g_sorcery/fileutils.py @@ -16,11 +16,15 @@ import json, os, shutil from .exceptions import FileJSONError class FileJSON(object): + """ + Class for JSON files. + """ def __init__(self, directory, name, mandatories): """ - Initialize - - mandatories -- list of mandatory keys + Args: + directory: File directory. + name: File name. + mandatories: List of requiered keys. """ self.directory = os.path.abspath(directory) self.name = name @@ -28,6 +32,9 @@ class FileJSON(object): self.mandatories = mandatories def read(self): + """ + Read JSON file. + """ if not os.path.exists(self.directory): os.makedirs(self.directory) content = {} @@ -45,6 +52,9 @@ class FileJSON(object): return content def write(self, content): + """ + Write JSON file. + """ for key in self.mandatories: if not key in content: raise FileJSONError('lack of mandatory key: ' + key) @@ -55,6 +65,17 @@ class FileJSON(object): def hash_file(name, hasher, blocksize=65536): + """ + Get a file hash. + + Args: + name: file name. + hasher: Hasher. + blocksize: Blocksize. + + Returns: + Hash value. + """ with open(name, 'rb') as f: buf = f.read(blocksize) while len(buf) > 0: @@ -63,6 +84,13 @@ def hash_file(name, hasher, blocksize=65536): return hasher.hexdigest() def copy_all(src, dst): + """ + Copy entire tree. + + Args: + src: Source. + dst: Destination. + """ for f_name in os.listdir(src): src_name = os.path.join(src, f_name) dst_name = os.path.join(dst, f_name) @@ -72,4 +100,14 @@ def copy_all(src, dst): shutil.copy2(src_name, dst_name) def wget(uri, directory): + """ + Fetch a file. + + Args: + uri: URI. + directory: Directory where file should be saved. + + Returns: + Nonzero in case of a failure. + """ return os.system('wget -P ' + directory + ' ' + uri)