From a8d65c16c3dd017a5e619426a92e12d096929095 Mon Sep 17 00:00:00 2001 From: Lukas Willin <14276298+LukasWillin@users.noreply.github.com> Date: Tue, 3 Mar 2020 14:57:59 +0100 Subject: [PATCH 1/7] <1> Fix TypeError when writing html to outputfile <2> Output original exception 1. TypeError: write() argument must be str, not bytes Thrown because of encoding on Windows with python 3.8.x 2. Write exception to console instead of writing your own --- htmlmerge | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htmlmerge b/htmlmerge index d19022a..9807ae8 100755 --- a/htmlmerge +++ b/htmlmerge @@ -635,9 +635,10 @@ else: try: with open (outfile,'w') as f: - f.write ( all_html ) - except: - error ("Failed to save \"" + outfile + "\" ! Do we have permission?") + f.write ( all_html.decode('utf-8') ) + except Exception as e: + error ("Failed to save \"" + outfile + "\" ! Do we have permission? (Original error below)") + error (e) sys.exit(1) # end try # end if From bbd171fbac0dd1e4f4b838fb4240201c57986ff9 Mon Sep 17 00:00:00 2001 From: Lukas Willin <14276298+LukasWillin@users.noreply.github.com> Date: Tue, 3 Mar 2020 15:06:45 +0100 Subject: [PATCH 2/7] Update README.md with another cli example --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f37c167..e02b0d5 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,9 @@ Make sure `~/bin/` is in your `$PATH` variable. htmlmerge index.html htmlmerge index.html -H -C -J -o build/out.html -u htmlmerge index.html -H --loglevel quiet -c -i -j + + Examples (Windows): + py htmlmerge index.dev.html -o index.html For CSS or JavaScript compression, additional YUIcompressor jar file must be present in the same directory as this script. From a7448dfc49b062a9b63941d24a836b4a9c156c4d Mon Sep 17 00:00:00 2001 From: Lukas Willin <14276298+LukasWillin@users.noreply.github.com> Date: Tue, 3 Mar 2020 18:07:16 +0100 Subject: [PATCH 3/7] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e02b0d5..dd2569e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ reduced. This is especially interesting for mobile devices. This script was tested on `Gentoo Linux` with `Python 3.2.5` and `BeautifulSoup4`. - +This script was tested on `Windows 10 (Version 1809, OS Build: 17763.1039)` with `python3 (3.8.2)` and +`BeautifulSoup4 (4.8.2)`. ### Install ### Save `htmlmerge` to your bin path and make it executable. From 485fa92f6e9e1915bef04344bc20f6097aaa14ba Mon Sep 17 00:00:00 2001 From: Lukas Willin <14276298+LukasWillin@users.noreply.github.com> Date: Tue, 3 Mar 2020 18:09:39 +0100 Subject: [PATCH 4/7] Reformat testing information --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dd2569e..6e20032 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,10 @@ reduced. This is especially interesting for mobile devices. * (optional) Yahoo [`YUIcompressor`](https://github.com/yui/yuicompressor/releases) -This script was tested on `Gentoo Linux` with `Python 3.2.5` and +This script was tested on: +- Unknown Date: `Gentoo Linux` with `Python 3.2.5` and `BeautifulSoup4`. -This script was tested on `Windows 10 (Version 1809, OS Build: 17763.1039)` with `python3 (3.8.2)` and +- 03.03.2020: `Windows 10 (Version 1809, OS Build: 17763.1039)` with `python3 (3.8.2)` and `BeautifulSoup4 (4.8.2)`. ### Install ### From e6351b353cfdb6125dbaab5aa2b6166ab5dc9d93 Mon Sep 17 00:00:00 2001 From: LukasWillin Date: Tue, 10 Mar 2020 12:52:24 +0100 Subject: [PATCH 5/7] <1:#2> Replace has_key with has_attr --- htmlmerge | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htmlmerge b/htmlmerge index 9807ae8..08a0fd8 100755 --- a/htmlmerge +++ b/htmlmerge @@ -403,7 +403,7 @@ if merge_js: # iterate over script tags for tag in scripts: # get src url of script tag - if tag.has_key ("src"): + if tag.has_attr ("src"): # save source url to variable src_url = tag['src'] else: @@ -483,10 +483,10 @@ if merge_css: # iterate over link tags for tag in links: # get content of rel attribute - if tag.has_key ("rel"): + if tag.has_attr ("rel"): rel = " ".join (tag['rel']) - if rel == "stylesheet" and tag.has_key ("href"): + if rel == "stylesheet" and tag.has_attr ("href"): # get href url of link tag src_url = tag['href'] From b9e43ea9bee252b6e74ed564fd90ab31959ac082 Mon Sep 17 00:00:00 2001 From: Lukas Willin Date: Tue, 10 Mar 2020 14:41:14 +0100 Subject: [PATCH 6/7] Add note about development settings LF (unix) --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6e20032..03512b9 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,9 @@ output file. If there is no output file given the script will save to * possibility to pass arguments to htmlcompressor * add a preset system +### Development ### +* Use unix-style end-of-line LF. + ### Author ### Fin Christensen From fe6b538c18a3888b01dc4abc58e673d7cac1ed71 Mon Sep 17 00:00:00 2001 From: Lukas Willin Date: Thu, 3 Apr 2025 12:07:09 +0200 Subject: [PATCH 7/7] Output exception when file.read() fails to help with debugging. --- htmlmerge | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/htmlmerge b/htmlmerge index 08a0fd8..43a6382 100755 --- a/htmlmerge +++ b/htmlmerge @@ -380,8 +380,9 @@ else: try: with open (infile,'r') as f: indexHTML = f.read() - except: + except Exception as e: error ("Could not open \"" + infile + "\" !") + print(e) sys.exit(1) # end try # end if @@ -418,8 +419,9 @@ if merge_js: try: with open (src_url,'r') as f: all_scripts += f.read() - except: + except Exception as e: error ("Could not open \"" + src_url + "\" !") + print(e) sys.exit(1) # end try @@ -496,8 +498,9 @@ if merge_css: try: with open (src_url,'r') as f: all_css += f.read() - except: + except Exception as e: error ("Could not open \"" + src_url + "\" !") + print(e) sys.exit(1) # end try @@ -541,8 +544,9 @@ if merge_css: with open (src_url,'r') as f: # insert loaded css at old @import index all_css.insert (idx, f.read()) - except: + except Exception as e: error ("Could not open \"" + src_url + "\" !") + print(e) sys.exit(1) # end try # end if