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

TIMOB-9309: BlackBerry: Convert argparse to optparse part2 #74

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 16 additions & 18 deletions support/blackberry/blackberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import os, sys, shutil
from blackberryndk import BlackberryNDK
from argparse import ArgumentParser
from optparse import OptionParser

template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
top_support_dir = os.path.dirname(template_dir)
Expand Down Expand Up @@ -148,8 +148,7 @@ def __unitTestTraceback():

def __runUnitTests():
from tiunittest import UnitTest

ndk = None if args.test == True else args.test
ndk = options.ndk.decode("utf-8") if options.ndk != None else None

bbndk = BlackberryNDK(ndk)
bb = Blackberry('TemplateTest', 'com.macadamian.template', bbndk)
Expand All @@ -165,30 +164,29 @@ def __runUnitTests():
print '\nFinished Running Unit Tests'
UnitTest.printDetails()


if __name__ == '__main__':
# This script is only meant to be invoked from project.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future please refrain from making changes to the empty lines format, it will never end if people start adding and removing empty lines back and forth to suit their personal preference.

Don't need to revert this.

# Setup script usage
parser = ArgumentParser(description = 'Creates blackberry project')
parser.add_argument('name', help = 'Blackberry project name', nargs = '?')
parser.add_argument('id', help = 'Blackberry project id', nargs = '?')
parser.add_argument('dir', help = 'Blackberry project directory', nargs = '?')
parser.add_argument('ndk', help = 'Blackberry NDK path', nargs = '?')
parser.add_argument('-t', '--test', help = 'run unit tests', metavar = 'ndk_location', nargs = '?', const = True)
args = parser.parse_args()

if args.test:
# Setup script usage using optparse
parser = OptionParser(usage='--name name --id id --dir dir [--ndk ndk] [-t]', description='Creates blackberry project')
parser.add_option('--name', help='Blackberry project name', dest='name')
parser.add_option('--id', help='Blackberry project id', dest='id')
parser.add_option('--dir', help='Blackberry project directory', dest='dir')
parser.add_option('--ndk', help='Blackberry NDK path', dest='ndk')
parser.add_option('-t', '--test', help='run unit tests', dest='test', action='store_true')
(options, args) = parser.parse_args()

if options.test:
__runUnitTests()
sys.exit(0)
else:
if args.name == None or args.id == None or args.dir == None or args.ndk == None:
if options.name == None or options.id == None or options.dir == None:
parser.print_usage()
sys.exit(1)

try:
bbndk = BlackberryNDK(args.ndk.decode("utf-8"))
bb = Blackberry(args.name.decode("utf-8"), args.id.decode("utf-8"), bbndk)
bb.create(args.dir.decode("utf-8"))
bbndk = BlackberryNDK(options.ndk.decode("utf-8") if options.ndk != None else None)
bb = Blackberry(options.name.decode("utf-8"), options.id.decode("utf-8"), bbndk)
bb.create(options.dir.decode("utf-8"))
except Exception, e:
print >>sys.stderr, e
sys.exit(1)
20 changes: 11 additions & 9 deletions support/blackberry/blackberryndk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# spaces for the tools to work correctly

import os, sys, platform, subprocess, pprint, shutil
from argparse import ArgumentParser
from optparse import OptionParser

class Device:
''' TODO Mac: Look at how qde works with sim for this class '''
Expand Down Expand Up @@ -344,19 +344,21 @@ def __runUnitTests(ipAddress = None):


if __name__ == "__main__":
parser = ArgumentParser(description = 'Prints the NDK directory and version')
parser.add_argument('ndk_path', help = 'path to the blackberry ndk', nargs='?')
parser.add_argument('-t', '--test', help = 'run unit tests', action = 'store_true')
parser.add_argument('--ip_address', help='simulator IP address for unit tests')
args = parser.parse_args()

# Setup script usage using optparse
parser = OptionParser(usage='[ndk_path] [-t] [--ip_address IP ADDRESS]', description='Prints the NDK directory and version')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above regarding default usage..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is "blackberryndk.py [options]", which probably not what we want.


parser.add_option('-t', '--test', help='run unit tests', action='store_true', dest='test')
parser.add_option('--ip_address', help='simulator IP address for unit tests', dest='ip_address')
(options, args) = parser.parse_args()

try:
ndk = BlackberryNDK(args.ndk_path)
ndk = BlackberryNDK(args[0].decode('utf-8') if len(args) != 0 else None)
print "BLACKBERRY_NDK=%s" % ndk.getBlackberryNdk()
print "BLACKBERRY_NDK_VERSION=%s" % ndk.getVersion()
except Exception, e:
print >>sys.stderr, e
sys.exit(1)

if args.test:
__runUnitTests(args.ip_address.decode('utf-8') if args.ip_address != None else None)
if options.test:
__runUnitTests(options.ip_address.decode('utf-8') if options.ip_address != None else None)
2 changes: 1 addition & 1 deletion support/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def main():

if blackberry:
blackberry_gen = os.path.join(template_dir,'blackberry','blackberry.py')
run([sys.executable, blackberry_gen, name, appid, directory, blackberry_ndk])
run([sys.executable, blackberry_gen, '--name', name, '--id', appid, '--dir', directory, '--ndk', blackberry_ndk])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should have been changed, to keep it close to what is done for other platforms. But it probably doesn't matter.


# copy LICENSE and README
for file in ['LICENSE','README']:
Expand Down