Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Converting to Python 3 #693

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/freeseer.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
master_doc = 'index'

# General information about the project.
project = u'Freeseer'
copyright = u'© 2011-2014 Free and Open Source Software Learning Centre'
project = 'Freeseer'
copyright = '© 2011-2014 Free and Open Source Software Learning Centre'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -182,8 +182,8 @@
latex_documents = [(
'index', # source start file
'Freeseer.tex', # target name
u'Freeseer Documentation', # title
u'Free and Open Source Software Learning Centre', # author
'Freeseer Documentation', # title
'Free and Open Source Software Learning Centre', # author
'manual' # documentclass [howto/manual]
)]

Expand Down Expand Up @@ -216,6 +216,6 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'freeseer', u'Freeseer Documentation',
[u'Free and Open Source Software Learning Centre'], 1)
('index', 'freeseer', 'Freeseer Documentation',
['Free and Open Source Software Learning Centre'], 1)
]
18 changes: 6 additions & 12 deletions src/freeseer/framework/config/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@
from freeseer.framework.config.exceptions import StorageNotSetError


class Option(object):
class Option(object, metaclass=abc.ABCMeta):
"""Represents a Config option."""

__metaclass__ = abc.ABCMeta

class NotSpecified(object):
pass

Expand Down Expand Up @@ -98,7 +96,7 @@ def __new__(meta, name, bases, class_attributes):
class_attributes, options = meta.find_options(class_attributes)
class_attributes['options'] = options
cls = super(ConfigBase, meta).__new__(meta, name, bases, class_attributes)
for opt_name, option in options.iteritems():
for opt_name, option in options.items():
opt_get = functools.partial(cls.get_value, name=opt_name, option=option, presentation=True)
opt_set = functools.partial(cls._set_value, name=opt_name, option=option)
setattr(cls, opt_name, property(opt_get, opt_set))
Expand All @@ -118,7 +116,7 @@ def find_options(class_attributes):
return new_attributes, options


class Config(object):
class Config(object, metaclass=ConfigBase):
"""Base class for all custom configs.

To be useful, its body must contain some number of Option instances.
Expand All @@ -128,8 +126,6 @@ class MyConfig(Config):
test = StringOption('default_value')
"""

__metaclass__ = ConfigBase

def __init__(self, storage=None, storage_args=None):
"""
Params:
Expand All @@ -149,7 +145,7 @@ def _set_value(self, value, name, option):

def set_defaults(self):
"""Sets the values of all options to their default value (if applicable)."""
for name, option in self.options.iteritems():
for name, option in self.options.items():
if not option.is_required():
self.set_value(name, option, option.default)

Expand Down Expand Up @@ -210,7 +206,7 @@ def schema(cls):
'properties': {},
}

for name, instance in cls.options.iteritems():
for name, instance in cls.options.items():
schema['properties'][name] = instance.schema()
if instance.is_required():
required.append(name)
Expand All @@ -221,11 +217,9 @@ def schema(cls):
return schema


class ConfigStorage(object):
class ConfigStorage(object, metaclass=abc.ABCMeta):
"""Defines an interface for loading and storing Config instances."""

__metaclass__ = abc.ABCMeta

def __init__(self, filepath):
"""
Params:
Expand Down
6 changes: 3 additions & 3 deletions src/freeseer/framework/config/persist/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# For support, questions, suggestions or any other inquiries, visit:
# http://wiki.github.com/Freeseer/freeseer/

import ConfigParser
from . import ConfigParser

from freeseer.framework.config.core import ConfigStorage

Expand All @@ -34,7 +34,7 @@ def load(self, config_instance, section):
parser = ConfigParser.ConfigParser()
parser.read([self._filepath])

for name, option in config_instance.options.iteritems():
for name, option in config_instance.options.items():
if parser.has_option(section, name):
raw = parser.get(section, name)
clean = option.decode(raw)
Expand All @@ -49,7 +49,7 @@ def store(self, config_instance, section):
if not parser.has_section(section):
parser.add_section(section)

for name, option in config_instance.options.iteritems():
for name, option in config_instance.options.items():
raw = config_instance.get_value(name, option)
clean = option.encode(raw)
parser.set(section, name, clean)
Expand Down
4 changes: 2 additions & 2 deletions src/freeseer/framework/config/persist/jsonstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def load(self, config_instance, section):
if section not in dict_:
return config_instance

for name, option in config_instance.options.iteritems():
for name, option in config_instance.options.items():
if name in dict_[section]:
raw = dict_[section][name]
clean = option.decode(raw)
Expand All @@ -61,7 +61,7 @@ def store(self, config_instance, section):
if section not in dict_:
dict_[section] = {}

for name, option in config_instance.options.iteritems():
for name, option in config_instance.options.items():
raw = config_instance.get_value(name, option)
clean = option.encode(raw)
dict_[section][name] = clean
Expand Down
2 changes: 1 addition & 1 deletion src/freeseer/framework/config/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_storage(self, name):
It will also be cached for future invocations of this method.
"""
if name not in self._storages:
for suffix, engine in self.STORAGE_MAP.iteritems():
for suffix, engine in self.STORAGE_MAP.items():
if name.endswith(suffix):
self._storages[name] = engine(self.get_filepath(name))
break
Expand Down
68 changes: 34 additions & 34 deletions src/freeseer/framework/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,33 @@ def get_talks_by_room_and_time(self, room):
def get_presentation(self, talk_id):
"""Returns a Presentation object associated to a talk_id"""
result = QtSql.QSqlQuery('''SELECT * FROM presentations WHERE Id="%s"''' % talk_id)
if result.next():
return Presentation(title=unicode(result.value(1).toString()),
speaker=unicode(result.value(2).toString()),
description=unicode(result.value(3).toString()),
category=unicode(result.value(4).toString()),
event=unicode(result.value(5).toString()),
room=unicode(result.value(6).toString()),
date=unicode(result.value(7).toString()),
startTime=unicode(result.value(8).toString()),
endTime=unicode(result.value(9).toString()))
if next(result):
return Presentation(title=str(result.value(1).toString()),
speaker=str(result.value(2).toString()),
description=str(result.value(3).toString()),
category=str(result.value(4).toString()),
event=str(result.value(5).toString()),
room=str(result.value(6).toString()),
date=str(result.value(7).toString()),
startTime=str(result.value(8).toString()),
endTime=str(result.value(9).toString()))
else:
return None

def get_string_list(self, column):
"""Returns a column as a QStringList"""
tempList = QStringList()
result = QtSql.QSqlQuery('''SELECT DISTINCT %s FROM presentations''' % column)
while result.next():
while next(result):
tempList.append(result.value(0).toString())
return tempList

def presentation_exists(self, presentation):
"""Checks if there's a presentation with the same Speaker and Title already stored"""
result = QtSql.QSqlQuery('''SELECT * FROM presentations''')
while result.next():
if (unicode(presentation.title) == unicode(result.value(1).toString())
and unicode(presentation.speaker) == unicode(result.value(2).toString())):
while next(result):
if (str(presentation.title) == str(result.value(1).toString())
and str(presentation.speaker) == str(result.value(2).toString())):
return True
return False

Expand Down Expand Up @@ -374,7 +374,7 @@ def get_talk_between_time(self, event, room, startTime, endTime):
WHERE Event='%s' AND Room='%s' \
AND Date BETWEEN '%s' \
AND '%s' ORDER BY Date ASC" % (event, room, startTime, endTime))
query.next()
next(query)
if query.isValid():
return query.value(0)
else:
Expand Down Expand Up @@ -458,17 +458,17 @@ def export_talks_to_csv(self, fname):
writer.writerow(headers)

result = self.get_talks()
while result.next():
log.debug(unicode(result.value(1).toString()))
writer.writerow({'Title': unicode(result.value(1).toString()),
'Speaker': unicode(result.value(2).toString()),
'Abstract': unicode(result.value(3).toString()),
'Category': unicode(result.value(4).toString()),
'Event': unicode(result.value(5).toString()),
'Room': unicode(result.value(6).toString()),
'Date': unicode(result.value(7).toString()),
'StartTime': unicode(result.value(8).toString()),
'EndTime': unicode(result.value(9).toString())})
while next(result):
log.debug(str(result.value(1).toString()))
writer.writerow({'Title': str(result.value(1).toString()),
'Speaker': str(result.value(2).toString()),
'Abstract': str(result.value(3).toString()),
'Category': str(result.value(4).toString()),
'Event': str(result.value(5).toString()),
'Room': str(result.value(6).toString()),
'Date': str(result.value(7).toString()),
'StartTime': str(result.value(8).toString()),
'EndTime': str(result.value(9).toString())})
finally:
file.close()

Expand Down Expand Up @@ -520,10 +520,10 @@ def clear_report_db(self):
def get_report(self, talkid):
"""Returns a failure from a given talkid. Returned value is a Failure object"""
result = QtSql.QSqlQuery('''SELECT * FROM failures WHERE Id = "%s"''' % talkid)
if result.next():
failure = Failure(unicode(result.value(0).toString()), # id
unicode(result.value(1).toString()), # comment
unicode(result.value(2).toString()), # indicator
if next(result):
failure = Failure(str(result.value(0).toString()), # id
str(result.value(1).toString()), # comment
str(result.value(2).toString()), # indicator
result.value(3).toBool()) # release
else:
failure = None
Expand All @@ -533,10 +533,10 @@ def get_reports(self):
"""Returns a list of failures in Report format"""
result = QtSql.QSqlQuery('''Select * FROM failures''')
list = []
while result.next():
failure = Failure(unicode(result.value(0).toString()), # id
unicode(result.value(1).toString()), # comment
unicode(result.value(2).toString()), # indicator
while next(result):
failure = Failure(str(result.value(0).toString()), # id
str(result.value(1).toString()), # comment
str(result.value(2).toString()), # indicator
bool(result.value(3))) # release
p = self.get_presentation(failure.talkId)
r = Report(p, failure)
Expand Down
14 changes: 7 additions & 7 deletions src/freeseer/framework/qt_key_grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ def __init__(self, parent=None):
def keyPressEvent(self, event):
other = None
if event.key() == QtCore.Qt.Key_Shift:
self.modifiers[QtCore.Qt.Key_Shift] = u'Shift'
self.modifiers[QtCore.Qt.Key_Shift] = 'Shift'
elif event.key() == QtCore.Qt.Key_Control:
self.modifiers[QtCore.Qt.Key_Control] = u'Ctrl'
self.modifiers[QtCore.Qt.Key_Control] = 'Ctrl'
elif event.key() == QtCore.Qt.Key_Alt:
self.modifiers[QtCore.Qt.Key_Alt] = u'Alt'
self.modifiers[QtCore.Qt.Key_Alt] = 'Alt'
elif event.key() == QtCore.Qt.Key_Meta:
self.modifiers[QtCore.Qt.Key_Meta] = u'Meta'
self.modifiers[QtCore.Qt.Key_Meta] = 'Meta'
else:
other = event.text()
if other:
if QtCore.Qt.Key_Control in self.modifiers:
self.key_string = u'+'.join(self.modifiers.values() + [unicode(chr(event.key()))])
self.key_string = '+'.join(list(self.modifiers.values()) + [str(chr(event.key()))])
else:
self.key_string = u'+'.join(self.modifiers.values() + [unicode(other)])
self.key_string = '+'.join(list(self.modifiers.values()) + [str(other)])
else:
self.key_string = u'+'.join(self.modifiers.values())
self.key_string = '+'.join(list(self.modifiers.values()))
if (self.parent.core.config.key_rec == 'Ctrl+Shift+R'):
self.flag = True

Expand Down
10 changes: 5 additions & 5 deletions src/freeseer/framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def make_record_name(presentation):
make_shortname(presentation.speaker),
make_shortname(presentation.title),
]
record_name = unicode('-'.join(tag for tag in tags if tag))
record_name = str('-'.join(tag for tag in tags if tag))

# Convert unicode filenames to their equivalent ascii so that
# we don't run into issues with gstreamer or filesystems.
Expand Down Expand Up @@ -121,7 +121,7 @@ def reset(configdir):
if confirm_yes() is True:
shutil.rmtree(configdir)
else:
print("%s is not a invalid configuration directory." % configdir)
print(("%s is not a invalid configuration directory." % configdir))


def reset_configuration(configdir, profile='default'):
Expand All @@ -139,7 +139,7 @@ def reset_configuration(configdir, profile='default'):
if os.path.exists(plugin_conf):
os.remove(plugin_conf)
else:
print("%s is not a invalid configuration directory." % configdir)
print(("%s is not a invalid configuration directory." % configdir))


def reset_database(configdir, profile='default'):
Expand All @@ -153,7 +153,7 @@ def reset_database(configdir, profile='default'):
if os.path.exists(dbfile):
os.remove(dbfile)
else:
print("%s is not a invalid configuration directory." % configdir)
print(("%s is not a invalid configuration directory." % configdir))


def validate_configdir(configdir):
Expand All @@ -168,7 +168,7 @@ def validate_configdir(configdir):

def confirm_yes():
"""Prompts the user to confirm by typing 'yes' in response"""
confirm = raw_input("Enter 'yes' to confirm: ")
confirm = input("Enter 'yes' to confirm: ")
if confirm == 'yes':
return True
return False
Loading