constants: switch to pathlib

This makes the code a little simpler.

Change-Id: Id52a037fbf0330115844d9d95e7f4e4eb1fe16e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/docs/+/3369302
Tested-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Lizzy Presland <zland@google.com>
Commit-Queue: Lizzy Presland <zland@google.com>
diff --git a/constants/signals.py b/constants/signals.py
index 1438728..79ba1d5 100755
--- a/constants/signals.py
+++ b/constants/signals.py
@@ -11,7 +11,7 @@
 import argparse
 import ctypes
 import ctypes.util
-import os
+from pathlib import Path
 import re
 import subprocess
 import sys
@@ -19,6 +19,9 @@
 import constants
 
 
+# The directory where all the code & markdown files live.
+TOPDIR = Path(__file__).resolve().parent
+
 # The C library header to find symbols.
 HEADER = 'signal.h'
 
@@ -176,10 +179,8 @@
     md_data = get_md_table(baseline, aliases)
 
     if opts.inplace:
-        md_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
-                               MARKDOWN)
-        with open(md_file) as fp:
-            old_data = fp.readlines()
+        md_file = TOPDIR / MARKDOWN
+        old_data = md_file.read_text().splitlines(keepends=True)
 
         i = None
         for i, line in enumerate(old_data):
@@ -191,7 +192,7 @@
             sys.exit(1)
 
         old_data = old_data[0:i + 2]
-        with open(md_file, 'w') as fp:
+        with md_file.open('w') as fp:
             fp.writelines(old_data)
             fp.write('\n'.join(md_data) + '\n')
     else: