Skip to content

Commit 01296ed

Browse files
committed
added docstrings
1 parent fbb7f99 commit 01296ed

File tree

10 files changed

+224
-76
lines changed

10 files changed

+224
-76
lines changed

ee/core/apt_repo.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ def __init__(self):
1212
pass
1313

1414
def add(self, repo_url=None, ppa=None):
15+
"""
16+
This function used to add apt repositories and or ppa's
17+
If repo_url is provided adds repo file to
18+
/etc/apt/sources.list.d/
19+
If ppa is provided add apt-repository using
20+
add-apt-repository
21+
command.
22+
"""
1523

1624
if repo_url is not None:
1725
repo_file_path = ("/etc/apt/sources.list.d/"
@@ -43,12 +51,23 @@ def add(self, repo_url=None, ppa=None):
4351
"'{ppa_name}'"
4452
.format(ppa_name=ppa))
4553

46-
def remove(self, repo_url=None):
54+
def remove(self, ppa=None):
55+
"""
56+
This function used to remove ppa's
57+
If ppa is provided adds repo file to
58+
/etc/apt/sources.list.d/
59+
command.
60+
"""
4761
EEShellExec.cmd_exec(self, "add-apt-repository -y "
4862
"--remove '{ppa_name}'"
4963
.format(ppa_name=repo_url))
5064

5165
def add_key(self, keyids, keyserver=None):
66+
"""
67+
This function adds imports repository keys from keyserver.
68+
default keyserver is hkp://keys.gnupg.net
69+
user can provide other keyserver with keyserver="hkp://xyz"
70+
"""
5271
if keyserver is None:
5372
EEShellExec.cmd_exec(self, "gpg --keyserver {serv}"
5473
.format(serv=(keyserver or

ee/core/aptget.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class EEAptGet():
1010
"""Generic apt-get intialisation"""
1111

1212
def update(self):
13+
"""
14+
Similar to `apt-get upgrade`
15+
"""
1316
try:
1417
apt_cache = apt.cache.Cache()
1518
apt_cache.update()
@@ -22,6 +25,9 @@ def update(self):
2225
Log.error(self, 'AttributeError: ' + str(e))
2326

2427
def dist_upgrade():
28+
"""
29+
Similar to `apt-get upgrade`
30+
"""
2531
apt_cache = apt.cache.Cache()
2632
apt_cache.update()
2733
apt_cache.open(None)
@@ -33,7 +39,9 @@ def dist_upgrade():
3339
return success
3440

3541
def install(self, packages):
36-
"""Installation of packages"""
42+
"""
43+
Similar to `apt-get install`
44+
"""
3745
apt_pkg.init()
3846
# #apt_pkg.PkgSystemLock()
3947
global apt_cache
@@ -79,6 +87,10 @@ def install_package(self, package_name):
7987
continue
8088

8189
def remove(self, packages, auto=False, purge=False):
90+
"""
91+
Similar to `apt-get remove/purge`
92+
purge packages if purge=True
93+
"""
8294
apt_pkg.init()
8395
# apt_pkg.PkgSystemLock()
8496
global apt_cache
@@ -122,13 +134,19 @@ def remove_package(self, package_name, purge=False):
122134
continue
123135

124136
def auto_clean(self):
137+
"""
138+
Similar to `apt-get autoclean`
139+
"""
125140
try:
126141
apt_get.autoclean("-y")
127142
except ErrorReturnCode as e:
128143
Log.debug(self, "{0}".format(e))
129144
Log.error(self, "Unable to apt-get autoclean")
130145

131146
def auto_remove(self):
147+
"""
148+
Similar to `apt-get autoremove`
149+
"""
132150
try:
133151
Log.debug(self, "Running apt-get autoremove")
134152
apt_get.autoremove("-y")
@@ -137,6 +155,10 @@ def auto_remove(self):
137155
Log.error(self, "Unable to apt-get autoremove")
138156

139157
def is_installed(self, package_name):
158+
"""
159+
Checks if package is available in cache and is installed or not
160+
returns True if installed otherwise returns False
161+
"""
140162
apt_cache = apt.cache.Cache()
141163
apt_cache.open()
142164
if (package_name.strip() in apt_cache and

ee/core/database.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414

1515
def init_db():
16+
"""
17+
Initializes and creates all tables from models into the database
18+
"""
1619
# import all modules here that might define models so that
1720
# they will be registered properly on the metadata. Otherwise
1821
# you will have to import them first before calling init_db()

ee/core/domainvalidate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44

55
def ValidateDomain(url):
6+
"""
7+
This function returns domain name removing http:// and https://
8+
returns domain name only with or without www as user provided.
9+
"""
610

711
# Check if http:// or https:// present remove it if present
812
domain_name = url.split('/')

ee/core/fileutils.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111

1212
class EEFileUtils():
13-
"""Method to operate on files"""
13+
"""Utilities to operate on files"""
1414
def __init__():
1515
pass
1616

1717
def remove(self, filelist):
18+
"""remove files from given path"""
1819
for file in filelist:
1920
if os.path.isfile(file):
2021
Log.info(self, "Removing {0:65}".format(file), end=' ')
@@ -33,6 +34,10 @@ def remove(self, filelist):
3334
Log.error(self, 'Unable to Remove file ')
3435

3536
def create_symlink(self, paths, errormsg=''):
37+
"""
38+
Create symbolic links provided in list with first as source
39+
and second as destination
40+
"""
3641
src = paths[0]
3742
dst = paths[1]
3843
if not os.path.islink(dst):
@@ -45,13 +50,21 @@ def create_symlink(self, paths, errormsg=''):
4550
Log.debug(self, "Destination: {0} exists".format(dst))
4651

4752
def remove_symlink(self, filepath):
53+
"""
54+
Removes symbolic link for the path provided with filepath
55+
"""
4856
try:
4957
os.unlink(filepath)
5058
except Exception as e:
5159
Log.debug(self, "{0}".format(e))
5260
Log.error(self, "Unable to reomove symbolic link ...\n")
5361

5462
def copyfile(self, src, dest):
63+
"""
64+
Copies files:
65+
src : source path
66+
dest : destination path
67+
"""
5568
try:
5669
shutil.copy2(src, dest)
5770
except shutil.Error as e:
@@ -64,6 +77,12 @@ def copyfile(self, src, dest):
6477
.fromat(src, dest))
6578

6679
def searchreplace(self, fnm, sstr, rstr):
80+
"""
81+
Search replace strings in file
82+
fnm : filename
83+
sstr: search string
84+
rstr: replace string
85+
"""
6786
try:
6887
for line in fileinput.input(fnm, inplace=True):
6988
print(line.replace(sstr, rstr), end='')
@@ -74,6 +93,11 @@ def searchreplace(self, fnm, sstr, rstr):
7493
.format(fnm, sstr, rstr))
7594

7695
def mvfile(self, src, dst):
96+
"""
97+
Moves file from source path to destination path
98+
src : source path
99+
dst : Destination path
100+
"""
77101
try:
78102
Log.debug(self, "Moving file from {0} to {1}".format(src, dst))
79103
shutil.move(src, dst)
@@ -83,13 +107,25 @@ def mvfile(self, src, dst):
83107
.format(src, dst))
84108

85109
def chdir(self, path):
110+
"""
111+
Change Directory to path specified
112+
Path : path for destination directory
113+
"""
86114
try:
87115
os.chdir(path)
88116
except OSError as e:
89117
Log.debug(self, "{err}".format(err=e.strerror))
90118
Log.error(self, 'Unable to Change Directory {0}'.format(path))
91119

92120
def chown(self, path, user, group, recursive=False):
121+
"""
122+
Change Owner for files
123+
change owner for file with path specified
124+
user: username of owner
125+
group: group of owner
126+
recursive: if recursive is True change owner for all
127+
files in directory
128+
"""
93129
userid = pwd.getpwnam(user)[2]
94130
groupid = pwd.getpwnam(user)[3]
95131
try:
@@ -111,6 +147,12 @@ def chown(self, path, user, group, recursive=False):
111147
Log.error(self, "Unable to change owner : {0} ".format(path))
112148

113149
def chmod(self, path, perm, recursive=False):
150+
"""
151+
Changes Permission for files
152+
path : file path permission to be changed
153+
perm : permissions to be given
154+
recursive: change permission recursively for all files
155+
"""
114156
try:
115157
if recursive:
116158
for root, dirs, files in os.walk(path):
@@ -125,13 +167,21 @@ def chmod(self, path, perm, recursive=False):
125167
Log.error(self, "Unable to change owner : {0}".format(path))
126168

127169
def mkdir(self, path):
170+
"""
171+
create directories.
172+
path : path for directory to be created
173+
Similar to `mkdir -p`
174+
"""
128175
try:
129176
os.makedirs(path)
130177
except OSError as e:
131178
Log.debug(self, "{0}".format(e.strerror))
132179
Log.error(self, "Unable to create directory {0} ".format(path))
133180

134181
def isexist(self, path):
182+
"""
183+
Check if file exist on given path
184+
"""
135185
try:
136186
if os.path.exists(path):
137187
return (True)
@@ -142,6 +192,9 @@ def isexist(self, path):
142192
Log.error(self, "Unable to check path {0}".format(path))
143193

144194
def grep(self, fnm, sstr):
195+
"""
196+
Searches for string in file and returns the matched line.
197+
"""
145198
try:
146199
for line in open(fnm):
147200
if sstr in line:
@@ -152,6 +205,9 @@ def grep(self, fnm, sstr):
152205
.format(sstr, fnm))
153206

154207
def rm(self, path):
208+
"""
209+
Remove files
210+
"""
155211
if EEFileUtils.isexist(self, path):
156212
try:
157213
if os.path.isdir(path):

ee/core/git.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ def ___init__():
1111
pass
1212

1313
def add(self, paths, msg="Intializating"):
14+
"""
15+
Initializes Directory as repository if not already git repo.
16+
and adds uncommited changes automatically
17+
"""
1418
for path in paths:
1519
global git
1620
git = git.bake("--git-dir={0}/.git".format(path),
@@ -40,6 +44,9 @@ def add(self, paths, msg="Intializating"):
4044
Log.debug(self, "EEGit: Path {0} not present".format(path))
4145

4246
def checkfilestatus(self, repo, filepath):
47+
"""
48+
Checks status of file, If its tracked or untracked.
49+
"""
4350
global git
4451
git = git.bake("--git-dir={0}/.git".format(repo),
4552
"--work-tree={0}".format(repo))

ee/core/logging.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33

44
class Log:
5+
"""
6+
Logs messages with colors for different messages
7+
according to functions
8+
"""
59
HEADER = '\033[95m'
610
OKBLUE = '\033[94m'
711
OKGREEN = '\033[92m'
@@ -12,16 +16,28 @@ class Log:
1216
UNDERLINE = '\033[4m'
1317

1418
def error(self, msg):
19+
"""
20+
Logs error into log file
21+
"""
1522
print(Log.FAIL + msg + Log.ENDC)
1623
self.app.log.error(Log.FAIL + msg + Log.ENDC)
1724
self.app.close(1)
1825

1926
def info(self, msg, end='\n'):
27+
"""
28+
Logs info messages into log file
29+
"""
2030
print(Log.OKBLUE + msg + Log.ENDC, end=end)
2131
self.app.log.info(Log.OKBLUE + msg + Log.ENDC)
2232

2333
def warn(self, msg):
34+
"""
35+
Logs warning into log file
36+
"""
2437
self.app.log.warn(Log.BOLD + msg + Log.ENDC)
2538

2639
def debug(self, msg):
40+
"""
41+
Logs debug messages into log file
42+
"""
2743
self.app.log.debug(Log.HEADER + msg + Log.ENDC)

ee/core/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
class SiteDB(Base):
6+
"""
7+
Databse model for site table
8+
"""
69
__tablename__ = 'sites'
710
id = Column(Integer, primary_key=True)
811
sitename = Column(String, unique=True)

0 commit comments

Comments
 (0)