PEP8 and cosmetic changes.

main
Olivier Mangin 4 years ago
parent 7413926589
commit 526ed05c41
No known key found for this signature in database
GPG Key ID: D72FEC1C3120A884

@ -16,11 +16,13 @@ GITIGNORE = """# files or directories for the git plugin to ignore
class GitPlugin(PapersPlugin): class GitPlugin(PapersPlugin):
"""The git plugin creates a git repository in the pubs directory and commit the changes """Make the pubs repository also a git repository.
to the pubs repository everytime a paper is modified.
It also add the `pubs git` subcommand, so git commands can be executed in the git repository The git plugin creates a git repository in the pubs directory
from the command line. and commit the changes to the pubs repository.
It also add the `pubs git` subcommand, so git commands can be executed
in the git repository from the command line.
""" """
name = 'git' name = 'git'
@ -28,10 +30,10 @@ class GitPlugin(PapersPlugin):
def __init__(self, conf, ui): def __init__(self, conf, ui):
self.ui = ui self.ui = ui
self.pubsdir = os.path.expanduser(conf['main']['pubsdir']) self.pubsdir = os.path.expanduser(conf['main']['pubsdir'])
self.manual = conf['plugins'].get('git', {}).get('manual', False) self.manual = conf['plugins'].get('git', {}).get('manual', False)
self.force_color = conf['plugins'].get('git', {}).get('force_color', True) self.force_color = conf['plugins'].get('git', {}).get('force_color', True)
self.quiet = conf['plugins'].get('git', {}).get('quiet', True) self.quiet = conf['plugins'].get('git', {}).get('quiet', True)
self.list_of_changes = [] self.list_of_changes = []
self._gitinit() self._gitinit()
@ -72,17 +74,18 @@ class GitPlugin(PapersPlugin):
""" """
colorize = ' -c color.ui=always' if self.force_color else '' colorize = ' -c color.ui=always' if self.force_color else ''
git_cmd = 'git -C {}{} {}'.format(self.pubsdir, colorize, cmd) git_cmd = 'git -C {}{} {}'.format(self.pubsdir, colorize, cmd)
#print(git_cmd)
p = Popen(git_cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, shell=True) p = Popen(git_cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, shell=True)
output, err = p.communicate(input_stdin) output, err = p.communicate(input_stdin)
p.wait() p.wait()
if p.returncode != 0: if p.returncode != 0:
raise RuntimeError('The git plugin encountered an error when running the git command:\n' + raise RuntimeError((
'{}\n\nReturned output:\n{}\n'.format(git_cmd, output.decode('utf-8')) + 'The git plugin encountered an error when running the git command:\n'
'If needed, you may fix the state of the {} git repository '.format(self.pubsdir) + '{}\n\n'
'manually.\nIf relevant, you may submit a bug report at ' + 'Returned output:\n{}\n'
'https://github.com/pubs/pubs/issues') 'If needed, you may fix the state of the {} git repository manually.\n'
'If relevant, you may submit a bug report at https://github.com/pubs/pubs/issues'
).format(git_cmd, output.decode('utf-8'), self.pubsdir))
elif command: elif command:
self.ui.message(output.decode('utf-8'), end='') self.ui.message(output.decode('utf-8'), end='')
elif not self.quiet: elif not self.quiet:
@ -97,10 +100,11 @@ def paper_change_event(event):
git = GitPlugin.get_instance() git = GitPlugin.get_instance()
if not git.manual: if not git.manual:
event_desc = event.description event_desc = event.description
for a, b in [('\\','\\\\'), ('"','\\"'), ('$','\\$'), ('`','\\`')]: for a, b in [('\\', '\\\\'), ('"', '\\"'), ('$', '\\$'), ('`', '\\`')]:
event_desc = event_desc.replace(a, b) event_desc = event_desc.replace(a, b)
git.list_of_changes.append(event_desc) git.list_of_changes.append(event_desc)
@PostCommandEvent.listen() @PostCommandEvent.listen()
def git_commit(event): def git_commit(event):
if GitPlugin.is_loaded(): if GitPlugin.is_loaded():

@ -31,7 +31,7 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase):
self.execute_cmds([('pubs rename Page99a ABC',)]) self.execute_cmds([('pubs rename Page99a ABC',)])
hash_c = git_hash(self.default_pubs_dir) hash_c = git_hash(self.default_pubs_dir)
self.execute_cmds([('pubs remove ABC', ['y']),]) self.execute_cmds([('pubs remove ABC', ['y'])])
hash_d = git_hash(self.default_pubs_dir) hash_d = git_hash(self.default_pubs_dir)
self.execute_cmds([('pubs doc add testrepo/doc/Page99.pdf Page99',)]) self.execute_cmds([('pubs doc add testrepo/doc/Page99.pdf Page99',)])
@ -101,6 +101,5 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase):
self.assertNotEqual(hash_l, hash_m) self.assertNotEqual(hash_l, hash_m)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save