Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify default parameters that are baked into the executable #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@ Shuttle is a utility that facilitates seamless file transfer from a source devic

## **Usage**

> **Note:** If you used the [ShuttleBuilder](https://github.com/ComPlat/shuttlebuilder), CLI arguments are preconfigured and do not need to be manually added.
### ShuttleBuilder
If you used the [ShuttleBuilder](https://github.com/ComPlat/shuttlebuilder), CLI arguments are preconfigured and do not need to be manually added.

### Execute by adding command line arguments
To run the utility, execute the following command:

```shell
go build
shuttle -src < source_directory_path > -duration < time_in_seconds > -dst < destination_server > -user < username > -pass < password > -type < file|folder|zip|tar|flat_tar > -transfer < webdav|sftp > -commonRegex < Regexp >
```

### Create a executable that contains default parameters
1. Edit the default parameters in "default_parameter.go"
1. Execute build which will create an executable for the desired operating system
```shell
python build.py
```

### Parameters:

- < source_directory_path >: Path to the source directory containing files to transfer.
Expand Down Expand Up @@ -102,5 +112,5 @@ This project is licensed under the MIT License.





22 changes: 22 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/local/bin/python
# This cannot be in go, since you cannot execute a go command from within go
import os

# get data from go-file
with open('default_parameter.go', encoding='utf-8') as fIn:
text = fIn.read()
text = text.split('return Parameter{')[1]
lines = text.split('}')[0].split('\n')
lines = [i.strip() for i in lines if i.strip()]
data = {i.split(":")[0]:i.split(":")[1].replace('"','').replace(',','').strip() for i in lines}

osDict = {
#label os arch extension
"linux":["linux", "amd64", "out"] ,
"winxp":["windows", "386", "exe"],
"win10":["windows", "amd64", "exe"]
}
osList = osDict[data['os'].lower()]

os.system(f"env GOOS={osList[0]} GOARCH={osList[1]} go build -o shuttle.{osList[2]}")

26 changes: 14 additions & 12 deletions cmd_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,27 @@ func (m Args) LogString() string {

// GetCmdArgs Get/Parse command line arguments manager
func GetCmdArgs() Args {
var fp, dst, user, pass, crt, durationStr, tType, name string
var fp, dst, user, pass, durationStr, tType, sendType, name string
var crt string
var duration int
var commonRegexStr string
var commonRegex *regexp.Regexp
var sendType string
var err error

flag.StringVar(&fp, "src", "{{ src }}", "Source directory to be watched.")
flag.StringVar(&name, "name", "{{ name }}", "Name of the EFW instance.")
flag.StringVar(&dst, "dst", "{{ dst }}", "WebDAV destination URL. If the destination is on the lsdf, the URL should be as follows:\nhttps://os-webdav.lsdf.kit.edu/<OE>/<inst>/projects/<PROJECTNAME>/\n <OE>-Organisationseinheit, z.B. kit.\n <inst>-Institut-Name, z.B. ioc, scc, ikp, imk-asf etc.\n <USERNAME>-User-Name z.B. xy1234, bs_abcd etc.\n <PROJRCTNAME>-Projekt-Name")
flag.StringVar(&user, "user", "{{ user }}", "WebDAV or SFTP user")
flag.StringVar(&pass, "pass", "{{ password }}", "WebDAV or SFTP Password")
flag.StringVar(&durationStr, "duration", "{{ duration }}", "Duration in seconds, i.e., how long a file must not be changed before sent.")
flag.StringVar(&crt, "crt", "{{ crt }}", "Path to server TLS certificate. Only needed if the server has a self signed certificate.")
var defaultParameter = DefaultParameter()

flag.StringVar(&fp, "src", defaultParameter.src, "Source directory to be watched.")
flag.StringVar(&name, "name", defaultParameter.name, "Name of the EFW instance.")
flag.StringVar(&dst, "dst", defaultParameter.dst, "WebDAV destination URL. If the destination is on the lsdf, the URL should be as follows:\nhttps://os-webdav.lsdf.kit.edu/<OE>/<inst>/projects/<PROJECTNAME>/\n <OE>-Organisationseinheit, z.B. kit.\n <inst>-Institut-Name, z.B. ioc, scc, ikp, imk-asf etc.\n <USERNAME>-User-Name z.B. xy1234, bs_abcd etc.\n <PROJRCTNAME>-Projekt-Name")
flag.StringVar(&user, "user", defaultParameter.user, "WebDAV or SFTP user")
flag.StringVar(&pass, "pass", defaultParameter.pass, "WebDAV or SFTP Password")
flag.StringVar(&durationStr, "duration", defaultParameter.duration, "Duration in seconds, i.e., how long a file must not be changed before sent.")
flag.StringVar(&crt, "crt", "{{ crt }}", "Path to server TLS certificate. Only needed if the server has a self signed certificate.")
/// Only considered if result are stored in a folder.
/// If zipped is set the result folder will be transferred as zip file
flag.StringVar(&sendType, "type", "{{ type }}", "Type must be 'file', 'folder', 'tar', 'zip' or 'flat_tar'. The 'file' option means that each file is handled individually, the 'folder' option means that entire folders are transmitted only when all files in them are ready. The option 'tar' and/or 'zip' send a folder zipped, only when all files in a folder are ready. The flat_tar option packs all files with have a common prefix into a tar file in a flat folder hierarchy")
flag.StringVar(&commonRegexStr, "commonRegex", "{{ common_regex }}", "The common prefix length is only required if the type is flat_tar. This value specifies the number of leading characters that must be the same in order for files to be packed together.")
flag.StringVar(&tType, "transfer", "{{ tType }}", "Type must be 'webdav' or 'sftp'.")
flag.StringVar(&sendType, "type", defaultParameter.tType, "Type must be 'file', 'folder', 'tar', 'zip' or 'flat_tar'. The 'file' option means that each file is handled individually, the 'folder' option means that entire folders are transmitted only when all files in them are ready. The option 'tar' and/or 'zip' send a folder zipped, only when all files in a folder are ready. The flat_tar option packs all files with have a common prefix into a tar file in a flat folder hierarchy")
flag.StringVar(&commonRegexStr,"commonRegex", "{{ common_regex }}", "The common prefix length is only required if the type is flat_tar. This value specifies the number of leading characters that must be the same in order for files to be packed together.")
flag.StringVar(&tType, "transfer", defaultParameter.sendType, "Type must be 'webdav' or 'sftp'.")
flag.Parse()

if duration, err = strconv.Atoi(durationStr); err != nil {
Expand Down
18 changes: 18 additions & 0 deletions default_parameter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

type Parameter struct {
src, user, pass, dst, sendType, tType, name, duration, os string
}

func DefaultParameter() Parameter {
return Parameter{
src: "",
name: "Instrument 1",
os: "winXP",
dst: "",
user: "",
pass: "",
duration: "5",
sendType: "sftp",
tType: "file"}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Shuttle

go 1.23
go 1.23.0

require (
github.com/StarmanMartin/gowebdav v0.0.0-20220901075112-8721ee532c0c
Expand Down