Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boilr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Die Migration und Wartungsarbeiten sind abgeschlossen.
Show more breadcrumbs
ifs
boilr
Commits
44e03bae
Commit
44e03bae
authored
9 years ago
by
Tamer Tas
Browse files
Options
Downloads
Patches
Plain Diff
Use boltdb for appdata
parent
97b2695b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/tmplt/configuration.go
+76
-0
76 additions, 0 deletions
pkg/tmplt/configuration.go
pkg/tmplt/db.go
+55
-0
55 additions, 0 deletions
pkg/tmplt/db.go
pkg/tmplt/errors.go
+8
-0
8 additions, 0 deletions
pkg/tmplt/errors.go
with
139 additions
and
0 deletions
pkg/tmplt/con
stants
.go
→
pkg/tmplt/con
figuration
.go
+
76
−
0
View file @
44e03bae
package
tmplt
import
(
"os"
"os/exec"
"path/filepath"
"github.com/tmrts/tmplt/pkg/util/exit"
"github.com/tmrts/tmplt/pkg/util/inpututil"
"github.com/tmrts/tmplt/pkg/util/osutil"
)
const
(
Version
=
"0.0.1"
)
var
(
ConfigPath
=
".tmpltrc"
Identifier
=
"tmplt"
DotIdentifier
=
"."
+
Identifier
AppDataDirPath
=
filepath
.
Join
(
"/var/lib"
,
Identifier
)
DBPath
=
filepath
.
Join
(
AppDataDirPath
,
"config.db"
)
ConfigDirPath
=
".tmplt/"
TemplateDirPath
=
".tmplt/templates/"
ConfigPath
=
DotIdentifier
+
"rc"
ConfigDirPath
=
DotIdentifier
TemplateDirPath
=
filepath
.
Join
(
DotIdentifier
,
"templates"
)
)
func
TemplatePath
(
name
string
)
(
string
,
error
)
{
...
...
@@ -21,10 +35,42 @@ func TemplatePath(name string) (string, error) {
func
init
()
{
homeDir
,
err
:=
osutil
.
GetUserHomeDir
()
if
err
!=
nil
{
panic
(
err
)
exit
.
Error
(
err
)
}
ConfigPath
=
filepath
.
Join
(
homeDir
,
ConfigPath
)
ConfigDirPath
=
filepath
.
Join
(
homeDir
,
ConfigDirPath
)
TemplateDirPath
=
filepath
.
Join
(
homeDir
,
TemplateDirPath
)
if
err
:=
osutil
.
DirExists
(
TemplateDirPath
);
os
.
IsNotExist
(
err
)
{
shouldInitialize
,
err
:=
inpututil
.
ScanYesOrNo
(
"Template directory doesn't exist. Initialize?"
,
true
)
if
err
!=
nil
{
exit
.
Error
(
err
)
}
if
shouldInitialize
{
if
err
:=
Initialize
();
err
!=
nil
{
exit
.
Error
(
err
)
}
}
else
{
exit
.
Error
(
ErrUninitializedTmpltDir
)
}
}
else
if
err
!=
nil
{
exit
.
Error
(
err
)
}
}
func
Initialize
()
error
{
dirs
:=
[]
string
{
DBPath
,
TemplateDirPath
,
}
for
_
,
path
:=
range
dirs
{
if
_
,
err
:=
exec
.
Command
(
"/usr/bin/mkdir"
,
"-p"
,
path
)
.
Output
();
err
!=
nil
{
return
err
}
}
return
initializeDB
()
}
This diff is collapsed.
Click to expand it.
pkg/tmplt/db.go
0 → 100644
+
55
−
0
View file @
44e03bae
package
tmplt
import
(
"os"
"time"
"github.com/boltdb/bolt"
"github.com/tmrts/tmplt/pkg/util/exit"
"github.com/tmrts/tmplt/pkg/util/osutil"
)
type
Configuration
struct
{
ConfigPath
string
ConfigDirPath
string
}
func
initializeDB
()
error
{
if
err
:=
osutil
.
FileExists
(
DBPath
);
!
os
.
IsNotExist
(
err
)
{
return
err
}
db
,
err
:=
bolt
.
Open
(
DBPath
,
0600
,
&
bolt
.
Options
{
Timeout
:
1
*
time
.
Second
})
if
err
!=
nil
{
return
err
}
else
{
defer
db
.
Close
()
}
return
db
.
Update
(
func
(
tx
*
bolt
.
Tx
)
error
{
_
=
tx
.
Bucket
([]
byte
(
"MyBucket"
))
return
nil
})
}
func
readConfig
()
(
Configuration
,
error
)
{
db
,
err
:=
bolt
.
Open
(
DBPath
,
0600
,
&
bolt
.
Options
{
Timeout
:
1
*
time
.
Second
})
if
err
!=
nil
{
exit
.
Error
(
err
)
}
else
{
defer
db
.
Close
()
}
var
conf
Configuration
err
=
db
.
View
(
func
(
tx
*
bolt
.
Tx
)
error
{
b
:=
tx
.
Bucket
([]
byte
(
"MyBucket"
))
conf
.
ConfigPath
=
string
(
b
.
Get
([]
byte
(
"configPath"
)))
conf
.
ConfigDirPath
=
string
(
b
.
Get
([]
byte
(
"configDirPath"
)))
return
nil
})
return
conf
,
err
}
This diff is collapsed.
Click to expand it.
pkg/tmplt/errors.go
0 → 100644
+
8
−
0
View file @
44e03bae
package
tmplt
import
"errors"
var
(
ErrTemplateAlreadyExists
=
errors
.
New
(
"tmplt: project template already exists"
)
ErrUninitializedTmpltDir
=
errors
.
New
(
"tmplt: .tmplt directory is not initialized"
)
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment