Skip to content

Commit 3612c15

Browse files
committed
Rewrote build script and wrapper and tests.
1 parent 857f356 commit 3612c15

26 files changed

+521
-1
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/python-redlines.iml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2024-present U.N. Owen <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Python Redlines
2+
3+
[![PyPI - Version](https://img.shields.io/pypi/v/python-redlines.svg)](https://pypi.org/project/python-redlines)
4+
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/python-redlines.svg)](https://pypi.org/project/python-redlines)
5+
6+
-----
7+
8+
**Table of Contents**
9+
10+
- [Installation](#installation)
11+
- [License](#license)
12+
13+
## Installation
14+
15+
```console
16+
pip install python-redlines
17+
```
18+
19+
## License
20+
21+
`python-redlines` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
22+
23+
Usage:
24+
25+
Setup project and create .net project in dir
26+
```
27+
dotnet new console
28+
```
29+
30+
Build app
31+
32+
```
33+
dotnet build
34+
```
35+
36+
Run via dotnet console
37+
```
38+
dotnet run [email protected] "/home/jman/Downloads/NVCA-Model-Document-Certificate-of-Incorporation.docx" "/home/jman/Downloads/Modified.docx" "/home/jman/Downloads/redline.docx"
39+
```
40+
41+
Package for linux
42+
```
43+
dotnet publish -c release -r linux-x64 --self-contained
44+
```
45+
46+
Package for windows
47+
```
48+
dotnet public -c release -r win-x64 --self-contained
49+
```
50+
51+
"Install" on Linux
52+
53+
1. Install .net for Linux (whatever distro you're using)
54+
2. Copy the Release contents from linux-x64 folder
55+
3. run `chmod 777 ./redlines`
56+
4. Then you can run `./redlines original_path.docx modified_path.docx`
57+
58+
More complete package and install directions:
59+
60+
https://ttu.github.io/dotnet-core-self-contained-deployments/
61+
62+
Archive and zip the release folder contents as .tar.gz, then distribute the archive. User install instructions would be:
63+
64+
```commandline
65+
$ mkdir redlines && cd redlines
66+
$ wget <github release url>
67+
$ tar -zxvf redlines-linux-x64.tar.gz
68+
$ chmod +x redlines
69+
$ ./redlines <author_tag> <original_path.docx> <modified_path.docx> <redline_path.docx>
70+
```
71+
72+
"Install" on Windows
73+
74+
TODO - run through this and document

build_differ.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import subprocess
2+
import os
3+
import tarfile
4+
import zipfile
5+
import sys
6+
7+
8+
def get_version():
9+
"""
10+
Extracts the version from the specified __about__.py file.
11+
"""
12+
about = {}
13+
with open('./src/python_redlines/__about__.py') as f:
14+
exec(f.read(), about)
15+
return about['__version__']
16+
17+
18+
def run_command(command):
19+
"""
20+
Runs a shell command and prints its output.
21+
"""
22+
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
23+
for line in process.stdout:
24+
print(line.decode().strip())
25+
26+
27+
def compress_files(source_dir, target_file):
28+
"""
29+
Compresses files in the specified directory into a tar.gz or zip file.
30+
"""
31+
if target_file.endswith('.tar.gz'):
32+
with tarfile.open(target_file, "w:gz") as tar:
33+
tar.add(source_dir, arcname=os.path.basename(source_dir))
34+
elif target_file.endswith('.zip'):
35+
with zipfile.ZipFile(target_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
36+
for root, dirs, files in os.walk(source_dir):
37+
for file in files:
38+
zipf.write(os.path.join(root, file),
39+
os.path.relpath(os.path.join(root, file),
40+
os.path.join(source_dir, '..')))
41+
42+
43+
def main():
44+
version = get_version()
45+
print(f"Version: {version}")
46+
47+
# Build for Linux
48+
print("Building for Linux...")
49+
run_command('dotnet publish ./csproj -c Release -r linux-x64 --self-contained')
50+
51+
# Build for Windows
52+
print("Building for Windows...")
53+
run_command('dotnet publish ./csproj -c Release -r win-x64 --self-contained')
54+
55+
# Compress the Linux build
56+
linux_build_dir = './csproj/bin/Release/net8.0/linux-x64'
57+
compress_files(linux_build_dir, f"./src/python_redlines/bin/linux-x64-{version}.tar.gz")
58+
59+
# Compress the Windows build
60+
windows_build_dir = './csproj/bin/Release/net8.0/win-x64'
61+
compress_files(windows_build_dir, f"./src/python_redlines/bin/win-x64-{version}.zip")
62+
63+
print("Build and compression complete.")
64+
65+
66+
if __name__ == "__main__":
67+
main()

csproj/Program.cs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.IO;
3+
using OpenXmlPowerTools;
4+
using DocumentFormat.OpenXml.Packaging;
5+
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
if (args.Length != 4)
11+
{
12+
Console.WriteLine("Usage: redlines <author_tag> <original_path.docx> <modified_path.docx> <redline_path.docx>");
13+
return;
14+
}
15+
16+
string authorTag = args[0];
17+
string originalFilePath = args[1];
18+
string modifiedFilePath = args[2];
19+
string outputFilePath = args[3];
20+
21+
if (!File.Exists(originalFilePath) || !File.Exists(modifiedFilePath))
22+
{
23+
Console.WriteLine("Error: One or both files do not exist.");
24+
return;
25+
}
26+
27+
try
28+
{
29+
var originalBytes = File.ReadAllBytes(originalFilePath);
30+
var modifiedBytes = File.ReadAllBytes(modifiedFilePath);
31+
var originalDocument = new WmlDocument(originalFilePath, originalBytes);
32+
Console.WriteLine(originalDocument);
33+
var modifiedDocument = new WmlDocument(modifiedFilePath, modifiedBytes);
34+
Console.WriteLine(modifiedDocument);
35+
var comparisonSettings = new WmlComparerSettings
36+
{
37+
AuthorForRevisions = authorTag,
38+
DetailThreshold = 0
39+
};
40+
41+
var comparisonResults = WmlComparer.Compare(originalDocument, modifiedDocument, comparisonSettings);
42+
Console.WriteLine(comparisonResults);
43+
var revisions = WmlComparer.GetRevisions(comparisonResults, comparisonSettings);
44+
Console.WriteLine(revisions);
45+
46+
// Output results
47+
Console.WriteLine($"Revisions found: {revisions.Count}");
48+
49+
File.WriteAllBytes(outputFilePath, comparisonResults.DocumentByteArray);
50+
}
51+
catch (Exception ex)
52+
{
53+
Console.WriteLine($"Error: {ex.Message}");
54+
Console.WriteLine("Detailed Stack Trace:");
55+
Console.WriteLine(ex.StackTrace);
56+
}
57+
}
58+
}
59+

csproj/bin/.gitignore

-1
This file was deleted.

csproj/redlines.csproj

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="DocumentFormat.OpenXml" Version="2.8.1" />
12+
<PackageReference Include="Open-Xml-PowerTools" Version="4.4.0" />
13+
</ItemGroup>
14+
15+
</Project>

csproj/redlines.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "redlines", "redlines.csproj", "{ABB1058B-B929-49BE-BFA7-3D93D8C7BFEA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{ABB1058B-B929-49BE-BFA7-3D93D8C7BFEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{ABB1058B-B929-49BE-BFA7-3D93D8C7BFEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{ABB1058B-B929-49BE-BFA7-3D93D8C7BFEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{ABB1058B-B929-49BE-BFA7-3D93D8C7BFEA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {EE9F0B5D-33E8-4477-BA5D-1C8F3EAA5CD8}
24+
EndGlobalSection
25+
EndGlobal

extract_version.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# extract_version.py
2+
def get_version():
3+
"""
4+
Extracts the version from the specified __about__.py file.
5+
"""
6+
about = {}
7+
with open('./src/python_redlines/__about__.py') as f:
8+
exec(f.read(), about)
9+
return about['__version__']
10+
11+
if __name__ == "__main__":
12+
print(get_version())

linux-x64-0.0.1.tar.gz

65.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)