Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
windows does not use zip version of ccxt-rest binary because 'unzip' …
Browse files Browse the repository at this point in the history
…is not supported by default in WSL
  • Loading branch information
nikhilsaraf committed May 6, 2020
1 parent a01c0b2 commit f86d17e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
54 changes: 39 additions & 15 deletions cmd/server_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,31 @@ func init() {
ccxtDirPath := kos.GetDotKelpWorkingDir().Join(kelpCcxtPath)
ccxtFilenameNoExt := fmt.Sprintf("ccxt-rest_%s-x64", ccxtGoos)
filenameWithExt := fmt.Sprintf("%s.zip", ccxtFilenameNoExt)
ccxtDestDir := ccxtDirPath.Join(ccxtFilenameNoExt)
ccxtBinPath := ccxtDestDir.Join(ccxtBinaryName)

// don't use explicit unix filepath here since it uses os.Stat and os.Create directly and won't work on windows
ccxtBundledZipPath := kos.GetBinDir().Join("ccxt").Join(filenameWithExt)
ccxtZipDestPath := ccxtDirPath.Join(filenameWithExt)
e = copyOrDownloadCcxtBinary(kos, ccxtBundledZipPath, ccxtDirPath, ccxtZipDestPath, filenameWithExt)
log.Printf("mkdir ccxtDirPath: %s ...", ccxtDirPath.AsString())
e := kos.Mkdir(ccxtDirPath)
if e != nil {
panic(e)
panic(fmt.Errorf("could not mkdir for ccxtDirPath: %s", e))
}

ccxtBinPath := ccxtDirPath.Join(ccxtFilenameNoExt, ccxtBinaryName)
unzipCcxtFile(kos, ccxtDirPath, ccxtBinPath, filenameWithExt)
if runtime.GOOS == "windows" {
ccxtSourceDir := kos.GetBinDir().Join("ccxt").Join(ccxtFilenameNoExt)
e = copyCcxtFolder(kos, ccxtSourceDir, ccxtDestDir)
if e != nil {
panic(e)
}
} else {
ccxtBundledZipPath := kos.GetBinDir().Join("ccxt").Join(filenameWithExt)
ccxtZipDestPath := ccxtDirPath.Join(filenameWithExt)
e = copyOrDownloadCcxtBinary(kos, ccxtBundledZipPath, ccxtZipDestPath, filenameWithExt)
if e != nil {
panic(e)
}

unzipCcxtFile(kos, ccxtDirPath, ccxtBinPath, filenameWithExt)
}

e = runCcxtBinary(kos, ccxtBinPath)
if e != nil {
Expand Down Expand Up @@ -364,19 +378,29 @@ func setMiddleware(r *chi.Mux) {
r.Use(middleware.Timeout(60 * time.Second))
}

func copyCcxtFolder(
kos *kelpos.KelpOS,
ccxtSourceDir *kelpos.OSPath,
ccxtDestDir *kelpos.OSPath,
) error {
log.Printf("copying ccxt directory from %s to location %s ...", ccxtSourceDir.AsString(), ccxtDestDir.AsString())

cpCmd := fmt.Sprintf("cp -a %s %s", ccxtSourceDir.Unix(), ccxtDestDir.Unix())
_, e := kos.Blocking("cp-ccxt", cpCmd)
if e != nil {
return fmt.Errorf("unable to copy ccxt directory from %s to %s: %s", ccxtSourceDir.AsString(), ccxtDestDir.AsString(), e)
}
log.Printf("... done copying ccxt from %s to location %s", ccxtSourceDir.AsString(), ccxtDestDir.AsString())

return nil
}

func copyOrDownloadCcxtBinary(
kos *kelpos.KelpOS,
ccxtBundledZipPath *kelpos.OSPath,
ccxtDirPath *kelpos.OSPath,
ccxtZipDestPath *kelpos.OSPath,
filenameWithExt string,
) error {
log.Printf("mkdir ccxtDirPath: %s ...", ccxtDirPath.AsString())
e := kos.Mkdir(ccxtDirPath)
if e != nil {
return errors.Wrap(e, "could not mkdir for ccxtDirPath: "+ccxtDirPath.AsString())
}

if _, e := os.Stat(ccxtZipDestPath.Native()); !os.IsNotExist(e) {
return nil
}
Expand All @@ -398,7 +422,7 @@ func copyOrDownloadCcxtBinary(
// else download
downloadURL := fmt.Sprintf("%s/%s", ccxtDownloadBaseURL, filenameWithExt)
log.Printf("download ccxt from %s to location: %s ...", downloadURL, ccxtZipDestPath.AsString())
e = networking.DownloadFileWithGrab(
e := networking.DownloadFileWithGrab(
downloadURL,
ccxtZipDestPath.Native(),
downloadCcxtUpdateIntervalLogMillis,
Expand Down
16 changes: 12 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,18 @@ do
mkdir -p "$ARCHIVE_FOLDER_NAME/$BIN_PATH_REL/ccxt"
check_build_result $?
echo "done"
echo -n "copying ccxt-rest zip file from $KELP_BUILD_CACHE_CCXT/$CCXT_FILENAME to $ARCHIVE_FOLDER_NAME/$BIN_PATH_REL/ccxt/$CCXT_FILENAME ... "
cp $KELP_BUILD_CACHE_CCXT/$CCXT_FILENAME $ARCHIVE_FOLDER_NAME/$BIN_PATH_REL/ccxt/$CCXT_FILENAME
check_build_result $?
echo "done"
if [[ $GOOS == "windows" ]]
then
echo -n "unzipping ccxt directory from $KELP_BUILD_CACHE_CCXT/$CCXT_FILENAME to $ARCHIVE_FOLDER_NAME/$BIN_PATH_REL/ccxt ... "
unzip -q $KELP_BUILD_CACHE_CCXT/$CCXT_FILENAME -d $ARCHIVE_FOLDER_NAME/$BIN_PATH_REL/ccxt
check_build_result $?
echo "done"
else
echo -n "copying ccxt-rest zip file from $KELP_BUILD_CACHE_CCXT/$CCXT_FILENAME to $ARCHIVE_FOLDER_NAME/$BIN_PATH_REL/ccxt/$CCXT_FILENAME ... "
cp $KELP_BUILD_CACHE_CCXT/$CCXT_FILENAME $ARCHIVE_FOLDER_NAME/$BIN_PATH_REL/ccxt/$CCXT_FILENAME
check_build_result $?
echo "done"
fi

# archive
if [[ ("$(go env GOOS)" == "darwin" && $GOOS == "darwin") ]]
Expand Down

0 comments on commit f86d17e

Please sign in to comment.