def switch_radio(self): old_frequencies = cobj('radio').contents.all() new_freq_dict = dict() for old_freq in [freq for freq in old_frequencies if freq.name.startswith('FREQ:')]: toss, freq_str = old_freq.name.split(' ', 1) new_freq, created = RadioFrequency.objects.get_or_create(key=freq_str) new_freq.setup() new_freq_dict[freq_str] = new_freq characters = [char for char in Character.objects.filter_family() if hasattr(char, 'mush')] for char in characters: for old_slot in char.mush.lattr('D`RADIO`*'): old_freq = char.mush.mushget(old_slot) old_name = char.mush.mushget(old_slot + '`NAME') old_title = char.mush.mushget(old_slot + '`TITLE') old_code = char.mush.mushget(old_slot + '`CODENAME') if old_freq not in new_freq_dict: new_freq, created2 = RadioFrequency.objects.get_or_create(key=old_freq) new_freq.setup() new_freq_dict[old_freq] = new_freq new_freq = new_freq_dict[old_freq] new_slot, created3 = char.radio.get_or_create(key=old_name, frequency=new_freq) if old_title: new_slot.title = old_title if old_code: new_slot.codename = old_code new_slot.save() new_slot.frequency.channel.connect(char)
def switch_fclist(self): old_themes = cobj('themedb').children.all() for old_theme in old_themes: new_theme, created = FCList.objects.get_or_create(key=old_theme.name) desc = old_theme.mushget('DESCRIBE') if desc: new_theme.description = desc powers = old_theme.mushget('POWERS') if powers: new_theme.powers = powers info = old_theme.mushget('INFO') if info: new_theme.info = info old_characters = [objmatch(char) for char in old_theme.mushget('CAST').split(' ') if objmatch(char)] for char in old_characters: if not char.obj: continue type = char.mushget('D`FINGER`TYPE') or 'N/A' status = char.mushget('D`FINGER`STATUS') or 'N/A' stat_kind, created = StatusKind.objects.get_or_create(key=status) type_kind, created = TypeKind.objects.get_or_create(key=type) stat_kind.characters.get_or_create(character=char.obj) type_kind.characters.get_or_create(character=char.obj) new_theme.cast.add(char.obj) new_theme.save()
def switch_grid(self): mush_rooms = MushObject.objects.filter(type=1) if not mush_rooms: self.error("No rooms to import.") return for mush_room in mush_rooms: if mush_room.obj: new_room = self.update_room(mush_room) else: new_room = self.create_room(mush_room) self.update_room(mush_room) for mush_exit in MushObject.objects.filter(type=4, obj=None): self.create_exit(mush_exit) district_parent = cobj(abbr='district') if not district_parent: self.error("Could not find old District Parent.") return old_districts = sorted(district_parent.children.all(), key=lambda dist: int(dist.mushget('order') or 500)) for old_district in old_districts: new_district, created = District.objects.get_or_create(key=old_district.name) new_district.ic = bool(int(old_district.mushget('d`ic') or 0)) new_district.order = int(old_district.mushget('order') or 500) rooms = old_district.children.all() for room in rooms: new_district.rooms.add(room.obj) new_district.save()
def switch_bbs(self): penn_boards = cobj('bbs').contents.all() board_group, created5 = BoardGroup.objects.get_or_create(main=1, group=None) for old_board in penn_boards: if not old_board.board: old_board.board = board_group.make_board(key=old_board.name) old_board.save(update_fields=['board']) new_board = old_board.board old_order = int(old_board.mushget('ORDER')) new_board.order = old_order new_board.save() self.convert_board(new_board)
def switch_groups(self): penn_groups = cobj('gop').children.all() for old_group in penn_groups: if not old_group.group: old_group.group, created = Group.objects.get_or_create(key=old_group.name) old_group.save(update_fields=['group']) new_group = old_group.group new_group.description = old_group.mushget('DESCRIBE') old_ranks = old_group.lattrp('RANK`\d+') old_rank_nums = [old_rank.split('`', 1)[1] for old_rank in old_ranks] rank_dict = dict() for num in old_rank_nums: new_rank, created = new_group.ranks.get_or_create(num=int(num)) rank_name = old_group.mushget('RANK`%s`NAME' % num) if rank_name: new_rank.name = sanitize_string(rank_name) new_rank.save(update_fields=['name']) rank_dict[int(num)] = new_rank old_members = [objmatch(member) for member in old_group.mushget('MEMBERS').split(' ') if objmatch(member)] for old_member in old_members: if not old_member.obj: continue old_num = int(old_member.mushget('D`GROUP`%s`RANK' % old_group.dbref)) or 4 title = old_member.mushget('D`GROUP`%s`NAME' % old_group.dbref) if not title: title = None new_member, created = new_group.participants.get_or_create(character=old_member.obj, title=title, rank=rank_dict[old_num]) for channel in [new_group.ic_channel, new_group.ooc_channel]: if channel: if channel.locks.check(new_member.character, 'listen'): channel.connect(new_member.character) new_group.save() board_group, created = BoardGroup.objects.get_or_create(main=0, group=new_group) for old_board in old_group.contents.all(): if not old_board.board: old_board.board = board_group.make_board(key=old_board.name) old_board.save(update_fields=['board']) new_board = old_board.board old_order = int(old_board.mushget('ORDER')) new_board.order = old_order new_board.save() self.convert_board(new_board)
def switch_accounts(self): char_typeclass = settings.BASE_CHARACTER_TYPECLASS accounts = cobj(abbr='accounts').children.all() for acc_obj in sorted(accounts, key=lambda acc: int(acc.name.split(' ')[1])): name = 'MushAcc %s' % acc_obj.name.split(' ')[1] password = str(random.randrange(5000000,1000000000)) email = acc_obj.mushget('email') or None new_player = create.create_player(name, email, password) new_player.db._import_ready = True new_player.db._reset_username = True if new_player.email == '*****@*****.**': new_player.db._reset_email = True objids = acc_obj.mushget('characters').split(' ') mush_chars = MushObject.objects.filter(objid__in=objids) for char in mush_chars: new_char = create.create_object(typeclass=char_typeclass, key=char.name) new_char.db.prelogout_location = char.location.obj char.obj = new_char char.save(update_fields=['obj']) new_player.bind_character(new_char) new_char.db._import_ready = True unbound = MushObject.objects.filter(type=8, obj=None) if unbound: name = 'Lost and Found' password = str(random.randrange(5000000,1000000000)) email = None new_player = create.create_player(name, email, password) new_player.db._lost_and_found = True for char in unbound: new_char = create.create_object(typeclass=char_typeclass, key=char.name) new_char.db.prelogout_location = char.location.obj char.obj = new_char char.save(update_fields=['obj']) new_player.bind_character(new_char) new_char.db._import_ready = True self.sys_msg("Finished importing characters!")
def switch_jobs(self): # Step one is importing all of the Job Categories from the MUSH data. Each category is a THING object # So we don't need mysql just yet. cat_dict = dict() old_categories = cobj('jobdb').children.all() for old_cat in old_categories: new_cat, created = JobCategory.objects.get_or_create(key=old_cat.name) if created: new_cat.setup() cat_dict[old_cat.objid] = new_cat # Establishing Mysql Connection! from commands.mysql import sql_dict db = MySQLdb.connect(host=sql_dict['site'], user=sql_dict['username'], passwd=sql_dict['password'], db=sql_dict['database'], cursorclass=cursors.DictCursor) c = db.cursor() # Our next order of business is retrieving all of the players who've ever posted jobs. # This section searches the database by OBJID and creates a dictionary that links the old jobsys player_id # to the new communications.ObjectStub, creating them if necessary. c.execute("""SELECT * from jobsys_players""") old_players = c.fetchall() char_dict = dict() for old_player in old_players: match = objmatch(old_player['objid']) if match: char = match.obj else: key = old_player['player_name'] char = create.create_object(typeclass='classes.characters.BaseCharacter', key=key) objid = old_player['objid'] dbref, csecs = objid.split(':', 1) cdate = from_unixtimestring(csecs) MushObject.objects.create(objid=objid, dbref=dbref, created=cdate, type=8, recreated=1, obj=char) char_dict[old_player['player_id']] = char # Now that we have the Player ID->Stub dictionary, we can begin the process of actually importing job data! # we only want the jobs from categories that actually exist. Probably rare that any of them wouldn't be, but # just in case... cat_list = ', '.join("'%s'" % cat for cat in cat_dict.keys()) c.execute("""SELECT * from jobsys_jobs WHERE job_objid IN (%s) ORDER BY job_id""" % cat_list) old_jobs = c.fetchall() for row in old_jobs: job_id = row['job_id'] if row['close_date']: close_date = row['close_date'].replace(tzinfo=pytz.utc) else: close_date = None if row['due_date']: due_date = row['due_date'].replace(tzinfo=pytz.utc) else: due_date = None if row['submit_date']: submit_date = row['submit_date'].replace(tzinfo=pytz.utc) else: submit_date = None title = row['job_title'] status = row['job_status'] owner = char_dict[row['player_id']] text = penn_substitutions(row['job_text']) category = cat_dict[row['job_objid']] handler_dict = dict() # We have our job row data prepped! Now to create the job and its opening comment as well as the owner-handler. new_job = category.jobs.create(title=title, submit_date=submit_date, due_date=due_date, close_date=close_date, status=status) new_owner = new_job.characters.create(character=owner, is_owner=True, check_date=utcnow()) new_owner.comments.create(text=text, date_made=submit_date) handler_dict[row['player_id']] = new_owner # Here it's time to import all of the job's claims, handlers, watchers, and create JobHandler rows for them. c.execute("""SELECT * from jobsys_claim WHERE job_id=%s""", (job_id,)) claim_data = c.fetchall() for old_claim in claim_data: stub = char_dict[old_claim['player_id']] new_handler, created = new_job.characters.get_or_create(character=stub, check_date=utcnow()) if old_claim['claim_mode'] == 0: new_handler.is_handler = True if old_claim['claim_mode'] == 1: new_handler.is_helper = True new_handler.save() handler_dict[old_claim['player_id']] = new_handler # Unfortunately it's also possible that people who didn't claim it might also need JobHandler entries so... c.execute("""SELECT DISTINCT player_id from jobsys_comments WHERE job_id=%s""", (job_id,)) all_speakers = c.fetchall() for speaker in all_speakers: if speaker['player_id'] not in handler_dict: new_handler, created = new_job.characters.get_or_create(character=char_dict[speaker['player_id']], check_date=utcnow()) handler_dict[speaker['player_id']] = new_handler # And another round. This time it's a matter of importing handlers for anyone who ever CHECKED a job. # Here we'll also import everyone's 'last date they checked the job'. c.execute("""SELECT * FROM jobsys_check WHERE job_id=%s""", (job_id,)) old_checks = c.fetchall() for check in old_checks: if check['player_id'] not in handler_dict: handler, created = new_job.characters.get_or_create(character=char_dict[check['player_id']], check_date=utcnow()) handler_dict[check['player_id']] = new_handler else: handler = handler_dict[check['player_id']] handler.check_date = check['check_date'].replace(tzinfo=pytz.utc) handler.save(update_fields=['check_date']) # Now to import all of the comments and replies. c.execute("""SELECT * from jobsys_comments WHERE job_id=%s ORDER BY comment_id""", (job_id,)) old_comments = c.fetchall() for old_com in old_comments: handler = handler_dict[old_com['player_id']] comment_text = penn_substitutions(old_com['comment_text']) comment_date = old_com['comment_date'].replace(tzinfo=pytz.utc) private = old_com['comment_type'] handler.comments.create(text=comment_text, date_made=comment_date, is_private=private) db.close()