Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File hash #8

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3fd30a3
Update requirements_dev.txt
Beakerboy Jan 6, 2023
ed88576
Update test_excelAddinGenerator.py
Beakerboy Jan 6, 2023
09517f0
Update test_excelAddinGenerator.py
Beakerboy Jan 6, 2023
f2e064b
Update test_excelAddinGenerator.py
Beakerboy Jan 6, 2023
0c473e5
Update test_excelAddinGenerator.py
Beakerboy Jan 6, 2023
d138230
Update test_excelAddinGenerator.py
Beakerboy Jan 7, 2023
9065ef8
Merge branch 'master' into File-hash
Beakerboy Jan 7, 2023
89d5d4f
Create pyproject.toml
Beakerboy Nov 3, 2023
3dcea6f
Delete setup.py
Beakerboy Nov 3, 2023
c645058
Delete requirements_dev.txt
Beakerboy Nov 3, 2023
8e55906
Update python-package.yml
Beakerboy Nov 3, 2023
b26bc17
Update python-package.yml
Beakerboy Nov 3, 2023
bb4c916
Update python-package.yml
Beakerboy Nov 3, 2023
352999a
Update pyproject.toml
Beakerboy Nov 3, 2023
cd87b35
Rename excelAddinGenerator/__init__.py to src/excel_addin_generator/_…
Beakerboy Nov 3, 2023
4f4ea96
Rename excelAddinGenerator/main.py to src/excel_addin_generator/main.py
Beakerboy Nov 3, 2023
a9ed0dc
Update pyproject.toml
Beakerboy Nov 3, 2023
d8ae589
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
a4bd455
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
a8778bc
Update main.py
Beakerboy Nov 3, 2023
702c102
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
fb09895
Merge branch 'master' into File-hash
Beakerboy Nov 3, 2023
cfdefe8
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
67e936e
Update main.py
Beakerboy Nov 3, 2023
f3360e2
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
010d622
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
8e924c1
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
b1ce0f5
Update main.py
Beakerboy Nov 3, 2023
41d3e46
Update main.py
Beakerboy Nov 3, 2023
94a29dd
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
4f61371
Update main.py
Beakerboy Nov 3, 2023
0a2298b
Update main.py
Beakerboy Nov 3, 2023
4b94e26
Update main.py
Beakerboy Nov 3, 2023
c6ebfcd
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
18ccebb
Update main.py
Beakerboy Nov 3, 2023
9f87d07
Update main.py
Beakerboy Nov 3, 2023
3796dd6
Update main.py
Beakerboy Nov 3, 2023
007f1a9
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
47b9f68
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
41bfb7e
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
a272cd0
Update __init__.py
Beakerboy Nov 3, 2023
5050fc3
Update main.py
Beakerboy Nov 3, 2023
37fd60e
Delete tests/__init__.py
Beakerboy Nov 3, 2023
65d23bb
moved data
Nov 3, 2023
7783a24
Update main.py
Beakerboy Nov 3, 2023
1fa2f09
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
fd87e11
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
0655d8f
Create __main__.py
Beakerboy Nov 3, 2023
84f8df9
Update main.py
Beakerboy Nov 3, 2023
4554e10
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
539a0f4
Update main.py
Beakerboy Nov 3, 2023
5d42b37
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
8b30ff6
Update __main__.py
Beakerboy Nov 3, 2023
7fbe97a
Update __main__.py
Beakerboy Nov 3, 2023
966b346
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
74097b9
Update test_excelAddinGenerator.py
Beakerboy Nov 3, 2023
1bac080
Update __main__.py
Beakerboy Nov 3, 2023
ade2ff0
Update __main__.py
Beakerboy Nov 3, 2023
922ebb9
Update __main__.py
Beakerboy Nov 3, 2023
98bbf28
Update pyproject.toml
Beakerboy Nov 3, 2023
bb65297
Update pyproject.toml
Beakerboy Nov 3, 2023
42fcedc
Update pyproject.toml
Beakerboy Nov 3, 2023
5d3e00e
Update pyproject.toml
Beakerboy Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
Expand All @@ -16,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand All @@ -27,9 +26,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
pip install -e .[tests]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand All @@ -40,5 +37,26 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pytest --cov=excelAddinGenerator
pytest --cov=src
coveralls --service=github

flake8:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[tests]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --show-source --statistics
1 change: 0 additions & 1 deletion excelAddinGenerator/__init__.py

This file was deleted.

44 changes: 0 additions & 44 deletions excelAddinGenerator/main.py

This file was deleted.

37 changes: 37 additions & 0 deletions pyproject.toml
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]
"*" = ["*.xml", ".rels", "*.rels"]
7 changes: 0 additions & 7 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions src/excel_addin_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# None
24 changes: 24 additions & 0 deletions src/excel_addin_generator/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import argparse
import os
import sys
import excel_addin_generator.main as gen


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("input",
help="The input bin or xlam file.")
parser.add_argument("output",
help="The output path and file name.")
args = parser.parse_args()
base_path = os.path.dirname(__file__)
# check the extension on sys.argv[1] to determine which function to call
if args.input.endswith('.xlam'):
gen.createFromZip(args.input, base_path + '/data', args.output)
elif args.input.endswith('.bin'):
gen.create_from_bin(args.input, base_path + '/data', args.output)
else:
raise Exception(args.input, " is not a valid file format.")


main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions src/excel_addin_generator/main.py
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.")
1 change: 0 additions & 1 deletion tests/__init__.py

This file was deleted.

41 changes: 17 additions & 24 deletions tests/test_excelAddinGenerator.py
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")
Loading