Skip to content

Commit

Permalink
Change name to utf8csv
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Carey committed May 15, 2022
1 parent 3edd6fe commit fd2871a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 210 deletions.
41 changes: 12 additions & 29 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Select Python, click the "Always use this program" checkbox and "OK".
### Setup
- Clone repository
- Create virtual environment
- `python -m pip install pytest black -e .`
- `python -m pip install pytest black pyinstaller -e .`

### Format
```shell
black -l 120 D:\PycharmProjects\openCSV
black -l 120 project\utf8csv
```

### Test
Expand All @@ -23,35 +23,18 @@ pytest

# Build

### Compiling `eventlog.mc` into `eventlog.dll`

First install Microsoft Visual Studio Community with the C++ and Windows SDK options.
On my system, `mc.exe` and `rc.exe` are then found at
`C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x86\`, and `link.exe` is found at
`C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX86\x86\`.

In Visual Studio Community, go to `Tools > Command Line > Developer Command Prompt` to
run these commands, they will be on the path.

```shell
# CD to project directory
cd /project/openCSV
# Compile messages file to .rc/.bin files
mc.exe src/eventlog.mc
# Compile those files to resource file
rc.exe /r eventlog.rc
# Link resource file to dll file
link.exe -dll -noentry -out:src/eventlog.dll eventlog.res
# remove intermediate files
rm eventlog.* MSG*.bin
```

### Creating .exe file
### Creating .exe file with PyInstaller
```shell
# CD to project directory
cd project\openCSV
cd project\utf8csv
# run PyInstaller
pyinstaller.exe --onefile --noconfirm --ascii --windowed --name opencsv --add-binary "src\eventlog.dll;eventlog.dll" .\src\opencsv\main.py
pyinstaller.exe --onefile --noconfirm --ascii --windowed --name utf8csv .\src\utf8csv\main.py
# ... or ...
pyinstaller.exe --onefile opencsv.spec
pyinstaller.exe --onefile utf8csv.spec
```

# Roadmap
- update logging (maybe file rotate)
- add simple tkinter windows for install/uninstall/options/(view logs)
- options: import encoding default on/off
- options: strip bom after close on/off
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from setuptools import setup, find_packages

setup(
name="openCSV",
name="utf8csv",
version="2022.05",
description="Open CSV file with UTF-8 encoding",
description="Open CSV files in Excel with UTF-8 encoding",
author="Joe Carey",
author_email="[email protected]",
author_email="[email protected]",
packages=find_packages(where="src"),
package_dir={"": "src"},
install_requires=["pywin32==304"],
Expand Down
Binary file removed src/eventlog.dll
Binary file not shown.
167 changes: 0 additions & 167 deletions src/eventlog.mc

This file was deleted.

File renamed without changes.
11 changes: 5 additions & 6 deletions src/opencsv/main.py → src/utf8csv/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from argparse import ArgumentParser
import logging
# from logging.handlers import NTEventLogHandler
import os
from pathlib import Path
import pythoncom
Expand All @@ -26,7 +25,7 @@
)

EXE = sys.executable
REG_NAME = "open_csv_utf8"
REG_NAME = "utf8csv"
ICON_PATH = "Excel.CSV\\DefaultIcon"
USER_PATH = "Software\\Classes"
SEARCH_PATHS = [(HKEY_CURRENT_USER, USER_PATH), (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes"), (HKEY_CLASSES_ROOT, "")]
Expand Down Expand Up @@ -62,13 +61,13 @@ def setup(self, dry_run: bool) -> None:
"""Set this program as the default handler for CSV files"""
if not self._run_as_script:
# copy this program to %LOCALAPPDATA%\{REG_NAME}
from shutil import copy
from shutil import copy, SameFileError

src = Path(self._program)
dst = Path(os.getenv("LOCALAPPDATA")) / (REG_NAME + src.suffix)
try:
copy(src, dst)
except shutil.SameFileError:
except SameFileError:
pass
self._program = str(dst)
logging.debug(f"Runner command: {self._command}")
Expand Down Expand Up @@ -287,10 +286,10 @@ def strip_bom(file: Path):

def main() -> None:
"""Set up CLI arguments and options"""
log_file = Path(EXE).with_name("opencsv.log")
log_file = Path(EXE).with_name("utf8csv.log")
logging.basicConfig(filename=log_file, encoding="utf-8", level=logging.WARNING)
logging.debug(f"Call: {sys.argv}")
parser = ArgumentParser(epilog="Thank you for using OpenCSV!")
parser = ArgumentParser(epilog="Thank you for using utf8csv!")
group = parser.add_mutually_exclusive_group()
group.add_argument("file", help="open this CSV file", type=Path, nargs="?")
group.add_argument("-u", "--uninstall", help="remove CSV file association", action="store_true")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_opener.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from opencsv import main
from utf8csv import main
from pathlib import Path
import pytest
import sys
Expand Down Expand Up @@ -67,4 +67,4 @@ def test_cli_help(capsys):
capture = capsys.readouterr()
assert exit_obj.type == SystemExit and exit_obj.value.code == 0
assert not capture.err
assert capture.out.endswith("Thank you for using OpenCSV!\n")
assert capture.out.endswith("Thank you for using utf8csv!\n")
6 changes: 3 additions & 3 deletions opencsv.spec → utf8csv.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ block_cipher = None


a = Analysis(
['src\\opencsv\\main.py'],
['src\\utf8csv\\main.py'],
pathex=[],
binaries=[('.\\src\\eventlog.dll', 'eventlog.dll')],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
Expand All @@ -28,7 +28,7 @@ exe = EXE(
a.zipfiles,
a.datas,
[],
name='opencsv',
name='utf8csv',
debug=False,
bootloader_ignore_signals=False,
strip=False,
Expand Down

0 comments on commit fd2871a

Please sign in to comment.