Skip to content

Commit

Permalink
Version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Hamilton-C committed Oct 3, 2023
1 parent 2c5325f commit 0f80dbf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to auto-rtf will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
auto-rtf uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# 1.1.0 - 2023-10-03
- Fixed some layout XML files not being included
- Added watermark to the top of the file
- This can be removed using the `--remove-watermark` or `-w` option
- This is here mostly to help with bug reports
- Added directory name to XML file headers
- Changed automatic project discovery to use current working directory rather than script directory
- This makes the script more command-line friendly

# 1.0.3 - 2023-09-18
- Fixed nav graphs not being included in the PDF
- Fixed macOS TextEdit not being able to open generated RTF files ([#1](https://github.com/Stephen-Hamilton-C/auto-rtf/issues/1))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Here are some helpful options:
- `--project-root`, `-p`: Specifies a root directory for an Android Studio project
- `--version`, `-v`: Displays the current version of auto-rtf
- `--report-bug`, `-b`: Opens the default web browser to report a bug
- `--remove-watermark`, `-w`: Removes the watermark placed at the top of the RTF file

To run this in the command line, use `python auto-rtf.py --help`
If that doesn't work, try `python3` instead of `python`.
Expand Down
21 changes: 17 additions & 4 deletions auto-rtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import argparse

# Constants
VERSION = "1.0.3"
VERSION = "1.1.0"
BUG_URL = "https://github.com/Stephen-Hamilton-C/auto-rtf/issues/new?assignees=Stephen-Hamilton-C&labels=&projects=&template=bug_report.md"
SCRIPT_PATH = __file__
SCRIPT_NAME = os.path.basename(SCRIPT_PATH)

# Setup argument parser
def getDefaultOutputFile():
parentDir = os.path.dirname(SCRIPT_PATH)
parentDir = os.getcwd()
parentDirName = os.path.basename(parentDir)
if parentDirName.startswith(".") and parentDirName.endswith("."):
parentDirName = os.path.basename(os.path.dirname(parentDir))
Expand All @@ -28,9 +28,10 @@ def getDefaultOutputFile():
# Setup arguments
parser = argparse.ArgumentParser(prog="auto-rtf", description="Compiles all Kotlin and relevant XML files from an Android Studio project and stuffs it into an RTF file. This can be used to export to PDF.", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-o", "--output-file", help="Specify file different file name or location. Default is script directory's name.", default=getDefaultOutputFile())
parser.add_argument("-p", "--project-root", help="Specify a different location for the Android Studio root.", default="./")
parser.add_argument("-p", "--project-root", help="Specify a different location for the Android Studio root.", default=os.getcwd())
parser.add_argument("-v", "--version", help="Prints current version", action="store_true")
parser.add_argument("-b", "--report-bug", help="Opens a web browser to report a bug", action="store_true")
parser.add_argument("-w", "--remove-watermark", help="Removes the watermark placed at the top of the RTF file", action="store_true")
args = vars(parser.parse_args())

# Open browser if report_bug option is present
Expand Down Expand Up @@ -79,7 +80,7 @@ def getDefaultOutputFile():
filePath = os.path.join(root, file)
ktFiles.append(filePath)
elif file.endswith(".xml"):
if root.endswith("layout") or root.endswith("navigation") or file == "strings.xml":
if "layout" in root or root.endswith("navigation") or file == "strings.xml":
filePath = os.path.join(root, file)
xmlFiles.append(filePath)

Expand All @@ -102,6 +103,11 @@ def codeToRTF(files) -> str:
# Set bold
rtf += "\\b "
# Insert file name to header
if file.lower().endswith(".xml"):
# Add directory name to xml files
fileDirectoryPath = os.path.dirname(file)
fileDirectoryName = os.path.basename(fileDirectoryPath)
rtf += fileDirectoryName + "/"
rtf += os.path.basename(file)
# End bold
rtf += "\\b0"
Expand Down Expand Up @@ -139,12 +145,19 @@ def codeToRTF(files) -> str:
\\margl1440\\margr1440\\vieww13440\\viewh7800\\viewkind0
\\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx4320\\tx5040\\tx5760\\tx6480\\tx7200\\tx7920\\tx8640\\pardirnatural\\partightenfactor0
"""
watermark = """\\fs16
This file was generated with auto-rtf version """ + VERSION + """\\line
\\line
"""
rtfFooter = "}\n"

# Create output file
with open(outputFilePath, 'w') as outputFile:
outputFile.write(rtfHeader)
if not args["remove_watermark"]:
outputFile.write(watermark)
outputFile.write(codeToRTF(ktFiles))
outputFile.write(codeToRTF(xmlFiles))
outputFile.write(rtfFooter)
Expand Down

0 comments on commit 0f80dbf

Please sign in to comment.