Skip to content
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
26 changes: 18 additions & 8 deletions ice/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@
import traceback

try:
from runners import command_line_runner
from .runners import command_line_runner

if __name__ == "__main__":
runner = command_line_runner.CommandLineRunner()
runner.run(sys.argv)
# Keeps the console from closing (until the user hits enter) so they can
# read any console output
print ""
print "Close the window, or hit enter to exit..."
raw_input()
print("")
print("Close the window, or hit enter to exit...")

# Wait for the user to press the enter key. Python2 and Python3 compatibilty.
try:
raw_input()
except:
input()
except Exception as e:
stderr = sys.stderr
with open('error.log', 'w') as f:
sys.stderr = f
traceback.print_exc()
sys.stderr = stderr
traceback.print_exc()
print ""
print "An error has occurred! A copy of the crash report has been saved to 'error.log'."
print "If this continues please submit an issue on our Github page (http://github.com/scottrice/Ice)"
raw_input()
print("")
print("An error has occurred! A copy of the crash report has been saved to 'error.log'.")
print("If this continues please submit an issue on our Github page (http://github.com/scottrice/Ice)")

# Wait for the user to press the enter key. Python2 and Python3 compatibilty.
try:
raw_input()
except:
input()
4 changes: 2 additions & 2 deletions ice/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from pysteam import shortcuts

import paths
from . import paths

from logs import logger
from .logs import logger

def default_backups_directory():
return os.path.join(paths.application_data_directory(), 'Backups')
Expand Down
4 changes: 2 additions & 2 deletions ice/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import collections
import os

import model
import paths
from . import model
from . import paths

ConfigOption = collections.namedtuple('ConfigOption', [
'identifier',
Expand Down
2 changes: 1 addition & 1 deletion ice/consoles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os

import roms
from . import roms

def console_roms_directory(configuration, console):
"""
Expand Down
12 changes: 6 additions & 6 deletions ice/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import pastebin

import filesystem
import paths
import settings
from . import filesystem
from . import paths
from . import settings

def debug_log_contents():
fs = filesystem.RealFilesystem()
Expand Down Expand Up @@ -41,6 +41,6 @@ def make_paste(contents):

def paste_debug_logs():
url = make_paste(debug_log_contents())
print "You can find your logs at:\n"
print "\t%s\n" % url
print "Please include this link in any bug reports."
print("You can find your logs at:\n")
print("\t%s\n" % url)
print("Please include this link in any bug reports.")
2 changes: 1 addition & 1 deletion ice/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: utf-8

from logs import logger
from .logs import logger

def catch_exceptions(msg):
def decorator(func):
Expand Down
6 changes: 3 additions & 3 deletions ice/environment_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import psutil
import sys

from error.path_existance_error import PathExistanceError
from error.process_running_error import ProcessRunningError
from error.writable_path_error import WritablePathError
from .error.path_existance_error import PathExistanceError
from .error.process_running_error import ProcessRunningError
from .error.writable_path_error import WritablePathError


class EnvironmentChecker(object):
Expand Down
2 changes: 1 addition & 1 deletion ice/error/path_existance_error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from env_checker_error import EnvCheckerError
from .env_checker_error import EnvCheckerError


class PathExistanceError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion ice/error/process_running_error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from env_checker_error import EnvCheckerError
from .env_checker_error import EnvCheckerError


class ProcessRunningError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion ice/error/writable_path_error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from env_checker_error import EnvCheckerError
from .env_checker_error import EnvCheckerError


class WritablePathError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion ice/gridproviders/combined_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from functools import reduce

import grid_image_provider
from . import grid_image_provider

from ice.logs import logger

Expand Down
21 changes: 14 additions & 7 deletions ice/gridproviders/consolegrid_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@

import sys
import os
import urllib
import urllib2

import grid_image_provider
# Python 2 and 3 compatibility for urllib.
Copy link
Owner

Choose a reason for hiding this comment

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

Oof. I think this is a sign that I need to convert over to something like requests.

try:
from urllib.request import urlopen, Request, urlretrieve
from urllib.error import HTTPError, URLError
from urllib.parse import quote
except ImportError:
from urllib import urlencode, quote, urlretrieve
from urllib2 import urlopen, Request, HTTPError, URLError

from . import grid_image_provider

from ice.logs import logger

Expand All @@ -29,7 +36,7 @@ def is_enabled():

def consolegrid_top_picture_url(self, rom):
host = self.api_url()
quoted_name = urllib.quote(rom.name)
quoted_name = quote(rom.name)
return "%s?console=%s&game=%s" % (host, rom.console.shortname, quoted_name)

def find_url_for_rom(self, rom):
Expand All @@ -38,7 +45,7 @@ def find_url_for_rom(self, rom):
ConsoleGrid.com
"""
try:
response = urllib2.urlopen(self.consolegrid_top_picture_url(rom))
response = urlopen(self.consolegrid_top_picture_url(rom))
if response.getcode() == 204:
name = rom.name
console = rom.console.fullname
Expand All @@ -47,7 +54,7 @@ def find_url_for_rom(self, rom):
)
else:
return response.read()
except urllib2.URLError as error:
except URLError as error:
# Connection was refused. ConsoleGrid may be down, or something bad
# may have happened
logger.debug(
Expand All @@ -59,7 +66,7 @@ def download_image(self, url):
Downloads the image at 'url' and returns the path to the image on the
local filesystem
"""
(path, headers) = urllib.urlretrieve(url)
(path, headers) = urlretrieve(url)
return path

def image_for_rom(self, rom):
Expand Down
2 changes: 1 addition & 1 deletion ice/gridproviders/local_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
import os

import grid_image_provider
from . import grid_image_provider

from ice.logs import logger

Expand Down
2 changes: 1 addition & 1 deletion ice/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import logging
import logging.handlers

import paths
from . import paths

def is_test_stack_frame(frame):
# The path of the executing file is in frame[1]
Expand Down
2 changes: 1 addition & 1 deletion ice/parsing/rom_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ROMParser(object):
# Regex that matches the entire string up until it hits the first '[',
# ']', '(', ')', or '.'
# DOESN'T WORK FOR GAMES WITH ()s IN THEIR NAME
ur"(?P<name>[^\(\)\[\]\.]*).*",
u"(?P<name>[^\(\)\[\]\.]*).*",
]

def __init__(self):
Expand Down
16 changes: 10 additions & 6 deletions ice/persistence/config_file_backing_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
Copyright (c) 2014 Scott Rice. All rights reserved.
"""

import ConfigParser
# Python 2 and 3 compatibility for ConfigParser
try:
from configparser import ConfigParser, RawConfigParser, NoSectionError, NoOptionError, DuplicateSectionError
except ImportError:
from ConfigParser import ConfigParser, RawConfigParser, NoSectionError, NoOptionError, DuplicateSectionError

import backing_store
from . import backing_store


class ConfigFileBackingStore(backing_store.BackingStore):

def __init__(self, path):
super(ConfigFileBackingStore, self).__init__(path)
self.configParser = ConfigParser.RawConfigParser()
self.configParser = RawConfigParser()
self.configParser.read(self.path)

def identifiers(self):
Expand All @@ -24,7 +28,7 @@ def identifiers(self):
def add_identifier(self, ident):
try:
self.configParser.add_section(ident)
except ConfigParser.DuplicateSectionError:
except DuplicateSectionError:
raise ValueError("The identifier `%s` already exists" % str(ident))

def remove_identifier(self, ident):
Expand All @@ -33,14 +37,14 @@ def remove_identifier(self, ident):
def keys(self, ident):
try:
return self.configParser.options(ident)
except ConfigParser.NoSectionError:
except NoSectionError:
raise ValueError("No identifier named `%s` exists" % str(ident))

def get(self, ident, key, default=None):
try:
val = self.configParser.get(ident, key.lower())
return val
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
except (NoSectionError, NoOptionError):
return default

def set(self, ident, key, value):
Expand Down
19 changes: 12 additions & 7 deletions ice/rom_finder.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import sys
from functools import partial

import consoles
import model
from . import consoles
from . import model

from logs import logger
from .logs import logger

class ROMFinder(object):

Expand Down Expand Up @@ -47,6 +47,11 @@ def roms_for_consoles(self, consoles):
Equivalent to calling `roms_for_console` on every element of `consoles`
and combining the results
"""
# Abuses the fact that the `+` operator is overloaded with lists to turn
# our list of lists into a single giant list. Yay for duck typing?
return sum(map(self.roms_for_console, consoles), [])
# Python 2 and 3 act differently on map() types, since map() in Python3 now returns an iterator
if sys.version_info[0] >= 3:
# TODO: Fix this somehow?
return list(map(self.roms_for_console, consoles))
else:
# Abuses the fact that the `+` operator is overloaded with lists to turn
# our list of lists into a single giant list. Yay for duck typing?
return sum(map(self.roms_for_console, consoles), [])
4 changes: 2 additions & 2 deletions ice/roms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

from pysteam import model

import emulators
import paths
from . import emulators
from . import paths

# LEGACY: At one point I added this to every shortcut that Ice made. That was
# a terrible idea, and I'm keeping this definition here just in case I ever
Expand Down
2 changes: 1 addition & 1 deletion ice/runners/command_line_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pysteam.steam import get_steam

from ice_engine import IceEngine
from .ice_engine import IceEngine

from ice import debug
from ice.filesystem import RealFilesystem
Expand Down
36 changes: 22 additions & 14 deletions ice/settings.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# encoding: utf-8

import os
import sys

import configuration
import paths
from . import configuration
from . import paths

from logs import logger
from gridproviders.combined_provider import CombinedProvider
from gridproviders.consolegrid_provider import ConsoleGridProvider
from gridproviders.local_provider import LocalProvider
from persistence.backed_object_manager import BackedObjectManager
from persistence.config_file_backing_store import ConfigFileBackingStore
from persistence.adapters.console_adapter import ConsoleBackedObjectAdapter
from persistence.adapters.emulator_adapter import EmulatorBackedObjectAdapter
from .logs import logger
from .gridproviders.combined_provider import CombinedProvider
from .gridproviders.consolegrid_provider import ConsoleGridProvider
from .gridproviders.local_provider import LocalProvider
from .persistence.backed_object_manager import BackedObjectManager
from .persistence.config_file_backing_store import ConfigFileBackingStore
from .persistence.adapters.console_adapter import ConsoleBackedObjectAdapter
from .persistence.adapters.emulator_adapter import EmulatorBackedObjectAdapter

def find_settings_file(name, filesystem):
"""
Expand Down Expand Up @@ -69,8 +70,15 @@ def image_provider(config):
names = map(normalize, config.provider_spec.split(","))
instances = map(lambda name: providerByName[name](), names)
logger.debug("Creating with component providers: %s" % str(instances))
if len(instances) == 0:
logger.error("No image providers specified. Ice will run, but will not \
find grid images for your ROMs. If this wasnt intentional, \
see config.txt.")
# map() returns an interator in Python 3, so we have to check empty in a different way.
if sys.version_info[0] >= 3:
if not instances:
logger.error("No image providers specified. Ice will run, but will not \
find grid images for your ROMs. If this wasnt intentional, \
see config.txt.")
else:
if len(instances) == 0:
logger.error("No image providers specified. Ice will run, but will not \
find grid images for your ROMs. If this wasnt intentional, \
see config.txt.")
return CombinedProvider(*instances)
4 changes: 2 additions & 2 deletions ice/steam_grid_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from pysteam import grid
from pysteam import shortcuts

import roms
from . import roms

from logs import logger
from .logs import logger

class SteamGridUpdater(object):

Expand Down
Loading