-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
136 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[build-system] | ||
requires = ["setuptools>=61.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "excel_addin_generator" | ||
version = "0.0.1" | ||
authors = [ | ||
{ name="Kevin Nowaczyk", email="beakerboy99@yahoo.com" }, | ||
] | ||
description = "Create an Excel addin with python." | ||
readme = "README.md" | ||
requires-python = ">=3.7" | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
] | ||
[project.optional-dependencies] | ||
tests = [ | ||
'coveralls', | ||
'filehash', | ||
'flake8-annotations', | ||
'pytest', | ||
'pytest-cov' | ||
] | ||
[project.urls] | ||
"Homepage" = "https://github.com/Beakerboy/vbaProject-Compiler" | ||
"Bug Tracker" = "https://github.com/Beakerboy/vbaProject-Compiler/issues" | ||
|
||
[tool.pytest.ini_options] | ||
pythonpath = "src" | ||
testpaths = [ | ||
"tests", | ||
] | ||
[tool.setuptools.package-data] | ||
"*" = ["*.cls"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
import sys | ||
import excel_addin_generator.main as gen | ||
|
||
|
||
def main() -> None: | ||
args = [] | ||
base_path = os.path.dirname(__file__) | ||
args[1] = sys.argv[1] | ||
args[2] = sys.argv[2] | ||
if len(args) > 2: | ||
# check the extension on sys.argv[1] to determine which function to call | ||
input_file = args[1] | ||
output_file_name = args[2] | ||
if input_file.endswith('.xlam'): | ||
gen.createFromZip(input_file, base_path + '/data', output_file_name) | ||
elif input_file.endswith('.bin'): | ||
gen.create_from_bin(input_file, base_path + '/data', output_file_name) | ||
else: | ||
raise Exception(input_file, " is not a valid file format.") | ||
|
||
|
||
main() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import shutil | ||
import sys | ||
import zipfile | ||
|
||
|
||
def create_from_bin(input_file: str, wrapper_dir: str, output_file_name: str) -> None: | ||
|
||
"""Create a zip file containing the provided bin""" | ||
# file must start with 'd0 cf 11 e0 a1 b1 1a e1' | ||
fileSig = open(input_file, "rb").read(8).hex() | ||
if fileSig != 'd0cf11e0a1b11ae1': | ||
raise Exception('File signature {} is not as expected.', format(fileSig)) | ||
shutil.copy(input_file, wrapper_dir + "/xl/vbaProject.bin") | ||
shutil.make_archive(output_file_name, 'zip', wrapper_dir) | ||
shutil.move(output_file_name + ".zip", output_file_name) | ||
|
||
|
||
def createFromZip(input_file: str, wrapper_dir: str, output_file_name: str) -> None: | ||
|
||
"""Create a zip file containing the bin file within the provided zip file""" | ||
extractBinFromZip(input_file) | ||
create_from_bin('xl/vbaProject.bin', wrapper_dir, output_file_name) | ||
|
||
|
||
def extractBinFromZip(input_file: str) -> None: | ||
|
||
# check that input is a zip file | ||
if zipfile.is_zipfile(input_file): | ||
# check that the zip archive contains /xl/vbaProject.bin | ||
with zipfile.ZipFile(input_file, 'r') as zip: | ||
zip.extract('xl/vbaProject.bin') | ||
else: | ||
raise Exception(input_file, " is not a valid file format.") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
# test_excelAddinGenerator.py | ||
|
||
import excel_addin_generator.main | ||
import pytest | ||
from excelAddinGenerator.main import * | ||
from os.path import exists | ||
from filehash import FileHash | ||
|
||
def test_success_from_bin(): | ||
|
||
def test_success_from_bin() -> None: | ||
"""Test that xlam is successfully generated from a OLE file""" | ||
createFromBin("tests/vbaProject.bin", "src/data", "success_bin.xlam") | ||
excel_addin_generator.main.create_from_bin("tests/vbaProject.bin", "src/excel_addin_generator/data", "success_bin.xlam") | ||
# Assert that xlam file is created | ||
assert exists("success_bin.xlam") | ||
#assert that bin file within success_bin.xlam matches tests/vbaProject.bin | ||
extractBinFromZip("success_bin.xlam") | ||
# assert that bin file within success_bin.xlam matches tests/vbaProject.bin | ||
excel_addin_generator.main.extractBinFromZip("success_bin.xlam") | ||
md5hasher = FileHash('md5') | ||
assert md5hasher.hash_file("tests/vbaProject.bin") == md5hasher.hash_file("xl/vbaProject.bin") | ||
|
||
createFromZip("success_bin.xlam", "src/data", "success_xlam.xlam") | ||
excel_addin_generator.main.createFromZip("success_bin.xlam", "src/excel_addin_generator/data", "success_xlam.xlam") | ||
assert exists("success_xlam.xlam") | ||
#assert that bin file within success_xlam.xlam matches bin file within success_bin.xlam | ||
extractBinFromZip("success_xlam.xlam") | ||
# assert that bin file within success_xlam.xlam matches bin file within success_bin.xlam | ||
excel_addin_generator.main.extractBinFromZip("success_xlam.xlam") | ||
assert md5hasher.hash_file("tests/vbaProject.bin") == md5hasher.hash_file("xl/vbaProject.bin") | ||
|
||
def test_not_bin_exception(): | ||
|
||
|
||
def test_not_bin_exception() -> None: | ||
""" Test that an exception is thrown if the bin file is not an OLE file""" | ||
with pytest.raises(Exception) as e_info: | ||
createFromBin("tests/blank.bin", "src/data", "./fail.xlam") | ||
|
||
def test_xlam_not_zip(): | ||
""" Test that an exception is thrown if the zip is not a zip archive""" | ||
with pytest.raises(Exception) as e_info: | ||
createFromZip("tests/blank.bin", "src/data", "./fail.xlam") | ||
with pytest.raises(Exception): | ||
excel_addin_generator.main.createFromBin("tests/blank.bin", "src/excel_addin_generator/data", "./fail.xlam") | ||
|
||
def test_main(): | ||
main(["./excelAddinGenerator", "./tests/vbaProject.bin", "success_bin.xlam"]) | ||
main(["./excelAddinGenerator", "success_bin.xlam", "success_xlam.xlam"]) | ||
|
||
def test_main_incorrect_type(): | ||
def test_xlam_not_zip() -> None: | ||
""" Test that an exception is thrown if the zip is not a zip archive""" | ||
with pytest.raises(Exception) as e_info: | ||
main(["./excelAddinGenerator", "./src/data/xl/styles.xml", "fail.xlam"]) | ||
with pytest.raises(Exception): | ||
excel_addin_generator.main.createFromZip("tests/blank.bin", "src/excel_addin_generator/data", "./fail.xlam") |