Skip to content

Commit

Permalink
ZIP comment functionality added (issue #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumICE committed Dec 17, 2023
1 parent 8604055 commit 42c1340
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
9 changes: 7 additions & 2 deletions downloader/configuration.go
Expand Up @@ -20,6 +20,7 @@ type RuntimeConfiguration struct {
GroupOutputBy OutputGroup
OpenTargetDirectory bool
ZipMode OutputZipMode
NoComment bool
DownloadThreads int
SaveRawContent bool
SaveXIHeader bool
Expand Down Expand Up @@ -84,10 +85,13 @@ func ParseLaunchOptions() (RuntimeConfiguration, error) {
messageIDs := flag.String("ids", "", "Required. Path to a list of message IDs to download, one message per line.")
logVersions := flag.String("log", LogVersionSpecialAll,
fmt.Sprintf(
"Comma-separated list of log versions which must be exported. Supports standard version names (BI, MS, etc) and special values (%s, %s, %s). See details in documentation. ",
"Comma-separated list of log versions which must be exported. Supports standard version names (BI, MS, etc) and special values (%s, %s, %s, %s, %s). See details in documentation. ",
LogVersionSpecialAll,
LogVersionSpecialNone,
LogVersionSpecialJSON))
LogVersionSpecialJSON,
LogVersionSpecialJSONSender,
LogVersionSpecialJSONReceiver,
))

stageVersions := flag.String("stage", StageVersionSpecialAll,
fmt.Sprintf(
Expand All @@ -104,6 +108,7 @@ func ParseLaunchOptions() (RuntimeConfiguration, error) {
zipMode := flag.String("zip", "all", "Mode of compression for exported payloads. Available options are: (n)one, (f)ile, (a)ll")
flag.IntVar(&options.DownloadThreads, "threads", 2, "Number of parallel HTTP download threads")
flag.BoolVar(&options.StatisticsOnly, "statsonly", false, "If specified, only statistics on available message versions will be displayed. No actual download will happen.")
flag.BoolVar(&options.NoComment, "nocomment", false, "If specified, no text comment will be added to ZIP file (applies to -zip all).")

//////////////

Expand Down
5 changes: 5 additions & 0 deletions downloader/file_writer.go
Expand Up @@ -9,6 +9,8 @@ import (
"time"
)

var ExportComment string

func prepareFileWriter(options RuntimeConfiguration, connect ConnectionOptions) error {
if options.StatisticsOnly {
// nothing to do here
Expand All @@ -25,6 +27,7 @@ func prepareFileWriter(options RuntimeConfiguration, connect ConnectionOptions)
}

dt := time.Now().Format("20060102150405")
dtcomment := time.Now().Format("2006-01-02 15:04:05")

path := fmt.Sprintf("%s/%s/%s/", options.OutputDirectory, url.Hostname(), dt)

Expand All @@ -38,6 +41,8 @@ func prepareFileWriter(options RuntimeConfiguration, connect ConnectionOptions)
return errors.New(fmt.Sprintf("Cannot change current directory to [%s]: %s", path, err))
}

ExportComment = fmt.Sprintf("Source : %s\nExtracted on: %s", url.Hostname(), dtcomment)

return nil
}

Expand Down
8 changes: 8 additions & 0 deletions downloader/file_writer_all.go
Expand Up @@ -27,6 +27,14 @@ func FileWriterModeAll(options RuntimeConfiguration, version <-chan XIMessagePay
w := zip.NewWriter(file)
defer w.Close()

if options.NoComment == false {
err = w.SetComment(ExportComment)
if err != nil {
fmt.Printf("Failed creating file [%s]: %s\n", newFilename, err)
os.Exit(8)
}
}

for entry := range version {

for _, item := range entry.Parts {
Expand Down
2 changes: 1 addition & 1 deletion downloader/launcher.go
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
ToolVersion string = "1.0.0 (2023-12-10)"
ToolVersion string = "1.1.0 (2023-12-17)"
ToolRepo = "https://github.com/platinumICE/sap-po-tools"
ToolAuthor = "Marat Bareev"
)
Expand Down

0 comments on commit 42c1340

Please sign in to comment.