-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename pmca.py to pmca-console.py, move commands to module
- Loading branch information
Showing
10 changed files
with
127 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
# Run `pyinstaller pmca.spec` to generate an executable | ||
# This file is used by other spec files | ||
|
||
import os.path, subprocess, sys | ||
import os, subprocess, sys | ||
|
||
# Get version from git | ||
version = subprocess.check_output(['git', 'describe', '--always', '--tags']).strip() | ||
|
||
# Generate filename | ||
suffix = {'linux2': '-linux', 'win32': '-win', 'darwin': '-osx'} | ||
output = 'pmca-' + subprocess.check_output(['git', 'describe', '--always', '--tags']).strip() + suffix.get(sys.platform, '') | ||
output += '-' + version + suffix.get(sys.platform, '') | ||
|
||
# Analyze files | ||
a = Analysis(['pmca.py'], excludes=['numpy'], datas=[('certs/*', 'certs')])# Don't let comtypes include numpy | ||
a = Analysis([input], excludes=['numpy'], datas=[('certs/*', 'certs')])# Don't let comtypes include numpy | ||
a.binaries = [((os.path.basename(name) if type == 'BINARY' else name), path, type) for name, path, type in a.binaries]# libusb binaries are not found in subdirs | ||
|
||
# Generate executable | ||
pyz = PYZ(a.pure, a.zipped_data) | ||
exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name=output) | ||
exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name=output, console=console) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
"""A command line application to install apps on Android-enabled Sony cameras""" | ||
import argparse | ||
|
||
import config | ||
from pmca.commands.market import * | ||
from pmca.commands.usb import * | ||
from pmca import spk | ||
|
||
def main(): | ||
"""Command line main""" | ||
parser = argparse.ArgumentParser() | ||
subparsers = parser.add_subparsers(dest='command', title='commands') | ||
info = subparsers.add_parser('info', description='Display information about the camera connected via USB') | ||
info.add_argument('-d', dest='driver', choices=['libusb', 'windows'], help='specify the driver') | ||
install = subparsers.add_parser('install', description='Installs an apk file on the camera connected via USB. The connection can be tested without specifying a file.') | ||
install.add_argument('-s', dest='server', help='hostname for the remote server (set to empty to start a local server)', default=config.appengineServer) | ||
install.add_argument('-d', dest='driver', choices=['libusb', 'windows'], help='specify the driver') | ||
install.add_argument('-o', dest='outFile', type=argparse.FileType('w'), help='write the output to this file') | ||
install.add_argument('-f', dest='apkFile', type=argparse.FileType('rb'), help='the apk file to install') | ||
market = subparsers.add_parser('market', description='Download apps from the official Sony app store') | ||
market.add_argument('-t', dest='token', help='Specify an auth token') | ||
market = subparsers.add_parser('apk2spk', description='Convert apk to spk') | ||
market.add_argument('inFile', metavar='app.apk', type=argparse.FileType('rb'), help='the apk file to convert') | ||
market.add_argument('outFile', metavar='app' + spk.constants.extension, type=argparse.FileType('wb'), help='the output spk file') | ||
market = subparsers.add_parser('spk2apk', description='Convert spk to apk') | ||
market.add_argument('inFile', metavar='app' + spk.constants.extension, type=argparse.FileType('rb'), help='the spk file to convert') | ||
market.add_argument('outFile', metavar='app.apk', type=argparse.FileType('wb'), help='the output apk file') | ||
|
||
args = parser.parse_args() | ||
if args.command == 'info': | ||
infoCommand(config.appengineServer, args.driver) | ||
elif args.command == 'install': | ||
installCommand(args.server, args.driver, args.apkFile, args.outFile) | ||
elif args.command == 'market': | ||
marketCommand(args.token) | ||
elif args.command == 'apk2spk': | ||
args.outFile.write(spk.dump(args.inFile.read())) | ||
elif args.command == 'spk2apk': | ||
args.outFile.write(spk.parse(args.inFile.read())) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Run `pyinstaller pmca-console.spec` to generate an executable | ||
|
||
input = 'pmca-console.py' | ||
output = 'pmca-console' | ||
console = True | ||
|
||
execfile('build.spec') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from getpass import getpass | ||
import os | ||
import re | ||
|
||
from .. import marketclient | ||
from .. import spk | ||
|
||
def marketCommand(token=None): | ||
if not token: | ||
print 'Please enter your Sony Entertainment Network credentials\n' | ||
email = raw_input('Email: ') | ||
password = getpass('Password: ') | ||
token = marketclient.login(email, password) | ||
if token: | ||
print 'Login successful. Your auth token (use with the -t option):\n%s\n' % token | ||
else: | ||
print 'Login failed' | ||
return | ||
|
||
devices = marketclient.getDevices(token) | ||
print '%d devices found\n' % len(devices) | ||
|
||
apps = [] | ||
for device in devices: | ||
print '%s (%s)' % (device.name, device.serial) | ||
for app in marketclient.getApps(device.deviceid): | ||
if not app.price: | ||
apps.append((device.deviceid, app.id)) | ||
print ' [%2d] %s' % (len(apps), app.name) | ||
print '' | ||
|
||
if apps: | ||
while True: | ||
i = int(raw_input('Enter number of app to download (0 to exit): ')) | ||
if i == 0: | ||
break | ||
app = apps[i - 1] | ||
print 'Downloading app %s' % app[1] | ||
spkName, spkData = marketclient.download(token, app[0], app[1]) | ||
fn = re.sub('(%s)?$' % re.escape(spk.constants.extension), '.apk', spkName) | ||
data = spk.parse(spkData) | ||
|
||
if os.path.exists(fn): | ||
print 'File %s exists already' % fn | ||
else: | ||
with open(fn, 'wb') as f: | ||
f.write(data) | ||
print 'App written to %s' % fn | ||
print '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
comtypes | ||
pycrypto | ||
# use pyinstaller 3.1.1 for now, 3.2 has some bugs | ||
pyinstaller==3.1.1 | ||
pyinstaller | ||
pyusb |