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 committed Oct 29, 2020
2 parents 9086f58 + c407fab commit baf8ef5
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 23 deletions.
26 changes: 26 additions & 0 deletions etc/mepo-cd.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function mepo-cd () {
if [ "$#" -gt 1 ]; then
echo "usage: "
echo " mepo-cd : cd to root of mepo project"
echo " mepo-cd <component> : cd to directory of <component>"
echo ""
echo "mepo-cd accepts only 0 or 1 arguments"
return 1
fi
if [ "$1" = "-h" ]; then
echo "usage: "
echo " mepo-cd : cd to root of mepo project"
echo " mepo-cd <component> : cd to directory of <component>"
echo ""
echo "mepo-cd accepts only 0 or 1 arguments"
return 0
fi
if (( $# == 0 )); then
output=$(mepo whereis _root)
else
output=$(mepo whereis $1)
fi
if [ $? -eq 0 ]; then
cd $output
fi
}
1 change: 0 additions & 1 deletion mepo.d/command/diff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from state.state import MepoState
from repository.git import GitRepository
from utilities.version import version_to_string
from utilities import verify

from shutil import get_terminal_size
Expand Down
12 changes: 9 additions & 3 deletions mepo.d/command/status/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ def run(args):

def check_component_status(comp):
git = GitRepository(comp.remote, comp.local)

# version_to_string can strip off 'origin/' for display purposes
# so we save the "internal" name for comparison
internal_state_branch_name = git.get_version()[0]

# This can return non "origin/" names for detached head branches
curr_ver = version_to_string(git.get_version())
return (curr_ver, git.check_status())
return (curr_ver, internal_state_branch_name, git.check_status())

def print_status(allcomps, result):
orig_width = len(max([comp.name for comp in allcomps], key=len))
for index, comp in enumerate(allcomps):
time.sleep(0.025)
current_version, output = result[index]
current_version, internal_state_branch_name, output = result[index]
# Check to see if the current tag/branch is the same as the original
if comp.version.name not in current_version:
if comp.version.name not in internal_state_branch_name:
component_name = colors.RED + comp.name + colors.RESET
width = orig_width + len(colors.RED) + len(colors.RESET)
else:
Expand Down
9 changes: 6 additions & 3 deletions mepo.d/command/whereis/whereis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
from utilities import verify

def run(args):
root_dir = MepoState.get_root_dir()
allcomps = MepoState.read_state()
if args.comp_name: # single comp name is specified, print relpath
if args.comp_name == "_root":
# _root is a "hidden" allowed argument for whereis to return
# the root dir of the project. Mainly used by mepo-cd
print(MepoState.get_root_dir())
print(root_dir)
else:
verify.valid_components([args.comp_name], allcomps)
for comp in allcomps:
if comp.name == args.comp_name:
print(_get_relative_path(comp.local))
full_local_path=os.path.join(root_dir,comp.local)
print(_get_relative_path(full_local_path))
else: # print relpaths of all comps
max_namelen = len(max([x.name for x in allcomps], key=len))
FMT = '{:<%s.%ss} | {:<s}' % (max_namelen, max_namelen)
for comp in allcomps:
print(FMT.format(comp.name, _get_relative_path(comp.local)))
full_local_path=os.path.join(root_dir,comp.local)
print(FMT.format(comp.name, _get_relative_path(full_local_path)))

def _get_relative_path(local_path):
return os.path.relpath(local_path, os.getcwd())
23 changes: 16 additions & 7 deletions mepo.d/repository/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import subprocess

from state.state import MepoState
from utilities import shellcmd
from utilities import colors
from urllib.parse import urljoin
Expand All @@ -10,21 +11,29 @@ class GitRepository(object):
"""
Class to consolidate git commands
"""
__slots__ = ['__local', '__remote', '__git']
__slots__ = ['__local', '__full_local_path', '__remote', '__git']

def __init__(self, remote_url, local_path):
self.__local = local_path

if remote_url.startswith('..'):
rel_remote = os.path.basename(remote_url)
fixture_url = get_current_remote_url()
self.__remote = urljoin(fixture_url,rel_remote)
else:
self.__remote = remote_url
self.__git = 'git -C {}'.format(local_path)

root_dir = MepoState.get_root_dir()
full_local_path=os.path.join(root_dir,local_path)
self.__full_local_path=full_local_path
self.__git = 'git -C {}'.format(self.__full_local_path)

def get_local_path(self):
return self.__local

def get_full_local_path(self):
return self.__full_local_path

def get_remote_url(self):
return self.__remote

Expand Down Expand Up @@ -107,13 +116,13 @@ def create_branch(self, branch_name):
def create_tag(self, tag_name, annotate, message, tf_file=None):
if annotate:
if tf_file:
cmd = ['git', '-C', self.__local, 'tag', '-a', '-F', tf_file, tag_name]
cmd = ['git', '-C', self.__full_local_path, 'tag', '-a', '-F', tf_file, tag_name]
elif message:
cmd = ['git', '-C', self.__local, 'tag', '-a', '-m', message, tag_name]
cmd = ['git', '-C', self.__full_local_path, 'tag', '-a', '-m', message, tag_name]
else:
raise Exception("This should not happen")
else:
cmd = ['git', '-C', self.__local, 'tag', tag_name]
cmd = ['git', '-C', self.__full_local_path, 'tag', tag_name]
shellcmd.run(cmd)

def delete_branch(self, branch_name, force):
Expand Down Expand Up @@ -237,9 +246,9 @@ def unstage_file(self, myfile):

def commit_files(self, message, tf_file=None):
if tf_file:
cmd = ['git', '-C', self.__local, 'commit', '-F', tf_file]
cmd = ['git', '-C', self.__full_local_path, 'commit', '-F', tf_file]
elif message:
cmd = ['git', '-C', self.__local, 'commit', '-m', message]
cmd = ['git', '-C', self.__full_local_path, 'commit', '-m', message]
else:
raise Exception("This should not happen")
shellcmd.run(cmd)
Expand Down
4 changes: 2 additions & 2 deletions mepo.d/state/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __set_original_version(self, comp_details):

def to_component(self, comp_name, comp_details):
self.name = comp_name
self.local = os.path.abspath(comp_details['local'])
self.local = comp_details['local']
self.remote = comp_details['remote']
self.develop = comp_details.get('develop', None) # develop is optional
self.sparse = comp_details.get('sparse', None) # sparse is optional
Expand All @@ -45,7 +45,7 @@ def to_component(self, comp_name, comp_details):

def to_dict(self, start):
details = dict()
details['local'] = './' + os.path.relpath(self.local, start)
details['local'] = self.local
details['remote'] = self.remote
if self.version.type == 't':
details['tag'] = self.version.name
Expand Down
13 changes: 9 additions & 4 deletions mepo.d/state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ def write_state(cls, state_details):
new_state_file = os.path.join(state_dir, state_file_name)
with open(new_state_file, 'wb') as fout:
pickle.dump(state_details, fout, -1)
state_fileptr = os.path.join(state_dir, cls.__state_fileptr_name)
if os.path.isfile(state_fileptr):
os.remove(state_fileptr)
os.symlink(new_state_file, state_fileptr)
state_fileptr = cls.__state_fileptr_name
state_fileptr_fullpath = os.path.join(state_dir, state_fileptr)
if os.path.isfile(state_fileptr_fullpath):
os.remove(state_fileptr_fullpath)
#os.symlink(new_state_file, state_fileptr_fullpath)
curr_dir=os.getcwd()
os.chdir(state_dir)
os.symlink(state_file_name, state_fileptr)
os.chdir(curr_dir)
14 changes: 11 additions & 3 deletions mepo.d/utilities/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
MepoVersion = namedtuple('MepoVersion', ['name', 'type', 'detached'])

def version_to_string(version):
s = '({}) {}'.format(version[1], version[0])
if version[2]: # detached head
s += ' (DH)'
version_name = version[0]
version_type = version[1]
version_detached = version[2]

if version_detached: # detached head
# We remove the "origin/" from the internal detached branch name
# for clarity in mepo status output
version_name = version_name.replace('origin/','')
s = f'({version_type}) {version_name} (DH)'
else:
s = f'({version_type}) {version_name}'
return s

0 comments on commit baf8ef5

Please sign in to comment.