Skip to content

Commit

Permalink
Merge branch 'develop' into feature/mathomp4/#30-add-develop-override
Browse files Browse the repository at this point in the history
  • Loading branch information
mathomp4 authored Sep 18, 2020
2 parents 4da72cb + 1fcca03 commit 94cffb5
Show file tree
Hide file tree
Showing 27 changed files with 629 additions and 36 deletions.
40 changes: 40 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"license": "other-open",
"upload_type": "software",
"creators": [
{
"name": "Thompson, Matthew",
"affiliation": "GMAO SSAI",
"orcid": "0000-0001-6222-6863"
},
{
"name": "Chakraborty, Purnendu"
},
{
"name": "Clune, Tom",
"affiliation": "NASA",
"orcid": "0000-0003-3320-0204"
}
],
"contributors": [
{
"name": "Thompson, Matthew",
"affiliation": "GMAO SSAI",
"orcid": "0000-0001-6222-6863",
"type": "ContactPerson"
},
{
"name": "Clune, Tom",
"affiliation": "NASA",
"orcid": "0000-0003-3320-0204",
"type": "ProjectLeader"
}
],
"keywords": [
"git",
"repository",
"python",
"yaml"
],
"access_right": "open"
}
8 changes: 2 additions & 6 deletions mepo
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ if sys.version_info < (3, 6, 0):
MEPO_D = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mepo.d')
sys.path.insert(0, MEPO_D)

# Call top level function
from main import main
try:
if __name__ == '__main__':
from main import main
main()
except Exception as e:
traceback.print_exc()
sys.exit(1)
10 changes: 8 additions & 2 deletions mepo.d/cmdline/branch_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ def __init__(self, branch):
def __list(self):
brlist = self.branch_subparsers.add_parser(
'list',
description = 'List local branches of all components')
description = 'List local branches.'
'If no component is specified, runs over all components')
brlist.add_argument(
'-a', '--all',
action = 'store_true',
help = 'list all (local+remote) branches of all components')
help = 'list all (local+remote) branches')
brlist.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '*',
help = 'Component to list branches in')

def __create(self):
create = self.branch_subparsers.add_parser(
Expand Down
80 changes: 76 additions & 4 deletions mepo.d/cmdline/parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse

from cmdline.branch_parser import MepoBranchArgParser
from cmdline.stash_parser import MepoStashArgParser
from cmdline.tag_parser import MepoTagArgParser

class MepoArgParser(object):

Expand All @@ -19,12 +21,18 @@ def parse(self):
self.__clone()
self.__list()
self.__status()
self.__restore_state()
self.__diff()
self.__fetch()
self.__fetch_all()
self.__checkout()
self.__checkout_if_exists()
self.__branch()
self.__tag()
self.__stash()
self.__develop()
self.__pull()
self.__pull_all()
self.__compare()
self.__whereis()
self.__stage()
Expand Down Expand Up @@ -55,9 +63,21 @@ def __clone(self):
description = "Clone repositories.")
clone.add_argument(
'repo_url',
metavar = 'URL',
nargs = '?',
default = None,
help = 'URL to clone')
clone.add_argument(
'directory',
nargs = '?',
default = None,
help = "Directory to clone into (Only allowed with URL!)")
clone.add_argument(
'--branch','-b',
metavar = 'name',
nargs = '?',
default = None,
help = 'Branch/tag of URL to initially clone (Only allowed with URL!)')
clone.add_argument(
'--config',
metavar = 'config-file',
Expand All @@ -75,11 +95,24 @@ def __status(self):
'status',
description = 'Check current status of all components')

def __restore_state(self):
restore_state = self.subparsers.add_parser(
'restore-state',
description = 'Restores all components to the last saved state.')

def __diff(self):
diff = self.subparsers.add_parser(
'diff',
description = 'Diff all components')
diff.add_argument('--name-only', action = 'store_true', help = 'Show only names of changed files')
diff.add_argument(
'--name-only',
action = 'store_true',
help = 'Show only names of changed files')
diff.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '*',
help = 'Component to list branches in')

def __checkout(self):
checkout = self.subparsers.add_parser(
Expand All @@ -97,6 +130,7 @@ def __checkout_if_exists(self):
description = 'Switch to branch <branch-name> in any component where it is present. ')
checkout_if_exists.add_argument('branch_name', metavar = 'branch-name')
checkout_if_exists.add_argument('--quiet', action = 'store_true', help = 'Suppress found messages')
checkout_if_exists.add_argument('--dry-run','-n', action = 'store_true', help = 'Dry-run only (lists repos where branch exists)')

def __fetch(self):
fetch = self.subparsers.add_parser(
Expand All @@ -108,16 +142,50 @@ def __fetch(self):
fetch.add_argument('--prune','-p', action = 'store_true', help = 'Prune remote branches.')
fetch.add_argument('--tags','-t', action = 'store_true', help = 'Fetch tags.')

def __fetch_all(self):
fetch_all = self.subparsers.add_parser(
'fetch-all',
description = 'Download objects and refs from all components. '
'Specifying --all causes all remotes to be fetched.')
fetch_all.add_argument('--all', action = 'store_true', help = 'Fetch all remotes.')
fetch_all.add_argument('--prune','-p', action = 'store_true', help = 'Prune remote branches.')
fetch_all.add_argument('--tags','-t', action = 'store_true', help = 'Fetch tags.')

def __branch(self):
branch = self.subparsers.add_parser('branch')
branch = self.subparsers.add_parser(
'branch',
description = "Runs branch commands.")
MepoBranchArgParser(branch)

def __stash(self):
stash = self.subparsers.add_parser(
'stash',
description = "Runs stash commands.")
MepoStashArgParser(stash)

def __tag(self):
tag = self.subparsers.add_parser(
'tag',
description = "Runs tag commands.")
MepoTagArgParser(tag)

def __develop(self):
develop = self.subparsers.add_parser(
'develop',
description = "Checkout current version of 'develop' branches of specified components")
develop.add_argument('comp_name', metavar = 'comp-name', nargs = '+', default = None)


def __pull(self):
pull = self.subparsers.add_parser(
'pull',
description = "Pull branches of specified components")
pull.add_argument('comp_name', metavar = 'comp-name', nargs = '+', default = None)

def __pull_all(self):
pull_all = self.subparsers.add_parser(
'pull-all',
description = "Pull branches of all components (only those in non-detached HEAD state)")

def __compare(self):
compare = self.subparsers.add_parser(
'compare',
Expand Down Expand Up @@ -171,7 +239,11 @@ def __commit(self):
def __push(self):
push = self.subparsers.add_parser(
'push',
description = 'Push local commits to remote')
description = 'Push local commits or tags to remote')
push.add_argument(
'--tags',
action = 'store_true',
help = 'push tags')
push.add_argument(
'comp_name',
metavar = 'comp-name',
Expand Down
69 changes: 69 additions & 0 deletions mepo.d/cmdline/stash_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import argparse

class MepoStashArgParser(object):

def __init__(self, stash):
self.stash = stash.add_subparsers()
self.stash.title = 'mepo stash sub-commands'
self.stash.dest = 'mepo_stash_cmd'
self.stash.required = True
self.__push()
self.__list()
self.__pop()
self.__apply()
self.__show()

def __push(self):
stpush = self.stash.add_parser(
'push',
description = 'Push (create) stash in component <comp-name>')
stpush.add_argument(
'-m', '--message',
type=str,
metavar = 'message',
default=None,
help = 'Message for the stash')
stpush.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '+',
help = 'Component to push stash in')

def __show(self):
stshow = self.stash.add_parser(
'show',
description = 'show stash in component <comp-name>')
stshow.add_argument(
'-p', '--patch',
action = 'store_true',
help = 'Message for the stash')
stshow.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '+',
help = 'Component to show stash in')

def __list(self):
stlist = self.stash.add_parser(
'list',
description = 'List local stashes of all components')

def __pop(self):
stpop = self.stash.add_parser(
'pop',
description = 'Pop stash in component <comp-name>')
stpop.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '+',
help = 'Component to pop stash in')

def __apply(self):
stapply = self.stash.add_parser(
'apply',
description = 'apply stash in component <comp-name>')
stapply.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '+',
help = 'Component to apply stash in')
56 changes: 56 additions & 0 deletions mepo.d/cmdline/tag_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import argparse

class MepoTagArgParser(object):

def __init__(self, tag):
self.tag = tag.add_subparsers()
self.tag.title = 'mepo tag sub-commands'
self.tag.dest = 'mepo_tag_cmd'
self.tag.required = True
self.__list()
self.__create()
self.__delete()

def __list(self):
tglist = self.tag.add_parser(
'list',
description = 'List tags.'
'If no component is specified, runs over all components')
tglist.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '*',
help = 'Component to list tags in')

def __create(self):
create = self.tag.add_parser(
'create',
description = 'Create tag <tag-name> in component <comp-name>')
create.add_argument('tag_name', metavar = 'tag-name')
create.add_argument(
'-a', '--annotate',
action = 'store_true',
help = "Make an annotated tag")
create.add_argument(
'-m', '--message',
type=str,
metavar = 'message',
default = None,
help = "Message for the tag"
)
create.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '+',
help = 'Component to create tags in')

def __delete(self):
delete = self.tag.add_parser(
'delete',
description = 'Delete tag <tag-name> in component <comp-name>')
delete.add_argument('tag_name', metavar = 'tag-name')
delete.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '+',
help = 'Component to delete tags in')
13 changes: 11 additions & 2 deletions mepo.d/command/branch/brlist/brlist.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from state.state import MepoState
from utilities import verify
from repository.git import GitRepository

def run(args):
allcomps = MepoState.read_state()
max_namelen = len(max([x.name for x in allcomps], key=len))
comps2list = _get_comps_to_list(args.comp_name, allcomps)
max_namelen = len(max([x.name for x in comps2list], key=len))
FMT = '{:<%s.%ss} | {:<s}' % (max_namelen, max_namelen)
for comp in allcomps:
for comp in comps2list:
git = GitRepository(comp.remote, comp.local)
output = git.list_branch(args.all).rstrip().split('\n')
print(FMT.format(comp.name, output[0]))
for line in output[1:]:
print(FMT.format('', line))

def _get_comps_to_list(specified_comps, allcomps):
comps_to_list = allcomps
if specified_comps:
verify.valid_components(specified_comps, allcomps)
comps_to_list = [x for x in allcomps if x.name in specified_comps]
return comps_to_list
13 changes: 9 additions & 4 deletions mepo.d/command/checkout-if-exists/checkout-if-exists.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ def run(args):
status = git.verify_branch(branch)

if status == 0:
if not args.quiet:
print("Checking out branch %s in %s" %
(colors.YELLOW + branch + colors.RESET,
if args.dry_run:
print("Branch %s exists in %s" %
(colors.YELLOW + branch + colors.RESET,
colors.RESET + comp.name + colors.RESET))
git.checkout(branch)
else:
if not args.quiet:
print("Checking out branch %s in %s" %
(colors.YELLOW + branch + colors.RESET,
colors.RESET + comp.name + colors.RESET))
git.checkout(branch)
Loading

0 comments on commit 94cffb5

Please sign in to comment.