+import os
+import sys
+import shutil
+from .tohtml import tohtml
+
+
+def read_file(file):
+ """
+ Read the contents of a file
+ :param file: The file to read
+ :return: The contents of the file
+ """
+ with open(file, "r") as f:
+ return f.read()
+
+
+def write_file(file, data):
+ """
+ Write data to a file
+ :param file: The file to write to
+ :param data: The data to write to the file
+ """
+ with open(file, "w") as f:
+ f.write(data)
+
+
+def main():
+ # Check if the user has given a directory as an argument
+ if len(sys.argv) != 2:
+ print("Please enter a directory as an argument")
+ sys.exit(1)
+
+ # Check if the directory given as an argument exists
+ if not os.path.isdir(sys.argv[1]):
+ print("The directory you entered does not exist")
+ sys.exit(1)
+
+ output_dir = "out"
+ if not os.path.exists(output_dir):
+ os.makedirs(output_dir)
+
+ for root, dirs, files in os.walk(sys.argv[1]):
+ dir = os.path.join(output_dir, root)
+ os.makedirs(dir)
+ for file in files:
+ if os.path.splitext(file)[1] == ".hbml":
+ html_data = tohtml(read_file(os.path.join(root, file)))
+
+ write_file(
+ os.path.join(dir, file.replace(".hbml", ".html")),
+ html_data,
+ )
+ else:
+ shutil.copy(os.path.join(root, file), dir)
+
+
+if __name__ == "__main__":
+ main()