2011-04-27 13:45:41 +04:00
|
|
|
#!/usr/bin/env python
|
2011-03-16 08:18:01 +03:00
|
|
|
'''
|
|
|
|
This file is part of the PyPhantomJS project.
|
|
|
|
|
|
|
|
Copyright (C) 2011 James Roe <roejames12@hotmail.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
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
'''
|
|
|
|
|
2011-04-28 03:36:45 +04:00
|
|
|
# automatically convert Qt types by using api 2
|
|
|
|
import sip
|
|
|
|
sip.setapi('QString', 2)
|
|
|
|
sip.setapi('QVariant', 2)
|
|
|
|
|
2011-06-12 12:23:15 +04:00
|
|
|
import os
|
2011-06-04 08:15:59 +04:00
|
|
|
import sys
|
2011-03-16 08:18:01 +03:00
|
|
|
|
2011-06-04 08:15:59 +04:00
|
|
|
from PyQt4.QtCore import qInstallMsgHandler
|
|
|
|
from PyQt4.QtGui import QIcon, QApplication
|
|
|
|
|
2011-07-04 13:37:18 +04:00
|
|
|
from plugincontroller import do_action
|
2011-05-07 10:46:51 +04:00
|
|
|
# load plugins if running script directly
|
2011-05-04 13:50:16 +04:00
|
|
|
if __name__ == '__main__':
|
2011-05-07 11:19:27 +04:00
|
|
|
from plugincontroller import load_plugins
|
2011-05-07 10:46:51 +04:00
|
|
|
load_plugins()
|
2011-05-04 13:50:16 +04:00
|
|
|
|
2011-06-04 08:15:59 +04:00
|
|
|
import resources
|
2011-04-12 12:32:07 +04:00
|
|
|
from phantom import Phantom
|
2011-04-12 12:34:20 +04:00
|
|
|
from utils import argParser, MessageHandler, version
|
2011-03-16 08:18:01 +03:00
|
|
|
|
|
|
|
# make keyboard interrupt quit program
|
|
|
|
import signal
|
|
|
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
|
|
|
2011-05-04 03:45:53 +04:00
|
|
|
# output unicode safe text
|
|
|
|
from utils import SafeStreamFilter
|
|
|
|
sys.stdout = SafeStreamFilter(sys.stdout)
|
|
|
|
sys.stderr = SafeStreamFilter(sys.stderr)
|
|
|
|
|
2011-06-01 03:23:06 +04:00
|
|
|
|
2011-04-27 13:45:41 +04:00
|
|
|
def parseArgs(args):
|
2011-03-16 08:18:01 +03:00
|
|
|
# Handle all command-line options
|
|
|
|
p = argParser()
|
2011-04-27 13:45:41 +04:00
|
|
|
arg_data = p.parse_known_args(args)
|
2011-04-13 19:12:43 +04:00
|
|
|
args = arg_data[0]
|
|
|
|
args.script_args = arg_data[1]
|
2011-03-16 08:18:01 +03:00
|
|
|
|
2011-06-08 14:07:46 +04:00
|
|
|
args.disk_cache = False if args.disk_cache == 'no' else True
|
|
|
|
args.ignore_ssl_errors = False if args.ignore_ssl_errors == 'no' else True
|
|
|
|
args.load_images = True if args.load_images == 'yes' else False
|
|
|
|
args.load_plugins = False if args.load_plugins == 'no' else True
|
2011-06-25 05:19:54 +04:00
|
|
|
args.local_access_remote = False if args.local_access_remote == 'no' else True
|
2011-06-08 14:07:46 +04:00
|
|
|
|
2011-03-16 08:18:01 +03:00
|
|
|
if args.proxy:
|
|
|
|
item = args.proxy.split(':')
|
|
|
|
if len(item) < 2 or not len(item[1]):
|
|
|
|
p.print_help()
|
|
|
|
sys.exit(1)
|
|
|
|
args.proxy = item
|
|
|
|
|
2011-07-04 13:37:18 +04:00
|
|
|
do_action('ParseArgs')
|
2011-05-04 13:50:16 +04:00
|
|
|
|
2011-04-13 19:12:43 +04:00
|
|
|
if not args.script:
|
2011-03-16 08:18:01 +03:00
|
|
|
p.print_help()
|
|
|
|
sys.exit(1)
|
|
|
|
|
2011-06-12 12:23:15 +04:00
|
|
|
if not os.path.exists(args.script):
|
|
|
|
sys.exit('No such file or directory: \'%s\'' % args.script)
|
2011-04-27 13:45:41 +04:00
|
|
|
|
|
|
|
return args
|
|
|
|
|
2011-06-01 03:23:06 +04:00
|
|
|
|
2011-04-27 13:45:41 +04:00
|
|
|
def main():
|
|
|
|
args = parseArgs(sys.argv[1:])
|
|
|
|
|
|
|
|
# register an alternative Message Handler
|
|
|
|
messageHandler = MessageHandler(args.verbose)
|
|
|
|
qInstallMsgHandler(messageHandler.process)
|
2011-03-16 08:18:01 +03:00
|
|
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
|
|
|
app.setWindowIcon(QIcon(':/resources/pyphantomjs-icon.png'))
|
|
|
|
app.setApplicationName('PyPhantomJS')
|
|
|
|
app.setOrganizationName('Umaclan Development')
|
|
|
|
app.setOrganizationDomain('www.umaclan.com')
|
|
|
|
app.setApplicationVersion(version)
|
|
|
|
|
2011-06-19 12:18:26 +04:00
|
|
|
phantom = Phantom(args)
|
2011-05-04 13:50:16 +04:00
|
|
|
|
2011-07-04 13:37:18 +04:00
|
|
|
do_action('Main')
|
2011-05-04 13:50:16 +04:00
|
|
|
|
2011-06-01 10:17:50 +04:00
|
|
|
if phantom.execute():
|
|
|
|
app.exec_()
|
2011-06-01 03:23:06 +04:00
|
|
|
return phantom.returnValue()
|
|
|
|
|
2011-04-27 13:45:41 +04:00
|
|
|
|
2011-07-04 13:37:18 +04:00
|
|
|
do_action('PyPhantomJS')
|
2011-05-04 13:50:16 +04:00
|
|
|
|
2011-06-01 03:23:06 +04:00
|
|
|
|
2011-04-27 13:45:41 +04:00
|
|
|
if __name__ == '__main__':
|
2011-06-01 03:23:06 +04:00
|
|
|
sys.exit(main())
|