Skip to content

Commit 411baa6

Browse files
committed
Misc lint cleanup
Cleanup a bunch of lint issues. Still have three files with lint issues: repository_git, sourcetree, test_unit_externals_description. Testing: python2 unit tests - pass python2 clm manual testing checkout, status - ok python2 cesm manual testing checkout, status - ok python3 unit tests - 3 errors
1 parent dcb6241 commit 411baa6

11 files changed

+96
-47
lines changed

checkout_externals.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
import logging
1515
import os
1616
import os.path
17-
import re
1817
import sys
1918
import textwrap
2019
import traceback
2120

21+
from manic import read_externals_description_file, create_externals_description
22+
from manic import SourceTree
23+
from manic import check_safe_to_update_repos
24+
from manic import printlog, PPRINTER
25+
2226
if sys.hexversion < 0x02070000:
2327
print(70 * '*')
2428
print('ERROR: {0} requires python >= 2.7.x. '.format(sys.argv[0]))
@@ -27,11 +31,6 @@
2731
print(70 * '*')
2832
sys.exit(1)
2933

30-
from manic import read_externals_description_file, create_externals_description
31-
from manic import SourceTree
32-
from manic import check_safe_to_update_repos
33-
from manic import printlog, PPRINTER
34-
3534

3635
# ---------------------------------------------------------------------
3736
#
@@ -244,7 +243,7 @@ def _main(args):
244243

245244
if args.status:
246245
# user requested status-only
247-
for comp in sorted(tree_status.iterkeys()):
246+
for comp in sorted(tree_status.keys()):
248247
msg = str(tree_status[comp])
249248
printlog(msg)
250249
if args.verbose:
@@ -255,7 +254,7 @@ def _main(args):
255254
safe_to_update = check_safe_to_update_repos(tree_status, args.debug)
256255
if not safe_to_update:
257256
# print status
258-
for comp in sorted(tree_status.iterkeys()):
257+
for comp in sorted(tree_status.keys()):
259258
msg = str(tree_status[comp])
260259
printlog(msg)
261260
# exit gracefully

manic/externals_description.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,24 @@
2828
try:
2929
# python2
3030
from ConfigParser import SafeConfigParser as config_parser
31-
import ConfigParser
31+
from ConfigParser import MissingSectionHeaderError
32+
from ConfigParser import NoSectionError, NoOptionError
3233

3334
def config_string_cleaner(text):
35+
"""convert strings into unicode
36+
"""
3437
return text.decode('utf-8')
3538
except ImportError:
3639
# python3
3740
from configparser import ConfigParser as config_parser
41+
from configparser import MissingSectionHeaderError
42+
from configparser import NoSectionError, NoOptionError
3843

3944
def config_string_cleaner(text):
45+
"""Python3 already uses unicode strings, so just return the string
46+
without modification.
47+
48+
"""
4049
return text
4150

4251
from .utils import printlog, fatal_error, str_to_bool
@@ -70,7 +79,7 @@ def read_externals_description_file(root_dir, file_name):
7079
config = config_parser()
7180
config.read(file_path)
7281
externals_description = config
73-
except ConfigParser.MissingSectionHeaderError:
82+
except MissingSectionHeaderError:
7483
# not a cfg file
7584
pass
7685

@@ -115,8 +124,8 @@ def get_cfg_schema_version(model_cfg):
115124
semver_str = ''
116125
try:
117126
semver_str = model_cfg.get(DESCRIPTION_SECTION, VERSION_ITEM)
118-
except Exception:
119-
msg = ('ERROR: externals description file must have the required '
127+
except (NoSectionError, NoOptionError):
128+
msg = ('externals description file must have the required '
120129
'section: "{0}" and item "{1}"'.format(DESCRIPTION_SECTION,
121130
VERSION_ITEM))
122131
fatal_error(msg)
@@ -291,6 +300,7 @@ class ExternalsDescriptionDict(ExternalsDescription):
291300
description files for unit testing.
292301
293302
"""
303+
294304
def __init__(self, model_data):
295305
"""Parse a native dictionary into a externals description.
296306
"""
@@ -304,6 +314,7 @@ class ExternalsDescriptionConfigV1(ExternalsDescription):
304314
schema version 1.
305315
306316
"""
317+
307318
def __init__(self, model_data):
308319
"""Convert the xml into a standardized dict that can be used to
309320
construct the source objects
@@ -350,5 +361,3 @@ def list_to_dict(input_list, convert_to_lower_case=True):
350361
if item in self._source_schema[self.REPO]:
351362
self[name][self.REPO][item] = self[name][item]
352363
del self[name][item]
353-
354-

manic/externalstatus.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""ExternalStatus
2+
3+
Class to store status and state information about repositories and
4+
create a string representation.
5+
6+
"""
7+
from __future__ import absolute_import
8+
from __future__ import unicode_literals
9+
from __future__ import print_function
10+
111
from .globals import EMPTY_STR
212
from .utils import printlog
313

manic/repository_factory.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""Factory for creating and initializing the appropriate repository class
2+
"""
3+
4+
from __future__ import absolute_import
5+
from __future__ import unicode_literals
6+
from __future__ import print_function
7+
18
from .repository_git import GitRepository
29
from .repository_svn import SvnRepository
310
from .externals_description import ExternalsDescription

manic/repository_git.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""Class for interacting with git repositories
2+
"""
3+
4+
from __future__ import absolute_import
5+
from __future__ import unicode_literals
6+
from __future__ import print_function
7+
18
import os
29
import re
310

@@ -315,23 +322,7 @@ def _git_checkout(self, repo_dir_path):
315322

316323
cmd = []
317324
if self._branch:
318-
(curr_branch, _) = self._git_current_branch()
319-
ref_type = self._git_ref_type(self._branch)
320-
if ref_type == self.GIT_REF_REMOTE_BRANCH:
321-
cmd = ['git', 'checkout', '--track', 'origin/' + self._branch]
322-
elif ref_type == self.GIT_REF_LOCAL_BRANCH:
323-
if curr_branch != self._branch:
324-
if not self._git_working_dir_clean(repo_dir_path):
325-
msg = ('Working directory "{0}" not clean, '
326-
'aborting'.format(repo_dir_path))
327-
fatal_error(msg)
328-
else:
329-
cmd = ['git', 'checkout', self._branch]
330-
331-
else:
332-
msg = 'Unable to check out branch, "{0}"'.format(self._branch)
333-
fatal_error(msg)
334-
325+
cmd = self._checkout_branch_command(repo_dir_path)
335326
elif self._tag:
336327
# For now, do a hail mary and hope tag can be checked out
337328
cmd = ['git', 'checkout', self._tag]
@@ -344,6 +335,31 @@ def _git_checkout(self, repo_dir_path):
344335

345336
os.chdir(cwd)
346337

338+
def _checkout_branch_command(self, repo_dir_path):
339+
"""Construct the command for checking out the specified branch
340+
"""
341+
cmd = []
342+
(curr_branch, _) = self._git_current_branch()
343+
ref_type = self._git_ref_type(self._branch)
344+
if ref_type == self.GIT_REF_REMOTE_BRANCH:
345+
cmd = ['git', 'checkout', '--track', 'origin/' + self._branch]
346+
elif ref_type == self.GIT_REF_LOCAL_BRANCH:
347+
if curr_branch != self._branch:
348+
# FIXME(bja, 2017-11) not sure what this branch logic
349+
# is accomplishing, but it can lead to cmd being
350+
# undefined without an error. Probably not what we
351+
# want!
352+
if not self._git_working_dir_clean(repo_dir_path):
353+
msg = ('Working directory "{0}" not clean, '
354+
'aborting'.format(repo_dir_path))
355+
fatal_error(msg)
356+
else:
357+
cmd = ['git', 'checkout', self._branch]
358+
else:
359+
msg = 'Unable to check out branch, "{0}"'.format(self._branch)
360+
fatal_error(msg)
361+
return cmd
362+
347363
@staticmethod
348364
def git_status_porcelain_v1z():
349365
"""Run the git status command on the cwd and report results in the

manic/repository_svn.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""Class for interacting with svn repositories
2+
"""
3+
4+
from __future__ import absolute_import
5+
from __future__ import unicode_literals
6+
from __future__ import print_function
7+
18
import logging
29
import os
310
import re

manic/sourcetree.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _create_externals_sourcetree(self):
196196

197197
externals_root = self._repo_dir_path
198198
model_data = read_externals_description_file(externals_root,
199-
self._externals)
199+
self._externals)
200200
externals = create_externals_description(model_data)
201201
self._externals_sourcetree = SourceTree(externals_root, externals)
202202
os.chdir(cwd)
@@ -237,16 +237,16 @@ def status(self, relative_path_base='.'):
237237
for comp in load_comps:
238238
printlog('{0}, '.format(comp), end='')
239239
stat = self._all_components[comp].status()
240-
for comp in stat.keys():
240+
for name in stat.keys():
241241
# check if we need to append the relative_path_base to
242242
# the path so it will be sorted in the correct order.
243-
if not stat[comp].path.startswith(relative_path_base):
244-
stat[comp].path = os.path.join(relative_path_base,
245-
stat[comp].path)
243+
if not stat[name].path.startswith(relative_path_base):
244+
stat[name].path = os.path.join(relative_path_base,
245+
stat[name].path)
246246
# store under key = updated path, and delete the
247247
# old key.
248-
comp_stat = stat[comp]
249-
del stat[comp]
248+
comp_stat = stat[name]
249+
del stat[name]
250250
stat[comp_stat.path] = comp_stat
251251
summary.update(stat)
252252

manic/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ def str_to_bool(bool_str):
6767
Conversion should be case insensitive.
6868
"""
6969
value = None
70-
if ((bool_str.lower() == 'true') or (bool_str.lower() == 't')):
70+
str_lower = bool_str.lower()
71+
if (str_lower == 'true') or (str_lower == 't'):
7172
value = True
72-
elif bool_str.lower() == 'false' or bool_str.lower() == 'f':
73+
elif (str_lower == 'false') or (str_lower == 'f'):
7374
value = False
7475
if value is None:
7576
msg = ('ERROR: invalid boolean string value "{0}". '

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ COVERAGE_ARGS=--rcfile=.coveragerc
2222

2323
SRC = \
2424
../checkout_externals.py \
25-
../manageexternals/*.py
25+
../manic/*.py
2626

2727
EXE = ../checkout_externals.py
2828

test/test_unit_externals_description.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@
1111
from __future__ import unicode_literals
1212
from __future__ import print_function
1313

14-
import string
15-
import sys
1614
import unittest
1715

1816
try:
1917
# python2
2018
from ConfigParser import SafeConfigParser as config_parser
2119

2220
def config_string_cleaner(text):
21+
"""convert strings into unicode
22+
"""
2323
return text.decode('utf-8')
2424
except ImportError:
2525
# python3
2626
from configparser import ConfigParser as config_parser
2727

2828
def config_string_cleaner(text):
29+
"""Python3 already uses unicode strings, so just return the string
30+
without modification.
31+
32+
"""
2933
return text
3034

3135
from manic.externals_description import DESCRIPTION_SECTION, VERSION_ITEM

0 commit comments

Comments
 (0)