Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion python/csconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This file is part of the PyPhantomJS project.

Copyright (C) 2011 James Roe <roejames12@hotmail.com>
Copyright (C) 2010-2011 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
30 changes: 16 additions & 14 deletions python/pyphantomjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ def __init__(self, args, parent = None):
QObject.__init__(self, parent)

# variable declarations
self.m_scriptFile = self.m_script = self.m_loadStatus = self.m_state = self.m_userAgent = QString()
self.m_loadStatus = self.m_state = self.m_userAgent = QString()
self.m_page = WebPage(self)
self.m_var = self.m_loadScript_cache = {}
# setup the values from args
self.m_script = QString.fromUtf8(args.script[0].readAll())
self.m_scriptFile = args.script[0].fileName()
self.m_script = QString.fromUtf8(args.script[0].read())
self.m_scriptFile = args.script[0].name
self.m_args = args.script[1:]
self.m_upload_file = args.upload_file
autoLoadImages = False if args.load_images == 'no' else True
Expand Down Expand Up @@ -158,8 +158,8 @@ def __init__(self, args, parent = None):

# if our script was called in a different directory, change to it
# to make any dealings with files be relative to the scripts directory
if os.path.dirname(str(self.m_scriptFile)):
os.chdir(os.path.dirname(str(self.m_scriptFile)))
if os.path.dirname(self.m_scriptFile):
os.chdir(os.path.dirname(self.m_scriptFile))

# inject our properties and slots into javascript
self.setObjectName('phantom')
Expand All @@ -170,7 +170,7 @@ def execute(self):
if self.m_script.startsWith('#!'):
self.m_script.prepend('//')

if self.m_scriptFile.endsWith('.coffee'):
if self.m_scriptFile.endswith('.coffee'):
coffee = CSConverter(self)
self.m_script = coffee.convert(self.m_script)

Expand Down Expand Up @@ -219,11 +219,12 @@ def loadScript(self, script):
self.m_page.mainFrame().evaluateJavaScript(self.m_loadScript_cache[script])
return True

scriptFile = QFile(script).fileName()
script = QFile(script)
if not script.open(QFile.ReadOnly):
scriptFile = QString(script)
try:
script = open(script)
script = QString.fromUtf8(script.read())
except IOError:
return False
script = QString.fromUtf8(script.readAll())

if script.startsWith('#!'):
script.prepend('//')
Expand Down Expand Up @@ -357,7 +358,7 @@ def viewportSize(self, size):
item_buffer[QString(item[0])] = QString(item[1])
for tag in item_buffer:
if not os.path.exists(item_buffer[tag]):
print >> sys.stderr, 'No such file: \'%s\'' % item_buffer[tag]
print >> sys.stderr, '[Errno 2] No such file or directory: \'%s\'' % item_buffer[tag]
sys.exit(1)
args.upload_file = item_buffer

Expand All @@ -372,9 +373,10 @@ def viewportSize(self, size):
p.print_help()
sys.exit(1)

args.script[0] = QFile(args.script[0])
if not args.script[0].open(QFile.ReadOnly):
print >> sys.stderr, 'No such file: \'%s\'' % args.script[0].fileName()
try:
args.script[0] = open(args.script[0])
except IOError as stderr:
print >> sys.stderr, stderr
sys.exit(1)

app = QApplication(sys.argv)
Expand Down