mirror of
https://github.com/vishapoberon/vipak.git
synced 2026-04-05 20:42:26 +00:00
Files moved to vpkConf
This commit is contained in:
parent
bea2422ac1
commit
2be7d9497e
2 changed files with 89 additions and 74 deletions
140
Vipack.Mod
140
Vipack.Mod
|
|
@ -1,10 +1,10 @@
|
|||
MODULE Vipack;
|
||||
IMPORT vpkFileManager,vpkJsonParser,vpkGit, vpkConf, vpkLogger, vpkPackageFileParser, Texts, Strings, In, Platform, Oberon, Out, Files, vpkUserDetails;
|
||||
IMPORT vpkFileManager,vpkJsonParser,vpkGit, vpkConf, vpkLogger, vpkPackageFileParser, Texts, Strings, In, Platform, Oberon, Out, vpkUserDetails;
|
||||
|
||||
PROCEDURE main();
|
||||
|
||||
CONST confFileName = "vipackConf.json";
|
||||
CONST syncDirName = "vipackTree/";
|
||||
CONST syncDirName = "vipackTree";
|
||||
CONST quote = '"';
|
||||
CONST startBracket = "{";
|
||||
CONST endBracket = "}";
|
||||
|
|
@ -12,17 +12,18 @@ CONST endBracket = "}";
|
|||
VAR user, str: ARRAY 32 OF CHAR;
|
||||
vpkDirPath, treePath, confPath, jsonString : ARRAY 120 OF CHAR;
|
||||
i : INTEGER;
|
||||
f : Files.File;
|
||||
r : Files.Rider;
|
||||
ch : CHAR;
|
||||
S: Texts.Scanner;
|
||||
jsonData,string,defaultUrl,gitUrl,project,command, jsonPathLine : ARRAY 500 OF CHAR;
|
||||
jsonData,string,defaultUrl,gitUrl,project,command, jsonPathLine : ARRAY 500 OF CHAR;
|
||||
success: BOOLEAN;
|
||||
jsonRecord: vpkJsonParser.JsonTypePointer;
|
||||
|
||||
PROCEDURE help();
|
||||
BEGIN
|
||||
vpkLogger.Log("HelpText");
|
||||
Out.String("Vipack sync - syncing git tree and local tree"); Out.Ln;
|
||||
Out.String("vipackConf.json path -> $HOME/.vipack/vipackConf.son"); Out.Ln;
|
||||
Out.String("vipackTree path -> $HOME/.vipack/vipackTree")
|
||||
END help;
|
||||
|
||||
|
||||
|
|
@ -36,84 +37,83 @@ defaultUrl := "https://github.com/vishaps/vipackTree";
|
|||
|
||||
command := S.s;
|
||||
|
||||
IF ~(Platform.getEnv("HOME", vpkDirPath)) THEN
|
||||
Out.String("HOME variable is not found"); Out.Ln;
|
||||
END;
|
||||
|
||||
(*HELP*)
|
||||
IF Strings.Match(command, "") OR Strings.Match(command, "--help")THEN
|
||||
IF Strings.Match(command, "") OR Strings.Match(command, "help")THEN
|
||||
help;
|
||||
END;
|
||||
|
||||
Strings.Append("/.vipack/",vpkDirPath);
|
||||
confPath := vpkDirPath;
|
||||
treePath := vpkDirPath;
|
||||
|
||||
(* Checking if ~/.vipack directory already exists *)
|
||||
IF vpkConf.makeDir(vpkDirPath) THEN
|
||||
Out.String("Creating directory "); Out.String(vpkDirPath);Out.Ln;
|
||||
ELSE Out.String(vpkDirPath); Out.String(" already exists or path is wrong");Out.Ln;
|
||||
END;
|
||||
|
||||
(* Checking if vipack.conf already exists *)
|
||||
Strings.Append(confFileName,confPath);
|
||||
|
||||
IF ~(vpkConf.confExists(confPath)) THEN
|
||||
Out.String("Creating the configuration file "); Out.String(confPath);Out.Ln;
|
||||
vpkConf.makeConf(confPath,f);
|
||||
Files.Set(r, f, 0);
|
||||
Strings.Append(startBracket, jsonPathLine);
|
||||
Strings.Append('"path" : ', jsonPathLine);
|
||||
Strings.Append(quote, jsonPathLine);
|
||||
Strings.Append(defaultUrl,jsonPathLine);
|
||||
Strings.Append(quote, jsonPathLine);
|
||||
Strings.Append(endBracket,jsonPathLine);
|
||||
Files.WriteString(r,jsonPathLine);
|
||||
Files.Close(f);
|
||||
ELSE
|
||||
Out.String("File already exists");Out.Ln;
|
||||
END;
|
||||
|
||||
IF ~(vpkConf.varCheck("HOME", vpkDirPath)) THEN
|
||||
Out.String("HOME variable is not found"); Out.Ln;
|
||||
END;
|
||||
|
||||
IF command = "sync" THEN
|
||||
Strings.Append("/.vipack/",vpkDirPath);
|
||||
confPath := vpkDirPath;
|
||||
treePath := vpkDirPath;
|
||||
Strings.Append(syncDirName, treePath);
|
||||
Out.String("*****************************************"); Out.Ln;
|
||||
Out.String("TreePath = "); Out.String(vpkDirPath);
|
||||
|
||||
(* Check tree directory if doesn't exist create*)
|
||||
IF vpkConf.makeDir(treePath) THEN
|
||||
Out.String("Creating "); Out.String(treePath); Out.String("for syncing");Out.Ln;
|
||||
ELSE Out.String("Some error occured or directory already exist");
|
||||
(* Checking if ~/.vipack directory already exists *)
|
||||
IF vpkConf.makeDir(vpkDirPath) THEN
|
||||
Out.String("Creating directory "); Out.String(vpkDirPath);Out.Ln;
|
||||
ELSE Out.String(vpkDirPath); Out.String(" already exists or path is wrong");Out.Ln;
|
||||
END;
|
||||
(* Syncing *)
|
||||
success := vpkFileManager.Read(confPath,jsonData);
|
||||
jsonRecord := vpkJsonParser.Create(jsonData);
|
||||
success := vpkJsonParser.GetTerminal(jsonRecord,"path", jsonString);
|
||||
Out.String("URL = ");
|
||||
Out.String(jsonString);Out.Ln;
|
||||
gitUrl := jsonString;
|
||||
string := gitUrl;
|
||||
Strings.Delete(string,19,Strings.Length(string)-17);
|
||||
Out.String(string);Out.Ln;
|
||||
(* Checking the URL of vipackConf.json path key *)
|
||||
IF Strings.Match(string,"https://github.com/") OR Strings.Match(string,"git://github.com/") THEN
|
||||
Out.String("YES"); Out.Ln;
|
||||
vpkGit.pull(gitUrl,treePath);
|
||||
|
||||
(* Checking if vipack.conf already exists *)
|
||||
Strings.Append(confFileName,confPath);
|
||||
|
||||
IF ~(vpkConf.confExists(confPath)) THEN
|
||||
Out.String("Creating the configuration file "); Out.String(confPath);Out.Ln;
|
||||
jsonPathLine := "";
|
||||
vpkConf.makeFile(confPath);
|
||||
Strings.Append(startBracket, jsonPathLine);
|
||||
Strings.Append('"path" : ', jsonPathLine);
|
||||
Strings.Append(quote, jsonPathLine);
|
||||
Strings.Append(defaultUrl,jsonPathLine);
|
||||
Strings.Append(quote, jsonPathLine);
|
||||
Strings.Append(endBracket,jsonPathLine);
|
||||
vpkConf.writeInFile(confPath,jsonPathLine,0);
|
||||
ELSE
|
||||
Out.String("File already exists");Out.Ln;
|
||||
END;
|
||||
|
||||
|
||||
IF command = "sync" THEN
|
||||
treePath := vpkDirPath;
|
||||
Strings.Append(syncDirName, treePath);
|
||||
Strings.Append("/",treePath);
|
||||
Out.String("*****************************************"); Out.Ln;
|
||||
Out.String("TreePath = "); Out.String(treePath);
|
||||
|
||||
(* Check tree directory if doesn't exist create*)
|
||||
IF vpkConf.makeDir(treePath) THEN
|
||||
Out.String("Creating "); Out.String(treePath); Out.String("for syncing");Out.Ln;
|
||||
ELSE Out.String("Some error occured or directory already exist");
|
||||
END;
|
||||
(* Syncing *)
|
||||
success := vpkFileManager.Read(confPath,jsonData);
|
||||
jsonRecord := vpkJsonParser.Create(jsonData);
|
||||
success := vpkJsonParser.GetTerminal(jsonRecord,"path", jsonString);
|
||||
Out.String("URL = ");
|
||||
Out.String(jsonString);Out.Ln;
|
||||
gitUrl := jsonString;
|
||||
string := gitUrl;
|
||||
Strings.Delete(string,19,Strings.Length(string)-17);
|
||||
Out.String(string);Out.Ln;
|
||||
(* Checking the URL of vipackConf.json path key *)
|
||||
IF Strings.Match(string,"https://github.com/") OR Strings.Match(string,"git://github.com/") THEN
|
||||
Out.String("YES"); Out.Ln;
|
||||
vpkGit.pull(gitUrl,treePath);
|
||||
END;
|
||||
END;
|
||||
END;
|
||||
|
||||
|
||||
|
||||
IF command = "install" THEN
|
||||
Texts.Scan(S);
|
||||
project := S.s;
|
||||
Out.String(project);Out.Ln;
|
||||
vpkPackageFileParser.install();
|
||||
IF command = "install" THEN
|
||||
Texts.Scan(S);
|
||||
project := S.s;
|
||||
Out.String(project);Out.Ln;
|
||||
vpkPackageFileParser.install();
|
||||
|
||||
END;
|
||||
|
||||
END;
|
||||
|
||||
|
||||
END main;
|
||||
|
||||
|
||||
|
|
|
|||
23
vpkConf.Mod
23
vpkConf.Mod
|
|
@ -1,5 +1,5 @@
|
|||
MODULE vpkConf;
|
||||
IMPORT Files, vpkFsHelper;
|
||||
IMPORT Out,Files, vpkFsHelper, Platform;
|
||||
|
||||
PROCEDURE confExists*(VAR confFile: ARRAY OF CHAR ):BOOLEAN;
|
||||
BEGIN
|
||||
|
|
@ -9,19 +9,34 @@ BEGIN
|
|||
|
||||
END confExists;
|
||||
|
||||
PROCEDURE makeConf*(VAR confFilePath: ARRAY OF CHAR;VAR f:Files.File);
|
||||
PROCEDURE makeFile*(VAR confFilePath: ARRAY OF CHAR);
|
||||
VAR f : Files.File;
|
||||
BEGIN
|
||||
|
||||
f := Files.New(confFilePath);
|
||||
Files.Register(f);
|
||||
|
||||
END makeConf;
|
||||
END makeFile;
|
||||
|
||||
PROCEDURE makeDir*(VAR confDirPath: ARRAY OF CHAR):BOOLEAN;
|
||||
BEGIN
|
||||
RETURN vpkFsHelper.mkDir(confDirPath);
|
||||
END makeDir;
|
||||
|
||||
PROCEDURE varCheck*(variable : ARRAY OF CHAR;VAR value : ARRAY OF CHAR): BOOLEAN;
|
||||
BEGIN
|
||||
RETURN Platform.getEnv(variable,value);
|
||||
END varCheck;
|
||||
|
||||
PROCEDURE writeInFile*(VAR pathToFile : ARRAY OF CHAR;VAR text : ARRAY OF CHAR; posRider : INTEGER);
|
||||
VAR f : Files.File;
|
||||
r : Files.Rider;
|
||||
BEGIN
|
||||
f := Files.Old(pathToFile);
|
||||
Files.Set(r,f,posRider);
|
||||
Files.WriteString(r,text);
|
||||
Files.Close(f);
|
||||
END writeInFile;
|
||||
|
||||
|
||||
BEGIN
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue