Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

"""Archive type classes and commands.""" 

from __future__ import absolute_import, print_function, unicode_literals 

 

import logging 

 

from xtract.base import BaseArchiveType, BaseCompressionType 

from xtract.utils import register_xtract 

 

 

logger = logging.getLogger(__name__) 

 

 

@register_xtract 

class Rar(BaseArchiveType): 

"""A class to represent the archive type: rar.""" 

 

name = 'rar' 

extensions = [ 

'rar' 

] 

mimetypes = [ 

'application/rar', 

'application/x-rar' 

] 

 

def get_unpack_command(self, source, destination): 

"""Unpack the given rar archive to the given destination.""" 

return "unrar x -o+ {} {}".format(source, destination) 

 

def get_pack_command(self, source_root, source_files, destination): 

"""Pack the given source to a rar archive at the given destination.""" 

return "rar a -r -ep1 {} {}".format(destination, ' '.join(source_files)), source_root 

 

 

def rar(*args, **kwargs): 

return Rar().pack(*args, **kwargs) 

 

 

@register_xtract 

class Zip(BaseArchiveType): 

"""A class to represent the archive type: zip.""" 

 

name = 'zip' 

extensions = [ 

'zip', 

'egg', 

'whl', 

'jar' 

] 

mimetypes = [ 

'application/zip', 

'application/x-zip', 

] 

 

def get_unpack_command(self, source, destination): 

"""Unpack the given zip archive to the given destination.""" 

return "unzip -o {} -d {}".format(source, destination) 

 

def get_pack_command(self, source_root, source_files, destination): 

"""Pack the given source to a zip archive at the given destination.""" 

return "zip -r {} {}".format(destination, ' '.join(source_files)), source_root 

 

 

def zip(*args, **kwargs): 

return Zip().pack(*args, **kwargs) 

 

 

@register_xtract 

class Tar(BaseArchiveType): 

"""A class to represent the archive type: tar.""" 

 

name = 'tar' 

extensions = [ 

'tar' 

] 

mimetypes = [ 

"application/tar", 

"application/x-tar", 

] 

 

def get_unpack_command(self, source, destination): 

"""Unpack the given tar archive to the given destination.""" 

return "tar --overwrite -C {} -xf {}".format(destination, source) 

 

def get_pack_command(self, source_root, source_files, destination): 

"""Pack the given source to a tar archive at the given destination.""" 

return "tar -C {} -cf {} {}".format(source_root, destination, ' '.join(source_files)) 

 

 

def tar(*args, **kwargs): 

return Tar().pack(*args, **kwargs) 

 

 

@register_xtract 

class GZip(BaseCompressionType): 

"""A class to represent the archive type: gzip.""" 

 

name = 'gzip' 

extensions = [ 

'gz' 

] 

mimetypes = [ 

"application/gzip", 

"application/x-gzip", 

] 

 

 

def gzip(*args, **kwargs): 

return GZip().compress(*args, **kwargs) 

 

 

@register_xtract 

class XZ(BaseCompressionType): 

"""A class to represent the archive type: xz.""" 

 

name = 'xz' 

extensions = [ 

'xz', 

'lzma', 

'txz', 

'tlz' 

] 

mimetypes = [ 

"application/xz", 

"application/x-xz", 

] 

 

 

def xz(*args, **kwargs): 

return XZ().compress(*args, **kwargs) 

 

 

@register_xtract 

class BZip2(BaseCompressionType): 

"""A class to represent the archive type: bzip2.""" 

 

name = 'bzip2' 

extensions = [ 

'bz2', 

'bz', 

'tbz2', 

'tbz', 

'bzip2', 

'bzip', 

] 

mimetypes = [ 

"application/bzip", 

"application/bzip2", 

"application/x-bzip", 

"application/x-bzip2", 

] 

 

 

def bzip2(*args, **kwargs): 

return BZip2().compress(*args, **kwargs)