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

windows fix #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
WARNING
=======
this mod to make buster usable on windows was written by someone who has 0 experience with python and 0 familiarity with python syntax, and who literally just started using github 3 days ago so he has no familiarity with convention or documentation.

i referred to axitkhurana's and lsiemens's buster.py source codes to put together this one to make it usable on windows, or well, it's usable on my blog at least.

problems with axitkhurana's buster for win
------------------------------------------
referring to axitkhurana/buster/commit/5e599f01fec32154cab3af600a377e7e8f76ccf2

line 48: when wget is given(--restrict-file-name=unix), it attempts to download xxx.css?v=xxxxxxxxxx files and xxx.js?v=xxxxxxxxxx files. windows explicitly forbids ? even existing in any file path, so wget fails when attempting to create these files in the static directory.

line 59 attempts to remove these query strings, but it does so by renaming the file and on windows, no file exists in the first place.

problems with lsiemens's buster for win
---------------------------------------
referring to lsiemens/buster/commit/30e54d36f99b127b4a3a3bb1b445ffa6902ce5aa

lsiemens's buster does perfectly what axitkhurana's cannot: download query-less .css and .js asset files, and remove such queries from the .html files. however, for some reason every image file that this version of buster fetches results in a corrupted file that is 6 bytes large (even when wget prints out xxxxKB downloaded in the command prompt). i have zero idea about what causes this, although i suspect that it's because it attempts to remove @v=.......... in every file that exists, which may result in it corrupting image files by reading them as plaintext and treating them as such.

what i did
----------
starting from axit's code (the image issue was something i just didn't want to deal with):

- removed line 48. this results in wget downloading .css@v=xxxxxxxxxx assets.
- changed the regex expressions in lines 52 and 56 to use @ instead of ?, since that's what the downloaded file names would have
- added code to allow buster to replace old asset files with new ones since os.rename on windows gives error 183 when the target filename already exists.
- added code to correct the .html files to refer to the renamed assets

problems my shit code has caused in turn
----------------------------------------
TypeError: expected string or buffer in File "build\bdist.win32\egg\buster\buster.py", line 90, in fixLinks

when i removed line 48, this error started popping up. it has to do with fixing rss links.


Buster
======

Expand Down
38 changes: 30 additions & 8 deletions buster/buster.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import shutil
import SocketServer
import SimpleHTTPServer
import platform
from docopt import docopt
from time import gmtime, strftime
from git import Repo
Expand All @@ -45,18 +46,39 @@ def main():
"--no-parent " # don't go to parent level
"--directory-prefix {1} " # download contents to static/ folder
"--no-host-directories " # don't create domain named folder
"--restrict-file-name=unix " # don't escape query string
"{0}").format(arguments['--domain'], static_path)
os.system(command)

# remove query string since Ghost 0.4
file_regex = re.compile(r'.*?(\?.*)')
for root, dirs, filenames in os.walk(static_path):
for filename in filenames:
if file_regex.match(filename):
newname = re.sub(r'\?.*', '', filename)
print "Rename", filename, "=>", newname
os.rename(os.path.join(root, filename), os.path.join(root, newname))
if platform.system() == "Windows":
file_regex = re.compile(r'.*?(\@.*)')
for root, dirs, filenames in os.walk(static_path):
for filename in filenames:
if file_regex.match(filename):
newname = re.sub(r'\@.*', '', filename)
print "Rename", filename, "=>", newname
if os.path.isfile(os.path.join(root, newname)):
os.remove(os.path.join(root, newname))
print "removing " + root + "/" + newname + " to make room for new copy..."
os.rename(os.path.join(root, filename), os.path.join(root, newname))
for filename in fnmatch.filter(filenames, "*.html"):
data = None
newData = None
with open(os.path.join(root, filename), 'r') as open_file:
data = open_file.read()
newData = re.sub(r'\@v=..........','',data)
with open(os.path.join(root, filename), 'w') as open_file:
open_file.write(newData)
print "patching", filename, "to remove asset versioning..."

else:
file_regex = re.compile(r'.*?(\?.*)')
for root, dirs, filenames in os.walk(static_path):
for filename in filenames:
if file_regex.match(filename):
newname = re.sub(r'\?.*', '', filename)
print "Rename", filename, "=>", newname
os.rename(os.path.join(root, filename), os.path.join(root, newname))

# remove superfluous "index.html" from relative hyperlinks found in text
abs_url_regex = re.compile(r'^(?:[a-z]+:)?//', flags=re.IGNORECASE)
Expand Down