forked from LazarenkoA/1C2GIT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
добавлена возможность работы с MongoDB, в веб интерфейс добавил диагр…
…амму, добавил пример конфигов
- Loading branch information
1 parent
399cb48
commit 1f4f6a0
Showing
8 changed files
with
538 additions
and
217 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,154 @@ | ||
package settings | ||
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
logrusRotate "github.com/LazarenkoA/LogrusRotate" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
"regexp" | ||
|
||
"github.com/sirupsen/logrus" | ||
xmlpath "gopkg.in/xmlpath.v2" | ||
) | ||
|
||
|
||
type RepositoryConf struct { | ||
TimerMinute int `json:"TimerMinute"` | ||
From *struct { | ||
Rep string `json:"Rep"` | ||
Login string `json:"Login"` | ||
Pass string `json:"Pass"` | ||
Extension bool `json:"Extension"` | ||
} `json:"From"` | ||
To *struct { | ||
RepDir string `json:"RepDir"` | ||
Branch string `json:"Branch"` | ||
} `json:"To"` | ||
version string // для хранения версии конфигурации | ||
} | ||
|
||
type Setting struct { | ||
Bin1C string `json:"Bin1C"` | ||
RepositoryConf []*RepositoryConf `json:"RepositoryConf"` | ||
Mongo *struct{ | ||
ConnectionString string | ||
} `json:"Mongo"` | ||
} | ||
|
||
func ReadSettings(Filepath string, data interface{}) { | ||
if _, err := os.Stat(Filepath); os.IsNotExist(err) { | ||
logrus.WithField("файл", Filepath).Panic("Конфигурационный файл не найден") | ||
logrusRotate.StandardLogger().WithField("файл", Filepath).Panic("Конфигурационный файл не найден") | ||
return | ||
} | ||
|
||
file, err := ioutil.ReadFile(Filepath) | ||
if err != nil { | ||
logrus.WithField("файл", Filepath).WithError(err).Panic("Ошибка открытия файла") | ||
logrusRotate.StandardLogger().WithField("файл", Filepath).WithError(err).Panic("Ошибка открытия файла") | ||
return | ||
} | ||
|
||
err = json.Unmarshal(file, data) | ||
if err != nil { | ||
logrus.WithField("файл", Filepath).WithError(err).Panic("Ошибка чтения конфигурационного файла") | ||
logrusRotate.StandardLogger().WithField("файл", Filepath).WithError(err).Panic("Ошибка чтения конфигурационного файла") | ||
return | ||
} | ||
} | ||
|
||
|
||
func (r *RepositoryConf) GetRepPath() string { | ||
return r.From.Rep | ||
} | ||
|
||
func (r *RepositoryConf) GetLogin() string { | ||
return r.From.Login | ||
} | ||
|
||
func (r *RepositoryConf) GetPass() string { | ||
return r.From.Pass | ||
} | ||
|
||
func (r *RepositoryConf) IsExtension() bool { | ||
return r.From.Extension | ||
} | ||
|
||
func (r *RepositoryConf) GetOutDir() string { | ||
return r.To.RepDir | ||
} | ||
|
||
func (this *RepositoryConf) SaveVersion() { | ||
logrusRotate.StandardLogger().WithField("Репозиторий", this.To.RepDir).WithField("Версия", this.version).Debug("Сохраняем версию расширения") | ||
|
||
ConfigurationFile := path.Join(this.To.RepDir, "Configuration.xml") | ||
if _, err := os.Stat(ConfigurationFile); os.IsNotExist(err) { | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).WithField("Репозиторий", this.GetRepPath()).Error("Конфигурационный файл (Configuration.xml) не найден") | ||
return | ||
} | ||
|
||
file, err := os.Open(ConfigurationFile) | ||
if err != nil { | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).WithField("Репозиторий", this.GetRepPath()).Errorf("Ошибка открытия: %q", err) | ||
return | ||
} | ||
defer file.Close() | ||
|
||
xmlroot, xmlerr := xmlpath.Parse(bufio.NewReader(file)) | ||
if xmlerr != nil { | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).Errorf("Ошибка чтения xml: %q", xmlerr.Error()) | ||
return | ||
} | ||
|
||
path := xmlpath.MustCompile("MetaDataObject/Configuration/Properties/Version/text()") | ||
if value, ok := path.String(xmlroot); ok { | ||
this.version = value | ||
} else { | ||
// значит версии нет, установим начальную | ||
this.version = "1.0.0" | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).Debugf("В файле не было версии, установили %q", this.version) | ||
} | ||
|
||
} | ||
|
||
func (this *RepositoryConf) RestoreVersion() { | ||
logrusRotate.StandardLogger().WithField("Репозиторий", this.To.RepDir).WithField("Версия", this.version).Debug("Восстанавливаем версию расширения") | ||
|
||
ConfigurationFile := path.Join(this.To.RepDir, "Configuration.xml") | ||
if _, err := os.Stat(ConfigurationFile); os.IsNotExist(err) { | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).WithField("Репозиторий", this.GetRepPath()).Error("Конфигурационный файл (Configuration.xml) не найден") | ||
return | ||
} | ||
|
||
// Меняем версию, без парсинга, поменять значение одного узла прям проблема, а повторять структуру xml в классе ой как не хочется | ||
// Читаем файл | ||
file, err := os.Open(ConfigurationFile) | ||
if err != nil { | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).Errorf("Ошибка открытия файла: %q", err) | ||
return | ||
} | ||
|
||
stat, _ := file.Stat() | ||
buf := make([]byte, stat.Size()) | ||
if _, err = file.Read(buf); err != nil { | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).Errorf("Ошибка чтения файла: %q", err) | ||
return | ||
} | ||
file.Close() | ||
os.Remove(ConfigurationFile) | ||
|
||
xml := string(buf) | ||
reg := regexp.MustCompile(`(?i)(?:<Version>(.+?)<\/Version>|<Version\/>)`) | ||
xml = reg.ReplaceAllString(xml, "<Version>"+this.version+"</Version>") | ||
|
||
// сохраняем файл | ||
file, err = os.OpenFile(ConfigurationFile, os.O_CREATE, os.ModeExclusive) | ||
if err != nil { | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).Errorf("Ошибка создания: %q", err) | ||
return | ||
} | ||
defer file.Close() | ||
|
||
if _, err := file.WriteString(xml); err != nil { | ||
logrusRotate.StandardLogger().WithField("Файл", ConfigurationFile).Errorf("Ошибка записи: %q", err) | ||
return | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
"Mongo": { | ||
"ConnectionString": "mongodb://127.0.0.1:27017" | ||
}, | ||
"Bin1C": "C:\Program Files\1cv8\8.3.14.1694\bin\1cv8.exe", | ||
"RepositoryConf": [ | ||
{ | ||
"TimerMinute": 30, | ||
"From": { | ||
"Rep": "tcp://server/HRM_Extention", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\HRM_Extention", | ||
"Branch": "Dev" | ||
} | ||
}, | ||
{ | ||
"TimerMinute": 30440, | ||
"From": { | ||
"Rep": "tcp://server/NSI_Extention", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\NSI_Extention", | ||
"Branch": "Dev" | ||
} | ||
}, | ||
{ | ||
"TimerMinute": 30, | ||
"From": { | ||
"Rep": "tcp://server/BPMN", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\BPMN", | ||
"Branch": "Dev" | ||
} | ||
}, | ||
{ | ||
"TimerMinute": 30, | ||
"From": { | ||
"Rep": "tcp://server/ACC_Extention", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\ACC_Extention", | ||
"Branch": "Dev" | ||
} | ||
}, | ||
{ | ||
"TimerMinute": 30, | ||
"From": { | ||
"Rep": "tcp://server/SM_Extention", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\SM_Extention", | ||
"Branch": "Dev" | ||
} | ||
}, | ||
{ | ||
"TimerMinute": 30, | ||
"From": { | ||
"Rep": "tcp://server/Common", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\Common", | ||
"Branch": "Dev" | ||
} | ||
}, | ||
{ | ||
"TimerMinute": 30, | ||
"From": { | ||
"Rep": "tcp://server/HRM_Sheet_extension", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\HRM_Sheet", | ||
"Branch": "Dev" | ||
} | ||
}, | ||
{ | ||
"TimerMinute": 30, | ||
"From": { | ||
"Rep": "tcp://server/HRM_WorkTime", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\HRM_WorkTime", | ||
"Branch": "Dev" | ||
} | ||
}, | ||
{ | ||
"TimerMinute": 30, | ||
"From": { | ||
"Rep": "tcp://server/nsi_extension", | ||
"Extension": true, | ||
"Login": "Insolent", | ||
"Pass": "123" | ||
}, | ||
"To": { | ||
"RepDir": "C:\Git\\Extensions\NSI_EXTENSION", | ||
"Branch": "Dev" | ||
} | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"Insolent": "Insolent.AN <[email protected]>", | ||
"Ivanov": "Ivanov <[email protected]>", | ||
"hamstrings": "hamstrings.MG <[email protected]>", | ||
"Default": "Anonymous <[email protected]>" | ||
} |
Oops, something went wrong.