1
+ import io
1
2
import os .path
2
3
import sys
3
4
import tarfile
4
5
import time
5
6
import zipfile
6
- import StringIO
7
7
8
8
def read_file (path , use_crlf ):
9
9
with open (path , 'rb' ) as file :
10
10
data = file .read ()
11
11
12
- if '\0 ' not in data :
13
- data = data .replace ('\r ' , '' )
12
+ if b '\0 ' not in data :
13
+ data = data .replace (b '\r ' , b '' )
14
14
if use_crlf :
15
- data = data .replace ('\n ' , '\r \n ' )
15
+ data = data .replace (b '\n ' , b '\r \n ' )
16
16
17
17
return data
18
18
@@ -24,7 +24,7 @@ def write_zip(target, arcprefix, timestamp, sources):
24
24
info = zipfile .ZipInfo (path )
25
25
info .date_time = time .localtime (timestamp )
26
26
info .compress_type = zipfile .ZIP_DEFLATED
27
- info .external_attr = 0644 << 16L
27
+ info .external_attr = 0o644 << 16
28
28
archive .writestr (info , data )
29
29
30
30
def write_tar (target , arcprefix , timestamp , sources , compression ):
@@ -35,7 +35,7 @@ def write_tar(target, arcprefix, timestamp, sources, compression):
35
35
info = tarfile .TarInfo (path )
36
36
info .size = len (data )
37
37
info .mtime = timestamp
38
- archive .addfile (info , StringIO . StringIO (data ))
38
+ archive .addfile (info , io . BytesIO (data ))
39
39
40
40
if len (sys .argv ) < 5 :
41
41
raise RuntimeError ('Usage: python archive.py <target> <archive prefix> <timestamp> <source files>' )
0 commit comments