Last active
August 29, 2015 14:18
-
-
Save EvilBeaver/286d4cae638921f6d623 to your computer and use it in GitHub Desktop.
Get-Latest-Snegopat-Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. НЕ работает группировка Procedure/EndProcedure, Function/EndFunction | |
//2. Не опознаются ключевые слова "Not", "In", "False", "True" | |
//3. Не опознается объект CommandLineArguments (АргументыКоманднойСтроки) | |
//4. Не опознается метод Count() (Количество()) у массивов | |
//5. RunApp глотает кавычки: | |
//cmdLine = | |
//"C:\Snegopat 20\fossil.exe" clone "http://snegopat.ru:9004" "C:\Snegopat 20\repo\core.fossil" | |
// | |
//а командная строка процесса = | |
//"C:\Snegopat 20\fossil.exe" clone http://snegopat.ru:9004 C:\Snegopat 20\repo\core.fossil | |
//#Помощь Объект | |
// | |
//#ИМЯ Run | |
//Скрипт автообновления Снегопата 2.0 | |
// | |
//#ОПИСАНИЕ | |
//Скрипт обновляет и при необходимости создает с нуля и клонирует | |
//тестовый репозитарий Снегопата 2.0 | |
// | |
//#ПРИМЕР | |
//Get-Latest20.os | |
// | |
//#ПРИМЕР | |
//Get-Latest20.os "C:\Snegopat20" | |
// | |
//#ССЫЛКА | |
// https://snegopat.ru/forum/viewtopic.php?f=3&t=678 | |
// | |
//#ВЕРСИЯ | |
//2.0.0.1 | |
// | |
//#КонецПомощь | |
Var script_Path; | |
Var script_RepoPath; | |
Var script_Fossil; | |
Function Test_Path(Path) | |
File = New File(Path); | |
Return File.Exists(); | |
EndFunction | |
Function New_Repository(Name, URLPath, Description, Val Path="", Val RepoPath="") | |
If Path = "" Then | |
Path = script_Path + "\" + Name; | |
EndIf; | |
If RepoPath = "" Then | |
RepoPath = script_RepoPath + "\" + Name + ".fossil"; | |
EndIf; | |
Return New Structure("Name, Description, URLPath, Path, RepoPath", | |
Name, Description, URLPath, Path, RepoPath); | |
EndFunction | |
Function New_Folder(Path) | |
//If not Test_Path(Path) Then | |
If Не Test_Path(Path) Then | |
CreateDirectory(Path); | |
EndIf; | |
EndFunction | |
Function Run_Fossil(Command, Arguments, Path) | |
ExitCode = -1; | |
CurrentDirectory = CurrentDirectory(); | |
SetCurrentDirectory(Path); | |
cmdLine = """" + script_Fossil + """ " + Command; | |
// For each Argument In Arguments Do | |
For each Argument Из Arguments Do | |
cmdLine = cmdLine + " " + Argument; | |
EndDo; | |
//RunApp(cmdLine, , Истина, ExitCode); | |
message(cmdLine); | |
Process = CreateProcess(cmdLine,Path,Истина); | |
Process.Start(); | |
Process.WaitForExit(); | |
Message(Process.StdOut.Read()); | |
Message(Process.StdErr.Read()); | |
SetCurrentDirectory(CurrentDirectory); | |
Return (ExitCode = 0); | |
EndFunction | |
Procedure Test_Repository(Repository, Cancel) | |
If Cancel Then | |
Return; | |
EndIf; | |
New_Folder(Repository.Path); | |
EndProcedure | |
Procedure Clone_Repository(Repository, Cancel) | |
If Cancel Then | |
Return; | |
EndIf; | |
//If not Test_Path(Repository.RepoPath) Then | |
If Не Test_Path(Repository.RepoPath) Then | |
Message(""); | |
Message("Клонирование " + Repository.Description); | |
Message(""); | |
Arguments = New Array; | |
Arguments.Add("""" + Repository.URLPath + """"); | |
Arguments.Add("""" + Repository.RepoPath + """"); | |
//If not Run_Fossil("clone", Arguments, Repository.Path) Then | |
If Не Run_Fossil("clone", Arguments, Repository.Path) Then | |
//Cancel = true; | |
Cancel = Истина; | |
Raise "Не удалось клонировать " + Repository.Description; | |
EndIf; | |
EndIf; | |
EndProcedure | |
Procedure Open_Repository(Repository, Cancel) | |
If Cancel Then | |
Return; | |
EndIf; | |
Message("Opening: " + Repository.Path); | |
//If not Test_Path(Repository.Path + "\_fossil_") Then | |
If Не Test_Path(Repository.Path + "\_fossil_") Then | |
Arguments = New Array; | |
Arguments.Add("""" + Repository.RepoPath + """"); | |
//If not Run_Fossil("open", Arguments, Repository.Path) Then | |
If Не Run_Fossil("open", Arguments, Repository.Path) Then | |
//Cancel = true; | |
Cancel = Истина; | |
Raise "Не удалось открыть " + Repository.Description; | |
EndIf; | |
Else | |
Message("fossil open was skipped"); | |
//Cancel = Истина; | |
EndIf; | |
EndProcedure | |
Procedure Update_Repository(Repository, Cancel) | |
If Cancel Then | |
Return; | |
EndIf; | |
//If Test_Path(Repository.Path + "\_fossil_") Then | |
If Test_Path(Repository.Path + "\_fossil_") Then | |
Arguments = New Array; | |
Run_Fossil("pull", Arguments, Repository.Path); | |
Run_Fossil("update", Arguments, Repository.Path); | |
EndIf; | |
EndProcedure | |
Procedure Close_Repository(Repository, Cancel) | |
If Cancel Then | |
Return; | |
EndIf; | |
//If Test_Path(Repository.Path + "\_fossil_") Then | |
If Test_Path(Repository.Path + "\_fossil_") Then | |
Arguments = New Array; | |
Run_Fossil("close", Arguments, Repository.Path); | |
EndIf; | |
EndProcedure | |
//If CommandLineArguments.Count() = 1 Then | |
If АргументыКоманднойСтроки.Количество() = 1 Then | |
// script_Path = CommandLineArguments[0]; | |
script_Path = АргументыКоманднойСтроки[0]; | |
Else | |
script_Path = CurrentDirectory(); | |
EndIf; | |
Message(script_Path); | |
script_RepoPath = script_Path + "\repo"; | |
script_Fossil = script_Path + "\fossil.exe"; | |
//If not Test_Path(script_Path) Then | |
If не Test_Path(script_Path) Then | |
Raise "Каталог " + script_Path + " не найден. Скрипт остановлен!"; | |
EndIf; | |
//If not Test_Path(script_Fossil) Then | |
If не Test_Path(script_Fossil) Then | |
Raise "Не найден fossil.exe. Скрипт остановлен!"; | |
EndIf; | |
New_Folder(script_RepoPath); | |
Repositories = New Array; | |
Repositories.Add(New_Repository("core", "http://snegopat.ru:9004","репозиторий Снегопата 2.0", script_Path )); | |
//For Each Repository In Repositories Do | |
For Each Repository Из Repositories Do | |
//Cancel = False; | |
Cancel = Ложь; | |
Test_Repository(Repository, Cancel); | |
Clone_Repository(Repository, Cancel); | |
Open_Repository(Repository, Cancel); | |
Update_Repository(Repository, Cancel); | |
Close_Repository(Repository, Cancel); | |
EndDo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment