aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/fetcher.nim0
-rw-r--r--src/core/locker.nim112
-rw-r--r--src/core/manager.nim89
-rw-r--r--src/core/parser.nim1
4 files changed, 0 insertions, 202 deletions
diff --git a/src/core/fetcher.nim b/src/core/fetcher.nim
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/core/fetcher.nim
diff --git a/src/core/locker.nim b/src/core/locker.nim
index f4e90e9..e69de29 100644
--- a/src/core/locker.nim
+++ b/src/core/locker.nim
@@ -1,112 +0,0 @@
-import std / [
- os,
- json,
- strformat
-]
-
-import ./manager
-
-proc lockPath*(): string =
- let
- homeDir: string = getHomeDir()
- lockDir: string = homeDir / ".local" / "tesserae"
- ensureDir(lockDir)
- result = lockDir / "tesserae.lock"
-
-proc loadLock*(): JsonNode =
- let lockFile: string = lockPath()
- result = %*{}
- if fileExists(lockFile):
- try:
- result = parseFile(lockFile)
- except JsonParsingError:
- echo "JsonParsingError. Treating the lockfile as non existant"
- result = %*{}
-
-proc writeLock*(jsonObject: JsonNode) =
- let lockFile: string = lockPath()
- writeFile(lockFile, jsonObject.pretty())
-
-proc updateLock*(
- packageName: string,
- sourceURL: string,
- sourceDir: string,
- chosenTag: string,
- configPath: string
-) =
- ## Updates the lockfile
- var lock: JsonNode = loadLock()
- let
- config: string = readConfigFile(configPath)
- jsonObject: JsonNode = %*{
- "source": { "url": sourceURL },
- "sha256": computeSHA256(sourceDir, chosenTag)
- "tag": chosenTag,
- "config": config
- # I should probably add a sha256 thingy
- }
- lock[packageName] = jsonObject
- writeLock(lock)
- echo "Updated {packageName}".fmt
-
-proc needRebuildLock*(
- packageName: string,
- sourceURL: string,
- sourceDir: string,
- chosenTag: string,
- configPath: string
-): bool =
- ## Checks whether the following have changed:\n
- ## - source (repo url)
- ## - sha256
- ## - tag (new release, manually updated, etc)
- ## - config file of package
- result = false
- let lockFile = loadLock()
-
- if not lockFile.hasKey(packageName):
- echo "{packageName} added to queue".fmt
- return true
-
- else:
- let package = lockFile[packageName]
- if not package.hasKey("source"):
- echo "Could not find source for package {packageName}".fmt
- echo "{packageName} added to queue".fmt
- return true
- if package["source"].hasKey("url"):
- let packageSource: string = package["source"]["url"].getStr
- if packageSource != sourceURL:
- echo "Source URL for package {packageName} has changed".fmt
- echo "{packageName} added to queue".fmt
- return true
-
-
- if not package.hasKey("sha256"):
- echo "sha256 not found for package {packageName}".fmt
- echo "{packageName} added to queue".fmt
- return true
- if package["sha256"].getStr != computeSHA256(sourceDir, chosenTag):
- echo "sha256 mismatch for package {packageName}".fmt
- echo "{packageName} added to queue".fmt
- return true
-
-
- if not package.hasKey("tag"):
- echo "Could not find release tag for package {packageName}".fmt
- echo "{packageName} added to queue".fmt
- return true
- if package["tag"].getStr != chosenTag:
- echo "Release tag has changed from {package["tag"]} -> {chosenTag}".fmt
- echo "{packageName} added to queue".fmt
- return true
-
-
- if not package.hasKey("config"):
- echo "Configuration file not found for package {packageName}".fmt
- echo "{packageName} added to queue"
- return true
- if package["config"].getStr != readConfigFile(configPath):
- echo "Configuration file changed for package {packageName}".fmt
- echo "{packageName} added to queue".fmt
- return true
diff --git a/src/core/manager.nim b/src/core/manager.nim
index 106c511..e69de29 100644
--- a/src/core/manager.nim
+++ b/src/core/manager.nim
@@ -1,89 +0,0 @@
-import std / [
- os,
- osproc,
- hashes,
- strformat
-]
-
-proc runCommand*(
- command: string,
- workingDir: string = ""
-): (string, int) =
- echo "-> {command} (workingDir: {workingDir})".fmt
- let (output, code) = execCmdEx(
- command=command,
- workingDir=workingDir
- )
- result = (output, code)
-
-proc ensureDir*(path: string) =
- if not dirExists(path):
- createDir(path)
-
-proc readConfigFile*(configPath: string): string =
- if fileExists(configPath):
- result = readFile(configPath)
- else:
- result = ""
-
-proc cloneSource*(
- repoURL: string,
- destinationDir: string
-) =
- if dirExists(destinationDir):
- echo "Repository already exists at {destinationDir}".fmt
- echo "Pulling..."
- let (output, code) = runCommand(
- command="git pull",
- workingDir=destinationDir
- )
- echo output
- else:
- echo "Cloning from {repoURL}...".fmt
- let (output, code) = runCommand(
- command="git clone {repoURL} {destinationDir}".fmt
- )
- echo output
-
-proc fetchTags*(
- destinationDir: string
-) =
- let (output, code) = runCommand(
- command="git fetch --tags --force",
- workingDir=destinationDir
- )
- echo output
-
-
-proc resolveTag*(
- destinationDir: string,
- pinnedTag: string = ""
-): string =
- ## if pinnedTag is defined, we use that;
- ## otherwise we fall back to newest tag
- if pinnedTag.len > 0:
- result = pinnedTag
- let (output, code) = runCommand(
- command="git rev-parse --verify {pinnedTag}".fmt,
- workingDir=destinationDir
- )
- echo output
- if code != 0:
- # if it fails, we try to fetch the tag
- # just in case
- fetchTags(destinationDir)
- let (newOutput, newCode) = runCommand(
- "git rev-parse --verify {pinnedTag}".fmt,
- workingDir=destinationdir
- )
- echo newOutput
- if newCode != 0:
- quit("Pinned tag {pinnedTag} not found in repo at {destDir}.")
- else:
- let (output, code) = runCommand(
- command="git describe --tags --abbrev=0",
- workingDir=destinationDir
- )
- result = output
- if code != 0:
- quit("There seem to be no releases available from this software")
diff --git a/src/core/parser.nim b/src/core/parser.nim
index 8b13789..e69de29 100644
--- a/src/core/parser.nim
+++ b/src/core/parser.nim
@@ -1 +0,0 @@
-
Directive (EU) 2019/790, Article 4(3); all rights regarding Text and Data Mining (TDM) are reserved.