Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82ec4ff

Browse files
committed
initial commit
1 parent d03a8c8 commit 82ec4ff

File tree

15 files changed

+426
-0
lines changed

15 files changed

+426
-0
lines changed

golang/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
gomr: go [m]utli-[r]epository manager
2+
-----
3+
4+
gomr is a golang command-line tool used to execute arbitrary commands on a set of tagged directories.
5+
6+
## Features
7+
8+
* Configuration is stored in the registered directory (allows for version-controlled configuration)
9+
* Any arbitrary command can be run, no ties to version-control specific commands.
10+
11+
12+
## Installation
13+
14+
I'm not distributing binaries yet (TODO) for now checkout and `go install` to build the binary.
15+
16+
## Command Help
17+
18+
For help run:
19+
* `gomr --help`
20+
* `gomr register --help`
21+
* `gomr run --help`
22+
23+
## Ports
24+
25+
Pymr has been ported to ruby as [rumr](https://github.com/kpurdon/rumr) and python as [pymr](https://github.com/kpurdon/pymr).

golang/gomr.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"github.com/codegangsta/cli"
5+
"os"
6+
)
7+
8+
func main() {
9+
app := cli.NewApp()
10+
app.Name = "gomr"
11+
app.Author = "Kyle W. Purdon"
12+
app.Version = "0.0.1"
13+
app.Usage = "multi-repository manager in go"
14+
app.Commands = []cli.Command{
15+
{
16+
Name: "register",
17+
Usage: "register a directory",
18+
Action: register,
19+
Flags: []cli.Flag{
20+
cli.StringFlag{
21+
Name: "directory, d",
22+
Value: "./",
23+
Usage: "directory to tag",
24+
},
25+
cli.StringFlag{
26+
Name: "tag, t",
27+
Value: "default",
28+
Usage: "tag to add for directory",
29+
},
30+
cli.BoolFlag{
31+
Name: "append",
32+
Usage: "append the tag to an existing registered directory",
33+
},
34+
},
35+
},
36+
{
37+
Name: "run",
38+
Usage: "run a command",
39+
Action: run,
40+
Flags: []cli.Flag{
41+
cli.StringFlag{
42+
Name: "basepath, b",
43+
Value: "./",
44+
Usage: "path to begin the recursive search",
45+
},
46+
cli.StringFlag{
47+
Name: "tag, t",
48+
Value: "default",
49+
Usage: "tag to add for directory",
50+
},
51+
cli.BoolFlag{
52+
Name: "dryrun, d",
53+
Usage: "print (dont execute) the commands that will be run",
54+
},
55+
},
56+
},
57+
}
58+
59+
app.Run(os.Args)
60+
}

golang/register.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/codegangsta/cli"
6+
"github.com/robfig/config"
7+
"os"
8+
"path"
9+
"strings"
10+
)
11+
12+
func AppendIfMissing(slice []string, i string) []string {
13+
for _, ele := range slice {
14+
if ele == i {
15+
return slice
16+
}
17+
}
18+
return append(slice, i)
19+
}
20+
21+
func register(ctx *cli.Context) {
22+
23+
fn := path.Join(ctx.String("directory"), ".gomr")
24+
25+
newTags := strings.Split(ctx.String("tag"), ",")
26+
27+
if ctx.Bool("append") {
28+
if _, err := os.Stat(fn); err == nil {
29+
cfg, _ := config.ReadDefault(".gomr")
30+
curTags, _ := cfg.String("gomr", "tags")
31+
32+
for _, tag := range strings.Split(curTags, ",") {
33+
newTags = AppendIfMissing(newTags, tag)
34+
}
35+
} else {
36+
err := "append used, existing file not found."
37+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
38+
os.Exit(1)
39+
}
40+
}
41+
42+
outTags := strings.Join(newTags, ",")
43+
44+
outCfg := config.NewDefault()
45+
outCfg.AddSection("gomr")
46+
outCfg.AddOption("gomr", "tags", outTags)
47+
outCfg.WriteFile(fn, 0644, "gomr configuration file")
48+
49+
return
50+
}

golang/run.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/codegangsta/cli"
6+
"github.com/robfig/config"
7+
"os"
8+
"os/exec"
9+
"path/filepath"
10+
"strings"
11+
)
12+
13+
func RunGomr(ctx *cli.Context) filepath.WalkFunc {
14+
return func(path string, f os.FileInfo, err error) error {
15+
16+
tag := ctx.String("tag")
17+
dryrun := ctx.Bool("dryrun")
18+
19+
if len(ctx.Args()) == 0 {
20+
panic("no command given")
21+
}
22+
23+
command := ctx.Args()[0]
24+
25+
if strings.Contains(path, ".gomr") {
26+
27+
cfg, _ := config.ReadDefault(path)
28+
gomrTags, _ := cfg.String("gomr", "tags")
29+
30+
if strings.Contains(gomrTags, tag) {
31+
if dryrun {
32+
fmt.Printf("Would run %s in %s\n", command, filepath.Dir(path))
33+
} else {
34+
os.Chdir(filepath.Dir(path))
35+
cmd := exec.Command("sh", "-c", command)
36+
stdout, err := cmd.Output()
37+
38+
if err != nil {
39+
panic(err.Error())
40+
}
41+
42+
println(string(stdout))
43+
}
44+
}
45+
46+
}
47+
return nil
48+
}
49+
}
50+
51+
func run(ctx *cli.Context) {
52+
53+
root := ctx.String("basepath")
54+
filepath.Walk(root, RunGomr(ctx))
55+
56+
return
57+
}

python/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pymr: [Py]thon [m]utli-[r]epository Tool
2+
-----
3+
4+
PyMR is a python command-line tool used to execute arbitrary commands on a set of tagged directories.
5+
6+
## Features
7+
8+
* Configuration is stored in the registered directory (allows for version-controlled configuration)
9+
* Any arbitrary command can be run, no ties to version-control specific commands.
10+
11+
## Where is PyMR
12+
13+
PyMR source is available on [Github](https://github.com/kpurdon/pymr) and is released to [PyPI](https://pypi.python.org/pypi/pymr).
14+
15+
## Installation
16+
17+
From pypi: `pip install pymr`
18+
19+
From source:
20+
* `python setup.py install`
21+
22+
## Command Help
23+
24+
For help run:
25+
* `pymr --help`
26+
* `pymr register --help`
27+
* `pymr run --help`
28+
29+
## Ports
30+
31+
Pymr has been ported to ruby as [rumr](https://github.com/kpurdon/rumr) and go as [gomr](https://github.com/kpurdon/gomr).

python/pymr/__init__.py

Whitespace-only changes.

python/pymr/__init__.pyc

132 Bytes
Binary file not shown.

python/pymr/pymr.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import pickle
3+
import fnmatch
4+
from subprocess import call
5+
6+
import pathlib
7+
import click
8+
9+
10+
@click.group()
11+
def pymr():
12+
pass
13+
14+
15+
@pymr.command()
16+
@click.option('--directory', '-d', default='./')
17+
@click.option('--tag', '-t', multiple=True)
18+
@click.option('--append', is_flag=True)
19+
def register(directory, tag, append):
20+
'''
21+
register a directory
22+
'''
23+
24+
pymr_file = os.path.join(directory, '.pymr')
25+
new_tags = tag
26+
27+
if append:
28+
if os.path.exists(pymr_file):
29+
cur_tags = pickle.load(open(pymr_file))
30+
new_tags = tuple(set(new_tags + cur_tags))
31+
32+
pickle.dump(new_tags, open(pymr_file, 'wb'))
33+
34+
35+
@pymr.command()
36+
@click.argument('command')
37+
@click.option('--basepath', '-b', default='./')
38+
@click.option('--tag', '-t')
39+
@click.option('--dryrun', is_flag=True)
40+
def run(command, basepath, tag, dryrun):
41+
'''
42+
run a given command in matching sub-directories
43+
'''
44+
45+
for fn in pathlib.Path(basepath).glob('**/.pymr'):
46+
47+
with fn.open(mode='rb') as f:
48+
cur_tags = pickle.load(f)
49+
50+
parent_dir = str(fn.parent)
51+
52+
if tag in cur_tags:
53+
if dryrun:
54+
print('Would run {0} in {1}'.format(command, parent_dir))
55+
else:
56+
os.chdir(parent_dir)
57+
call(command, shell=True)
58+
59+
60+
if __name__ == '__main__':
61+
pymr()

python/pymr/pymr.pyc

1.91 KB
Binary file not shown.

python/setup.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from setuptools import setup, find_packages
2+
3+
classifiers = [
4+
'Environment :: Console',
5+
'Operating System :: OS Independent',
6+
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
7+
'Intended Audience :: Developers',
8+
'Programming Language :: Python',
9+
'Programming Language :: Python :: 2',
10+
'Programming Language :: Python :: 2.7'
11+
]
12+
13+
setuptools_kwargs = {
14+
'install_requires': [
15+
'click>=4,<5',
16+
'pathlib>=1,<2'
17+
],
18+
'entry_points': {
19+
'console_scripts': [
20+
'pymr = pymr.pymr:pymr',
21+
]
22+
}
23+
}
24+
25+
26+
setup(
27+
name='pymr',
28+
description='A tool for executing ANY command in a set of tagged directories.',
29+
author='Kyle W Purdon',
30+
author_email='[email protected]',
31+
url='https://github.com/kpurdon/pymr',
32+
download_url='https://github.com/kpurdon/pymr',
33+
version='2.0.1',
34+
packages=find_packages(),
35+
classifiers=classifiers,
36+
**setuptools_kwargs
37+
)

ruby/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'thor', '~>0.19.1'

ruby/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
rumr: [Ru]by [m]utli-[r]epository Tool
2+
-----
3+
4+
Rumr is a ruby command-line tool used to execute arbitrary commands on a set of tagged directories.
5+
6+
## Features
7+
8+
* Configuration is stored in the registered directory (allows for version-controlled configuration)
9+
* Any arbitrary command can be run, no ties to version-control specific commands.
10+
11+
12+
## Installation
13+
14+
From rubygems: `gem install rumr`
15+
16+
From source:
17+
* `gem build rumr.gemspec`
18+
* `gem install rumr-[version].gem`
19+
20+
## Command Help
21+
22+
For help run:
23+
* `rumr help`
24+
* `rumr help register`
25+
* `rumr help exec`
26+
27+
## Ports
28+
29+
rumr has been ported to python as [pymr](https://github.com/kpurdon/pymr) and go as [gomr](https://github.com/kpurdon/gomr).

ruby/bin/rumr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'rumr'
4+
5+
Rumr.start(ARGV)

0 commit comments

Comments
 (0)