39
39
40
40
from robot .errors import DataError
41
41
from robot .parsing import get_model , SuiteStructureBuilder , SuiteStructureVisitor
42
- from robot .tidypkg import (Aligner , Cleaner , SeparatorCleaner , PipeAdder ,
43
- NewlineAdder )
42
+ from robot .tidypkg import Aligner , Cleaner , NewlineCleaner , SeparatorCleaner
44
43
from robot .utils import Application , file_writer
45
44
46
- # TODO: maybe rename --format to --extension
47
45
# FIXME: Proofread usage
48
46
USAGE = """robot.tidy -- Robot Framework test data clean-up tool
49
47
71
69
-r --recursive Process given directory recursively. Files in the directory
72
70
are processed in-place similarly as when --inplace option
73
71
is used. Does not process referenced resource files.
74
- -f --format txt|robot
75
- Output file format. If omitted, the format of the input
76
- file is used.
77
72
-p --usepipes Use pipe ('|') as a cell separator in the plain text format.
78
73
-s --spacecount number
79
74
The number of spaces between cells in the plain text format.
@@ -139,11 +134,12 @@ class Tidy(SuiteStructureVisitor):
139
134
Tidy command line options with same names.
140
135
"""
141
136
142
- def __init__ (self , format = 'robot' , use_pipes = False , space_count = 4 ,
143
- line_separator = os .linesep ):
144
- self ._options = dict (format = format , pipe_separated = use_pipes ,
145
- txt_separating_spaces = space_count ,
146
- line_separator = line_separator )
137
+ def __init__ (self , space_count = 4 , use_pipes = False , line_separator = os .linesep ):
138
+ self .space_count = space_count
139
+ self .use_pipes = use_pipes
140
+ self .line_separator = line_separator
141
+ self .short_test_name_length = 18
142
+ self .setting_and_variable_name_length = 14
147
143
148
144
def file (self , path , outpath = None ):
149
145
"""Tidy a file.
@@ -160,8 +156,7 @@ def file(self, path, outpath=None):
160
156
return writer .getvalue ().replace ('\r \n ' , '\n ' )
161
157
162
158
def _get_writer (self , outpath ):
163
- return file_writer (outpath , newline = self ._options ['line_separator' ],
164
- usage = 'Tidy output' )
159
+ return file_writer (outpath , usage = 'Tidy output' )
165
160
166
161
def inplace (self , * paths ):
167
162
"""Tidy file(s) in-place.
@@ -183,13 +178,12 @@ def directory(self, path):
183
178
184
179
def _tidy (self , model , output = None ):
185
180
Cleaner ().visit (model )
186
- NewlineAdder ().visit (model )
187
- if self ._options ['pipe_separated' ]:
188
- PipeAdder ().visit (model )
189
- else :
190
- SeparatorCleaner (self ._options ['txt_separating_spaces' ]).visit (model )
191
- Aligner ().visit (model )
192
- model .save (output , self ._options ['line_separator' ])
181
+ NewlineCleaner (self .line_separator ,
182
+ self .short_test_name_length ).visit (model )
183
+ SeparatorCleaner (self .use_pipes , self .space_count ).visit (model )
184
+ Aligner (self .short_test_name_length ,
185
+ self .setting_and_variable_name_length ).visit (model )
186
+ model .save (output )
193
187
194
188
def visit_file (self , file ):
195
189
self .inplace (file .source )
@@ -211,9 +205,9 @@ class TidyCommandLine(Application):
211
205
def __init__ (self ):
212
206
Application .__init__ (self , USAGE , arg_limits = (1 ,))
213
207
214
- def main (self , arguments , recursive = False , inplace = False , format = 'txt' ,
208
+ def main (self , arguments , recursive = False , inplace = False ,
215
209
usepipes = False , spacecount = 4 , lineseparator = os .linesep ):
216
- tidy = Tidy (format = format , use_pipes = usepipes , space_count = spacecount ,
210
+ tidy = Tidy (use_pipes = usepipes , space_count = spacecount ,
217
211
line_separator = lineseparator )
218
212
if recursive :
219
213
tidy .directory (arguments [0 ])
@@ -227,7 +221,6 @@ def validate(self, opts, args):
227
221
validator = ArgumentValidator ()
228
222
opts ['recursive' ], opts ['inplace' ] = validator .mode_and_args (args ,
229
223
** opts )
230
- opts ['format' ] = validator .format (args , ** opts )
231
224
opts ['lineseparator' ] = validator .line_sep (** opts )
232
225
if not opts ['spacecount' ]:
233
226
opts .pop ('spacecount' )
@@ -267,16 +260,6 @@ def _default_mode_arguments(self, args):
267
260
if not os .path .isfile (args [0 ]):
268
261
raise DataError ('Default mode requires input to be a file.' )
269
262
270
- def format (self , args , format , inplace , recursive , ** others ):
271
- if not format :
272
- if inplace or recursive or len (args ) < 2 :
273
- return None
274
- format = os .path .splitext (args [1 ])[1 ][1 :]
275
- format = format .upper ()
276
- if format not in ('TXT' , 'ROBOT' ):
277
- raise DataError ("Invalid format '%s'." % format )
278
- return format
279
-
280
263
def line_sep (self , lineseparator , ** others ):
281
264
values = {'native' : os .linesep , 'windows' : '\r \n ' , 'unix' : '\n ' }
282
265
try :
@@ -303,7 +286,7 @@ def tidy_cli(arguments):
303
286
304
287
from robot.tidy import tidy_cli
305
288
306
- tidy_cli(['--format ', 'robot ', 'tests.txt '])
289
+ tidy_cli(['--spacecount ', '2 ', 'tests.robot '])
307
290
"""
308
291
TidyCommandLine ().execute_cli (arguments )
309
292
0 commit comments