client: Ending newline
Text files always have a final "\n" character. Add it before running the editor, otherwise, it will automatically add it and we would think the file has changed.
This commit is contained in:
parent
f9956f913a
commit
3ff1608c0a
1 changed files with 8 additions and 3 deletions
11
client.py
11
client.py
|
@ -561,12 +561,17 @@ def editor(texte, annotations=u""):
|
||||||
atexit.register(f.close)
|
atexit.register(f.close)
|
||||||
if annotations:
|
if annotations:
|
||||||
annotations = "# " + annotations.replace("\n", "\n# ")
|
annotations = "# " + annotations.replace("\n", "\n# ")
|
||||||
f.write((texte + "\n" + annotations).encode("utf-8"))
|
# Usually, there is already an ending newline in a text document
|
||||||
|
if texte[-1] != '\n':
|
||||||
|
annotations = '\n' + annotations
|
||||||
|
else:
|
||||||
|
annotations += '\n'
|
||||||
|
f.write((texte + annotations).encode("utf-8"))
|
||||||
f.flush()
|
f.flush()
|
||||||
proc = subprocess.Popen([os.getenv('EDITOR', '/usr/bin/editor'), f.name])
|
proc = subprocess.Popen([os.getenv('EDITOR', '/usr/bin/editor'), f.name])
|
||||||
os.waitpid(proc.pid, 0)
|
os.waitpid(proc.pid, 0)
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
ntexte = f.read().decode("utf-8")
|
ntexte = f.read().decode("utf-8", errors='ignore')
|
||||||
f.close()
|
f.close()
|
||||||
ntexte = u'\n'.join(filter(lambda l: not l.startswith('#'), ntexte.split('\n')))
|
ntexte = u'\n'.join(filter(lambda l: not l.startswith('#'), ntexte.split('\n')))
|
||||||
return ntexte
|
return ntexte
|
||||||
|
@ -718,7 +723,7 @@ Enregistrez le fichier vide pour annuler.\n"""
|
||||||
# On peut vouloir chiffrer un fichier sans avoir la possibilité de le lire
|
# On peut vouloir chiffrer un fichier sans avoir la possibilité de le lire
|
||||||
# dans le futur, mais dans ce cas on préfère demander confirmation
|
# dans le futur, mais dans ce cas on préfère demander confirmation
|
||||||
if not any(r + '-w' in my_roles for r in new_roles):
|
if not any(r + '-w' in my_roles for r in new_roles):
|
||||||
message = u"""Vous vous apprêtez à perdre vos droits d'écritures""" + \
|
message = u"""Vous vous apprêtez à perdre vos droits en écriture""" + \
|
||||||
"""(ROLES ne contient rien parmi : %s) sur ce fichier, continuer ?"""
|
"""(ROLES ne contient rien parmi : %s) sur ce fichier, continuer ?"""
|
||||||
message = message % (", ".join(r[:-2] for r in my_roles if '-w' in r),)
|
message = message % (", ".join(r[:-2] for r in my_roles if '-w' in r),)
|
||||||
if not confirm(options, message):
|
if not confirm(options, message):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue