Fixed file extension for tar files

This commit is contained in:
Sebastian Lohff 2012-04-27 17:39:12 +02:00
parent b5c43664e2
commit e649416b17
1 changed files with 12 additions and 1 deletions

View File

@ -174,6 +174,7 @@ class TarFileHandler(FileBaseHandler):
cmd = ["tar", "-cj"] cmd = ["tar", "-cj"]
else: else:
raise ValueError("Unknown compression mode '%s'" % self.compression) raise ValueError("Unknown compression mode '%s'" % self.compression)
dirname = os.path.basename(self.target.rstrip("/")) dirname = os.path.basename(self.target.rstrip("/"))
chdirTo = os.path.dirname(self.target.rstrip("/")) chdirTo = os.path.dirname(self.target.rstrip("/"))
if chdirTo != '': if chdirTo != '':
@ -181,6 +182,16 @@ class TarFileHandler(FileBaseHandler):
cmd.append(dirname) cmd.append(dirname)
return cmd return cmd
@staticmethod
def getCompressionExt():
if TarFileHandler.compression == "none":
return ".tar"
elif TarFileHandler.compression == "gzip":
return ".tar.gz"
elif TarFileHandler.compression == "bzip2":
return ".tar.bz2"
raise ValueError("Unknown compression mode '%s'" % self.compression)
class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler): class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler):
""" Simple HTTP Server which allows uploading to a specified directory """ Simple HTTP Server which allows uploading to a specified directory
either via multipart/form-data or POST/PUT requests containing the file. either via multipart/form-data or POST/PUT requests containing the file.
@ -545,7 +556,7 @@ class ServeFile():
if not os.path.exists(self.realTarget): if not os.path.exists(self.realTarget):
raise ServeFileException("Error: Could not open file or directory") raise ServeFileException("Error: Could not open file or directory")
TarFileHandler.target = self.realTarget TarFileHandler.target = self.realTarget
TarFileHandler.fileName = os.path.basename(self.realTarget.rstrip("/")) TarFileHandler.fileName = os.path.basename(self.realTarget.rstrip("/")) + TarFileHandler.getCompressionExt()
handler = TarFileHandler handler = TarFileHandler
elif self.serveMode == self.MODE_UPLOAD: elif self.serveMode == self.MODE_UPLOAD: