Skip to content

Commit

Permalink
minor: works better with git
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Oct 23, 2012
1 parent c20c90d commit 119bbef
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/python/moa/plugin/system/moautil.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,24 @@ def cp(job, args):
if dirTo[-1] == '/':
dirTo = dirTo[:-1]

toBase = os.path.basename(dirTo)
if not os.path.exists(dirFrom):
moa.ui.exitError("Directory does not exists: %s" % dirFrom)

print toBase
toBase = os.path.basename(dirTo)

#print fromBase, toBase
# trick - the second argument is a number
# renumber the target directory
if re.match("^[0-9]+$", toBase) and re.match("^[0-9]+\..+$", fromBase):
print toBase, fromBase
toBase = re.sub("^[0-9]*\.", toBase + '.', fromBase)
dirTo = os.path.join(os.path.dirname(dirTo), toBase)

elif args.overwrite and os.path.exists(dirTo):
#if the 'to' directory exists - create a new sub directory
dirTo = os.path.join(dirTo, fromBase)

l.info("Copying from %s to %s" % (dirFrom, dirTo))

moa.ui.message("Copying %s to %s" % (dirFrom, dirTo))
sysConf.moautil.dirFrom = dirFrom
sysConf.moautil.dirTo = dirTo
if not args.recursive:
if not os.path.isdir(dirFrom):
moa.ui.exitError(
Expand Down Expand Up @@ -243,9 +243,13 @@ def _copyMoaDir(job, toDir):

def hook_git_finish_cp():
files = sysConf.moautil.get('filesCopied', [])
repo = sysConf.git.getRepo(sysConf.job)
repo.index.add(map(os.path.abspath, files))
repo.index.commit("moa cp %s" % " ".join(sysConf.newargs))
if len(files) == 0:
return

sysConf.git.callGit('git add -f %s' % " ".join(files))
sysConf.git.callGit("git commit -m 'moa cp %s %s' %s" % (
sysConf.moautil.dirFrom, sysConf.moautil.dirTo,
" ".join(files)))


@moa.args.argument('todir', metavar='to', nargs='?', help='copy to')
Expand Down

0 comments on commit 119bbef

Please sign in to comment.