Skip to content

Commit 9d02636

Browse files
committed
initial cleaning
1 parent c7b0b99 commit 9d02636

File tree

10 files changed

+80
-96
lines changed

10 files changed

+80
-96
lines changed

doc/_ext/aafig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def run(self):
9292
if isinstance(image_node, nodes.system_message):
9393
return [image_node]
9494
text = '\n'.join(self.content)
95-
image_node.aafig = dict(options = aafig_options, text = text)
95+
image_node.aafig = dict(options = aafig_options, text = text)
9696
return [image_node]
9797

9898

@@ -187,7 +187,7 @@ def render_aafigure(app, text, options):
187187

188188
try:
189189
(visitor, output) = aafigure.render(text, outfn, options)
190-
output.close()
190+
output.close()
191191
except aafigure.UnsupportedFormatError, e:
192192
raise AafigError(str(e))
193193

tmuxp/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def run():
2020
tmuxp.cli.main()
2121

2222
if __name__ == '__main__':
23-
exit = run()
23+
_exit = run()
2424
if exit:
25-
sys.exit(exit)
25+
sys.exit(_exit)

tmuxp/cli.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def prompt(name, default=None):
4646
4747
"""
4848

49-
prompt = name + (default and ' [%s]' % default or '')
50-
prompt += name.endswith('?') and ' ' or ': '
49+
_prompt = name + (default and ' [%s]' % default or '')
50+
_prompt += name.endswith('?') and ' ' or ': '
5151
while True:
52-
rv = input(prompt)
52+
rv = input(_prompt)
5353
if rv:
5454
return rv
5555
if default is not None:
@@ -77,11 +77,11 @@ def prompt_bool(name, default=False, yes_choices=None, no_choices=None):
7777
else:
7878
prompt_choice = 'y/N'
7979

80-
prompt = name + ' [%s]' % prompt_choice
81-
prompt += name.endswith('?') and ' ' or ': '
80+
_prompt = name + ' [%s]' % prompt_choice
81+
_prompt += name.endswith('?') and ' ' or ': '
8282

8383
while True:
84-
rv = input(prompt)
84+
rv = input(_prompt)
8585
if not rv:
8686
return default
8787
if rv.lower() in yes_choices:
@@ -633,7 +633,7 @@ def command_convert(args):
633633

634634
if 'json' in ext:
635635
if args.answer_yes or prompt_yes_no(
636-
'convert to <%s> to yaml?' % (fullfile)
636+
'convert to <%s> to yaml?' % fullfile
637637
):
638638
configparser = kaptan.Kaptan()
639639
configparser.import_config(configfile)
@@ -642,28 +642,28 @@ def command_convert(args):
642642
'yaml', indent=2, default_flow_style=False
643643
)
644644
if args.answer_yes or prompt_yes_no(
645-
'Save config to %s?' % (newfile)
645+
'Save config to %s?' % newfile
646646
):
647647
buf = open(newfile, 'w')
648648
buf.write(newconfig)
649649
buf.close()
650-
print('New config saved to %s' % (newfile))
650+
print('New config saved to %s' % newfile)
651651
elif 'yaml' in ext:
652652
if args.answer_yes or prompt_yes_no(
653-
'convert to <%s> to json?' % (fullfile)
653+
'convert to <%s> to json?' % fullfile
654654
):
655655
configparser = kaptan.Kaptan()
656656
configparser.import_config(configfile)
657657
newfile = fullfile.replace(ext, '.json')
658658
newconfig = configparser.export('json', indent=2)
659659
print(newconfig)
660660
if args.answer_yes or prompt_yes_no(
661-
'Save config to <%s>?' % (newfile)
661+
'Save config to <%s>?' % newfile
662662
):
663663
buf = open(newfile, 'w')
664664
buf.write(newconfig)
665665
buf.close()
666-
print('New config saved to <%s>.' % (newfile))
666+
print('New config saved to <%s>.' % newfile)
667667

668668

669669
def command_attach_session(args):
@@ -898,7 +898,7 @@ def get_parser():
898898
help='''\
899899
Checks current ~/.teamocil and current directory for yaml files.
900900
'''
901-
).completer = TeamocilCompleter(allowednames=('.yml'), directories=False)
901+
).completer = TeamocilCompleter(allowednames='.yml', directories=False)
902902
import_teamocil.set_defaults(callback=command_import_teamocil)
903903

904904
import_tmuxinator = importsubparser.add_parser(
@@ -920,7 +920,7 @@ def get_parser():
920920
help='''\
921921
Checks current ~/.tmuxinator and current directory for yaml files.
922922
'''
923-
).completer = TmuxinatorCompleter(allowednames=('.yml'), directories=False)
923+
).completer = TmuxinatorCompleter(allowednames='.yml', directories=False)
924924

925925
import_tmuxinator.set_defaults(callback=command_import_tmuxinator)
926926

tmuxp/config.py

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ def validate_schema(sconf):
2828
"""
2929

3030
# verify session_name
31-
if not 'session_name' in sconf:
31+
if 'session_name' not in sconf:
3232
raise exc.ConfigError('config requires "session_name"')
3333

34-
if not 'windows' in sconf:
34+
if 'windows' not in sconf:
3535
raise exc.ConfigError('config requires list of "windows"')
3636

3737
for window in sconf['windows']:
38-
if not 'window_name' in window:
38+
if 'window_name' not in window:
3939
raise exc.ConfigError('config window is missing "window_name"')
4040

41-
if not 'panes' in window:
41+
if 'panes' not in window:
4242
raise exc.ConfigError(
4343
'config window %s requires list of panes' %
4444
window['window_name']
@@ -64,8 +64,8 @@ def is_config_file(filename, extensions=['.yml', '.yaml', '.json']):
6464

6565

6666
def in_dir(
67-
config_dir=os.path.expanduser('~/.tmuxp'),
68-
extensions=['.yml', '.yaml', '.json']
67+
config_dir=os.path.expanduser('~/.tmuxp'),
68+
extensions=['.yml', '.yaml', '.json']
6969
):
7070
"""Return a list of configs in ``config_dir``.
7171
@@ -80,7 +80,7 @@ def in_dir(
8080

8181
for filename in os.listdir(config_dir):
8282
if is_config_file(filename, extensions) and \
83-
not filename.startswith('.'):
83+
not filename.startswith('.'):
8484
configs.append(filename)
8585

8686
return configs
@@ -102,6 +102,7 @@ def in_cwd():
102102

103103
return configs
104104

105+
105106
def expandshell(_path):
106107
"""Return expanded path based on user's ``$HOME`` and ``env``.
107108
@@ -115,6 +116,7 @@ def expandshell(_path):
115116
"""
116117
return os.path.expandvars(os.path.expanduser(_path))
117118

119+
118120
def inline(sconf):
119121
""" Return config in inline form, opposite of :meth:`config.expand`.
120122
@@ -125,26 +127,26 @@ def inline(sconf):
125127
"""
126128

127129
if (
128-
'shell_command' in sconf and
129-
isinstance(sconf['shell_command'], list) and
130-
len(sconf['shell_command']) == 1
130+
'shell_command' in sconf and
131+
isinstance(sconf['shell_command'], list) and
132+
len(sconf['shell_command']) == 1
131133
):
132134
sconf['shell_command'] = sconf['shell_command'][0]
133135

134136
if len(sconf.keys()) == int(1):
135137
sconf = sconf['shell_command']
136138
if (
137-
'shell_command_before' in sconf and
138-
isinstance(sconf['shell_command_before'], list) and
139-
len(sconf['shell_command_before']) == 1
139+
'shell_command_before' in sconf and
140+
isinstance(sconf['shell_command_before'], list) and
141+
len(sconf['shell_command_before']) == 1
140142
):
141143
sconf['shell_command_before'] = sconf['shell_command_before'][0]
142144

143145
# recurse into window and pane config items
144146
if 'windows' in sconf:
145147
sconf['windows'] = [
146148
inline(window) for window in sconf['windows']
147-
]
149+
]
148150
if 'panes' in sconf:
149151
sconf['panes'] = [inline(pane) for pane in sconf['panes']]
150152

@@ -221,30 +223,30 @@ def expand(sconf, cwd=None, parent=None):
221223
)
222224

223225
if (
224-
'shell_command' in sconf and
225-
isinstance(sconf['shell_command'], string_types)
226+
'shell_command' in sconf and
227+
isinstance(sconf['shell_command'], string_types)
226228
):
227229
sconf['shell_command'] = [sconf['shell_command']]
228230

229231
if (
230-
'shell_command_before' in sconf and
231-
isinstance(sconf['shell_command_before'], string_types)
232+
'shell_command_before' in sconf and
233+
isinstance(sconf['shell_command_before'], string_types)
232234
):
233235
sconf['shell_command_before'] = [sconf['shell_command_before']]
234236

235237
if (
236-
'shell_command_before' in sconf and
237-
isinstance(sconf['shell_command_before'], list)
238+
'shell_command_before' in sconf and
239+
isinstance(sconf['shell_command_before'], list)
238240
):
239241
sconf['shell_command_before'] = [
240242
expandshell(scmd) for scmd in sconf['shell_command_before']
241-
]
243+
]
242244

243245
# recurse into window and pane config items
244246
if 'windows' in sconf:
245247
sconf['windows'] = [
246248
expand(window, parent=sconf) for window in sconf['windows']
247-
]
249+
]
248250
elif 'panes' in sconf:
249251

250252
for pconf in sconf['panes']:
@@ -322,8 +324,8 @@ def trickle(sconf):
322324
windowconfig['start_directory'] = session_start_directory
323325
else:
324326
if not any(
325-
windowconfig['start_directory'].startswith(a)
326-
for a in ['~', '/']
327+
windowconfig['start_directory'].startswith(a)
328+
for a in ['~', '/']
327329
):
328330
window_start_path = os.path.join(
329331
session_start_directory, windowconfig['start_directory']
@@ -351,7 +353,7 @@ def trickle(sconf):
351353

352354
p_index = windowconfig['panes'].index(paneconfig)
353355
windowconfig['panes'][p_index]['shell_command'] = commands_before
354-
#paneconfig['shell_command'] = commands_before
356+
# paneconfig['shell_command'] = commands_before
355357

356358
return sconf
357359

@@ -425,9 +427,7 @@ def import_tmuxinator(sconf):
425427
for w in sconf['windows']:
426428
for k, v in w.items():
427429

428-
windowdict = {}
429-
430-
windowdict['window_name'] = k
430+
windowdict = {'window_name': k}
431431

432432
if isinstance(v, string_types) or v is None:
433433
windowdict['panes'] = [v]
@@ -482,9 +482,8 @@ def import_teamocil(sconf):
482482

483483
for w in sconf['windows']:
484484

485-
windowdict = {}
485+
windowdict = {'window_name': w['name']}
486486

487-
windowdict['window_name'] = w['name']
488487
if 'clear' in w:
489488
windowdict['clear'] = w['clear']
490489

tmuxp/log.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ def default_log_template(self, record):
3939
)
4040
asctime = (
4141
'[' + Fore.BLACK + Style.DIM + Style.BRIGHT +
42-
'%(asctime)s'
43-
+ Fore.RESET + Style.RESET_ALL + ']'
42+
'%(asctime)s' + Fore.RESET + Style.RESET_ALL + ']'
4443
)
4544
name = (
4645
' ' + Fore.WHITE + Style.DIM + Style.BRIGHT +
47-
'%(name)s'
48-
+ Fore.RESET + Style.RESET_ALL + ' '
46+
'%(name)s' + Fore.RESET + Style.RESET_ALL + ' '
4947
)
5048

5149
tpl = reset + levelname + asctime + name + reset
@@ -54,7 +52,6 @@ def default_log_template(self, record):
5452

5553

5654
class LogFormatter(logging.Formatter):
57-
5855
template = default_log_template
5956

6057
def __init__(self, color=True, *args, **kwargs):
@@ -88,18 +85,15 @@ def debug_log_template(self, record):
8885
reset = Style.RESET_ALL
8986
levelname = (
9087
LEVEL_COLORS.get(record.levelname) + Style.BRIGHT +
91-
'(%(levelname)1.1s)'
92-
+ Style.RESET_ALL + ' '
88+
'(%(levelname)1.1s)' + Style.RESET_ALL + ' '
9389
)
9490
asctime = (
9591
'[' + Fore.BLACK + Style.DIM + Style.BRIGHT +
96-
'%(asctime)s'
97-
+ Fore.RESET + Style.RESET_ALL + ']'
92+
'%(asctime)s' + Fore.RESET + Style.RESET_ALL + ']'
9893
)
9994
name = (
10095
' ' + Fore.WHITE + Style.DIM + Style.BRIGHT +
101-
'%(name)s'
102-
+ Fore.RESET + Style.RESET_ALL + ' '
96+
'%(name)s' + Fore.RESET + Style.RESET_ALL + ' '
10397
)
10498
module_funcName = (
10599
Fore.GREEN + Style.BRIGHT +
@@ -116,7 +110,6 @@ def debug_log_template(self, record):
116110

117111

118112
class DebugLogFormatter(LogFormatter):
119-
120113
"""Provides greater technical details than standard log Formatter."""
121114

122115
template = debug_log_template

tmuxp/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _list_windows(self):
208208

209209
# tmux < 1.8 doesn't have window_id, use window_name
210210
for w in windows:
211-
if not 'window_id' in w:
211+
if 'window_id' not in w:
212212
w['window_id'] = w['window_name']
213213

214214
if self._windows:
@@ -323,7 +323,7 @@ def has_session(self, target_session):
323323

324324
proc = self.cmd('has-session', '-t%s' % target_session)
325325

326-
if proc.stdout == []:
326+
if not proc.stdout:
327327
return True
328328
if any(
329329
x in proc.stdout for x in

0 commit comments

Comments
 (0)