Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print cformat(' %{blue!}Aspect:%{reset} {}').format(a.name)
l.aspects.append(a)
if old_aspect.defaultOnStartup:
l.default_aspect = a
# add custom attributes
for ca in custom_attributes_dict.get(l.name, []):
if ca['type'] != 'str':
raise RuntimeError('Non-str custom attributes are unsupported: {}'.format(ca))
attr_name = attribute_map.get(ca['name'], ca['name'])
attr = RoomAttribute(name=attr_name.replace(' ', '-').lower(), title=attr_name, type=ca['type'],
is_required=ca['required'], is_hidden=ca['hidden'])
l.attributes.append(attr)
print cformat(' %{blue!}Attribute:%{reset} {}').format(attr.title)
# add new created location
db.session.add(l)
print
print
db.session.commit()
def _migrate_timetable(self):
if not self.importer.quiet:
self.importer.print_info(cformat('%{green}Timetable...'))
self._migrate_timetable_entries(self.old_event._Conference__schedule._entries)
agent.backend_name = 'invenio'
agent.settings = {
'server_url': old_agent._url
}
elif old_agent_class == 'CERNSearchUploadAgent':
agent.backend_name = 'cernsearch'
agent.settings = {
'server_url': old_agent._url,
'username': old_agent._username,
'password': old_agent._password,
}
else:
print cformat('%{red!}skipping unknown agent type: {}%{reset}').format(old_agent_class)
continue
print cformat('- %{cyan}{} ({})').format(agent.name, agent.backend_name)
db.session.add(agent)
continue
review.proposed_contribution_type = old_judgment.accepted_type
review.proposed_track = self.track_map_by_id[old_judgment.track_id]
elif review.proposed_action == AbstractAction.change_tracks:
review.proposed_tracks = {self.track_map[t] for t in zodb_judgment._proposedTracks}
elif review.proposed_action == AbstractAction.mark_as_duplicate:
as_duplicate_reviews.add((review, zodb_judgment._originalAbst))
review.user = judge
review.track = track
answered_questions = set()
for old_answer in getattr(zodb_judgment, '_answers', []):
if old_answer._question in answered_questions:
self.importer.print_warning(
cformat("%{blue!}Abstract {}: {yellow}question answered more than once!").format(
abstract.friendly_id), event_id=self.event.id)
continue
try:
question = self.question_map[old_answer._question]
except KeyError:
question = self._migrate_question(old_answer._question, is_deleted=True)
self.importer.print_warning(
cformat("%{blue!}Abstract {}: {yellow}answer for deleted question").format(
abstract.friendly_id), event_id=self.event.id)
rating = AbstractReviewRating(question=question, value=self._convert_scale(old_answer))
review.ratings.append(rating)
answered_questions.add(old_answer._question)
abstract.reviews.append(review)
def _migrate_tracks(self):
program = convert_to_unicode(getattr(self.conf, 'programDescription', ''))
if program:
track_settings.set_multi(self.event, {'program_render_mode': RenderMode.html, 'program': program})
for pos, old_track in enumerate(self.conf.program, 1):
track = Track(title=convert_to_unicode(old_track.title),
description=convert_to_unicode(old_track.description),
code=convert_to_unicode(old_track._code),
position=pos,
abstract_reviewers=set())
self.importer.print_info(cformat('%{white!}Track:%{reset} {}').format(track.title))
for coordinator in old_track._coordinators:
user = self._user_from_legacy(coordinator)
if user is None:
continue
self.importer.print_info(cformat('%{blue!} Coordinator:%{reset} {}').format(user))
track.conveners.add(user)
track.abstract_reviewers.add(user)
self.event.update_principal(user, add_roles={'abstract_reviewer', 'track_convener'}, quiet=True)
self.track_map[old_track] = track
self.track_map_by_id[int(old_track.id)] = track
self.event.tracks.append(track)
def _migrate_timetable_entries(self, old_entries, session_block=None):
for old_entry in old_entries:
item_type = old_entry.__class__.__name__
if item_type == 'ContribSchEntry':
entry = self._migrate_contribution_timetable_entry(old_entry, session_block)
elif item_type == 'BreakTimeSchEntry':
entry = self._migrate_break_timetable_entry(old_entry, session_block)
elif item_type == 'LinkedTimeSchEntry':
parent = old_entry._LinkedTimeSchEntry__owner
parent_type = parent.__class__.__name__
if parent_type == 'Contribution':
self.importer.print_warning(cformat('%{yellow!}Found LinkedTimeSchEntry for contribution'),
event_id=self.event.id)
entry = self._migrate_contribution_timetable_entry(old_entry, session_block)
elif parent_type != 'SessionSlot':
self.importer.print_error(cformat('%{red!}Found LinkedTimeSchEntry for {}').format(parent_type),
event_id=self.event.id)
continue
else:
assert session_block is None
entry = self._migrate_block_timetable_entry(old_entry)
else:
raise ValueError('Unexpected item type: ' + item_type)
if session_block:
if entry.start_dt < session_block.timetable_entry.start_dt:
self.importer.print_warning(cformat('%{yellow!}Block boundary (start) violated; extending block '
'from {} to {}').format(session_block.timetable_entry.start_dt,
entry.start_dt),
def main():
models = {model: make_query(model).count() for model in StoredFileMixin.__subclasses__()}
models = {model: total for model, total in models.iteritems() if total}
labels = {model: cformat('Processing %{blue!}{}%{reset} (%{cyan}{}%{reset} rows)').format(model.__name__, total)
for model, total in models.iteritems()}
max_length = max(len(x) for x in labels.itervalues())
labels = {model: label.ljust(max_length) for model, label in labels.iteritems()}
for model, total in sorted(models.items(), key=itemgetter(1)):
with click.progressbar(query_chunked(model, 100), length=total, label=labels[model],
show_percent=True, show_pos=True) as objects:
for obj in objects:
try:
with obj.open() as f:
checksum = get_file_checksum(f)
except Exception as exc:
click.echo(cformat('\n%{red!}Could not open %{reset}%{yellow}{}%{red!}: %{reset}%{yellow!}{}')
.format(obj, exc))
else:
obj.md5 = checksum
def _migrate_reason_section(self, form):
if not form._enabled and not any(x._reasonParticipation for x in self.event._registrants.itervalues()):
return
section = RegistrationFormSection(registration_form=self.regform, title=_sanitize(form._title),
description=_sanitize(form._description, html=True))
self.importer.print_info(cformat('%{green!}Section/Reason%{reset} - %{cyan}{}').format(section.title))
field = self.reason_field = RegistrationFormField(registration_form=self.regform, title='Reason',
input_type='textarea')
field.data, field.versioned_data = field.field_impl.process_field_data({'number_of_rows': 4})
section.children.append(field)
def migrate_category_attachments(self):
self.print_step('migrating category attachments')
for category, material, resources in self._committing_iterator(self._iter_category_materials()):
folder = self._folder_from_material(material, category)
if not self.quiet:
self.print_success(cformat('%{cyan}[{}]').format(folder['title']), event_id=category.id)
for resource in resources:
attachment = self._attachment_from_resource(folder, material, resource, category)
if attachment is None:
continue
if not self.quiet:
if attachment['type'] == AttachmentType.link:
self.print_success(cformat('- %{cyan}{}').format(attachment['title']), event_id=category.id)
else:
self.print_success(cformat('- %{cyan!}{}').format(attachment['title']), event_id=category.id)
'{:.02f}'.format(price) if billable and price else ''))
attrs = {}
if field.input_type in {'text', 'textarea', 'email'}:
if isinstance(old_item._value, basestring):
attrs['data'] = convert_to_unicode(old_item._value)
else:
self.importer.print_warning(cformat("Non-string '%{red}{!r}%{reset}' in {} field")
.format(old_item._value, field.input_type), event_id=self.event.id)
attrs['data'] = unicode(old_item._value)
elif field.input_type == 'number':
if not isinstance(old_item._value, (int, float)) and not old_item._value:
return
try:
attrs['data'] = float(old_item._value)
except ValueError:
self.importer.print_warning(cformat("Garbage number '%{red}{0}%{reset}' in number field")
.format(old_item._value), event_id=self.event.id)
else:
if attrs['data'] == int(attrs['data']):
# if we store a float we keep an ugly '.0'
attrs['data'] = int(attrs['data'])
data_version = self._ensure_version_price(field, billable, price) or data_version
elif field.input_type == 'phone':
attrs['data'] = normalize_phone_number(convert_to_unicode(old_item._value))
elif field.input_type == 'date':
if old_item._value:
dt = (datetime.strptime(old_item._value, field.data['date_format'])
if isinstance(old_item._value, basestring)
else old_item._value)
attrs['data'] = dt.isoformat()
elif field.input_type in {'bool', 'checkbox'}:
attrs['data'] = old_item._value == 'yes'