Skip to content

Commit 314f8e5

Browse files
committed
feat: moved to using the windows temp folder
feat: added installer compiler with Inno Setup feat: opens the output folder for the user
1 parent 89fd170 commit 314f8e5

File tree

4 files changed

+61
-15
lines changed

4 files changed

+61
-15
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ An application to manipulate postcode data.
1010

1111
## Build Exe
1212

13-
- `pyinstaller --onefile src/postcode_parse/postcode_parse.py`
13+
- `pyinstaller --onefile src/postcode_parse/postcode_parse.py --clean`
14+
- Compile the `postcode_parser.iss` in Inno Setup Compiler
15+
- Run the installer (to install or to update)
1416

1517
## Launching
1618

postcode_parser.iss

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; Script generated by the Inno Setup Script Wizard.
2+
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
3+
4+
#define MyAppName "PostcodeParser"
5+
#define MyAppVersion "1.0"
6+
#define MyAppPublisher "Matthew Armstrong"
7+
#define MyAppExeName "postcode_parse.exe"
8+
9+
[Setup]
10+
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
11+
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
12+
AppId={{78952356-F91F-41AE-B31C-AC505744949D}
13+
AppName={#MyAppName}
14+
AppVersion={#MyAppVersion}
15+
;AppVerName={#MyAppName} {#MyAppVersion}
16+
AppPublisher={#MyAppPublisher}
17+
DefaultDirName={autopf}\{#MyAppName}
18+
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
19+
; on anything but x64 and Windows 11 on Arm.
20+
ArchitecturesAllowed=x64compatible
21+
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
22+
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
23+
; meaning it should use the native 64-bit Program Files directory and
24+
; the 64-bit view of the registry.
25+
ArchitecturesInstallIn64BitMode=x64compatible
26+
DisableProgramGroupPage=yes
27+
; Uncomment the following line to run in non administrative install mode (install for current user only.)
28+
;PrivilegesRequired=lowest
29+
PrivilegesRequiredOverridesAllowed=dialog
30+
OutputBaseFilename=PostcodeParser_Installer
31+
Compression=lzma
32+
SolidCompression=yes
33+
WizardStyle=modern
34+
35+
[Languages]
36+
Name: "english"; MessagesFile: "compiler:Default.isl"
37+
38+
[Tasks]
39+
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
40+
41+
[Files]
42+
Source: "C:\Users\marms\Documents\Repos\PostcodeParse\dist\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
43+
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
44+
45+
[Icons]
46+
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
47+
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
48+
49+
[Run]
50+
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
51+

src/postcode_parse/_constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44

55
class SystemDefs:
6-
LOG_DIRECTORY = "logging"
7-
LOGGING_FILE_PATH = os.path.join(LOG_DIRECTORY, "log.log")
6+
TEMP_FOLDER = os.getenv('TEMP')
7+
TEMP_DIRECTORY = os.path.join(TEMP_FOLDER, "PostcodeParser")
8+
LOGGING_FILE_PATH = os.path.join(TEMP_DIRECTORY, "log.log")
89

9-
TEMP_DIRECTORY = ".tmp"
1010
TEMP_ONS_CSV = os.path.join(TEMP_DIRECTORY, "tmp_ons_data.csv")
1111

12-
OUTPUT_DIRECTORY = "output"
12+
OUTPUT_DIRECTORY = os.path.join(TEMP_DIRECTORY, "output")
1313

1414
PAF_FORMAT = {
1515
"Organisation Name": 11,

src/postcode_parse/postcode_parse.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,6 @@ def kml_output(postcode_output_dict: Dict[str, PostcodeData], output_path: str)
174174
kml.save(output_path)
175175

176176

177-
def clean_tmp_folder(tmp_folder_path: str) -> None:
178-
try:
179-
shutil.rmtree(tmp_folder_path, ignore_errors=True)
180-
logger.debug(f"Deleting the tmp directory at {tmp_folder_path} and all its contents")
181-
except Exception as e:
182-
logger.error(f"An error occurred while deleting the folder '{tmp_folder_path}': {e}")
183-
184-
185177
def guided_option_entry() -> Tuple[str, List[str], str, bool, bool, bool]:
186178
paf_path = questionary.path("What is the path to the PAF file?").ask()
187179

@@ -199,8 +191,8 @@ def guided_option_entry() -> Tuple[str, List[str], str, bool, bool, bool]:
199191

200192

201193
if __name__ == "__main__":
202-
atexit.register(clean_tmp_folder, SystemDefs.TEMP_DIRECTORY)
203-
create_folder(SystemDefs.LOG_DIRECTORY)
194+
atexit.register(input, "Press Enter to exit...")
195+
create_folder(SystemDefs.TEMP_DIRECTORY)
204196
logger = create_logger(file_append=False)
205197

206198
parser = argparse.ArgumentParser(description="Parse Postcodes")
@@ -224,3 +216,4 @@ def guided_option_entry() -> Tuple[str, List[str], str, bool, bool, bool]:
224216
options = (args.paf, args.districts, args.ons, args.csv_flag, args.kml_flag, args.disable_progress_bar)
225217

226218
postcode_parse(*options)
219+
os.startfile(SystemDefs.OUTPUT_DIRECTORY)

0 commit comments

Comments
 (0)