1
- # -*- coding: utf-8 -*-
2
1
# Copyright 2012 Camptocamp SA
3
2
# Author: Guewen Baconnier
4
3
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
5
4
6
- import string
7
5
import datetime
6
+ import string
8
7
from io import StringIO
9
8
10
9
11
10
class CarrierFileGenerator (object ):
12
-
13
11
def __init__ (self , carrier_name ):
14
12
self .carrier_name = carrier_name
15
13
@@ -19,8 +17,8 @@ def carrier_for(cls, carrier_name):
19
17
20
18
@staticmethod
21
19
def sanitize_filename (name ):
22
- valid_chars = "-_.() %s%s" % (string .ascii_letters , string .digits )
23
- return '' .join (c for c in name if c in valid_chars )
20
+ valid_chars = "-_.() {}{}" . format (string .ascii_letters , string .digits )
21
+ return "" .join (c for c in name if c in valid_chars )
24
22
25
23
@staticmethod
26
24
def _filename_date (timestamp = None ):
@@ -33,7 +31,7 @@ def _filename_date(timestamp=None):
33
31
:return: a date as str
34
32
"""
35
33
date = timestamp or datetime .datetime .now ()
36
- return date .strftime (' %Y%m%d_%H%M%S' )
34
+ return date .strftime (" %Y%m%d_%H%M%S" )
37
35
38
36
def generate_files (self , pickings , configuration ):
39
37
"""
@@ -53,7 +51,7 @@ def generate_files(self, pickings, configuration):
53
51
else :
54
52
return self ._generate_files_single (pickings , configuration )
55
53
56
- def _get_filename_single (self , picking , configuration , extension = ' csv' ):
54
+ def _get_filename_single (self , picking , configuration , extension = " csv" ):
57
55
"""
58
56
Generate the filename for a picking when one file is
59
57
generated for one picking
@@ -65,9 +63,9 @@ def _get_filename_single(self, picking, configuration, extension='csv'):
65
63
:param str extension: extension of the file to create, csv by default
66
64
:return: a string with the name of the file
67
65
"""
68
- return "%s_%s.%s" % (picking .name , self ._filename_date (), extension )
66
+ return "{}_{}.{}" . format (picking .name , self ._filename_date (), extension )
69
67
70
- def _get_filename_grouped (self , configuration , extension = ' csv' ):
68
+ def _get_filename_grouped (self , configuration , extension = " csv" ):
71
69
"""
72
70
Generate the filename for a file which group many pickings.
73
71
When pickings are grouped in one file, the filename cannot
@@ -79,7 +77,7 @@ def _get_filename_grouped(self, configuration, extension='csv'):
79
77
:param str extension: extension of the file to create, csv by default
80
78
:return: a string with the name of the file
81
79
"""
82
- return "%s_%s.%s" % ( ' out' , self ._filename_date (), extension )
80
+ return "{}_{}.{}" . format ( " out" , self ._filename_date (), extension )
83
81
84
82
def _get_rows (self , picking , configuration ):
85
83
"""
@@ -121,8 +119,7 @@ def _get_file(self, rows, configuration):
121
119
"""
122
120
file_handle = StringIO ()
123
121
try :
124
- file_handle = self ._write_rows (file_handle ,
125
- rows , configuration )
122
+ file_handle = self ._write_rows (file_handle , rows , configuration )
126
123
file_content = file_handle .getvalue ()
127
124
finally :
128
125
file_handle .close ()
0 commit comments