def build_and_install_ranks(): print "Running: build_and_install_ranks" # Loading rayeval from the path it was installed to f, filename, description = imp.find_module('rayeval', [INSTALL_LIB_PATH]) if f is None: f, filename, description = imp.find_module('rayeval', [file_join(INSTALL_LIB_PATH, 'rayeval')]) rayeval_module = imp.load_module('rayeval', f, filename, description) global INSTALL_DATA_FILES_PATH global ARGV_OPTIONS if ARGV_OPTIONS['use_ranks_7'] is None: ranks_7_path = file_join(INSTALL_DATA_FILES_PATH, ARGV_OPTIONS['hand_ranks_7_file_name']) else: if not os.path.exists(ARGV_OPTIONS['use_ranks_7']): raise IOError, "Hand ranks 7 file not found: %s" % ARGV_OPTIONS['use_ranks_7'] ranks_7_path = os.path.abspath(ARGV_OPTIONS['use_ranks_7']) if ARGV_OPTIONS['use_ranks_9'] is None: ranks_9_path = file_join(INSTALL_DATA_FILES_PATH, ARGV_OPTIONS['hand_ranks_9_file_name']) else: if not os.path.exists(ARGV_OPTIONS['use_ranks_9']): raise IOError, "Hand ranks 9 file not found: %s" % ARGV_OPTIONS['use_ranks_9'] ranks_9_path = os.path.abspath(ARGV_OPTIONS['use_ranks_9']) if GENERATE_HAND_RANKS and ARGV_OPTIONS['use_ranks_7'] is None: rayeval_module.generate_handranks_7(ranks_7_path, not ARGV_OPTIONS['no_ranks_test']) if GENERATE_HAND_RANKS and ARGV_OPTIONS['use_ranks_9'] is None: rayeval_module.generate_handranks_9(ranks_9_path, ranks_7_path, not ARGV_OPTIONS['no_ranks_test']) if GENERATE_HAND_RANKS or ARGV_OPTIONS['use_ranks_7'] is not None or ARGV_OPTIONS['use_ranks_9'] is not None: f = open(resource_filename('rayeval', "__rayeval_ranks_path__.txt"), 'w') f.write(ranks_7_path + "\n") f.write(ranks_9_path) f.close()
def dump_db(): dump_db_file_name = 'cookcountyjail-%s.json' % str(date.today()) target_file_path = file_join(env.home, file_join(env.backup_dirs, dump_db_file_name)) with cd(env.path): with activate_cmd(): run('python ./manage.py dumpdata countyapi > %s' % target_file_path) with cd(env.backup_dirs): run('gzip -f %s' % dump_db_file_name) run('rm -f latest.json.gz; ln -s %s.gz latest.json.gz' % dump_db_file_name)
def build_and_install_ranks(): print "Running: build_and_install_ranks" # Loading rayeval from the path it was installed to f, filename, description = imp.find_module('rayeval', [INSTALL_LIB_PATH]) if f is None: f, filename, description = imp.find_module( 'rayeval', [file_join(INSTALL_LIB_PATH, 'rayeval')]) rayeval_module = imp.load_module('rayeval', f, filename, description) global INSTALL_DATA_FILES_PATH global ARGV_OPTIONS if ARGV_OPTIONS['use_ranks_7'] is None: ranks_7_path = file_join(INSTALL_DATA_FILES_PATH, ARGV_OPTIONS['hand_ranks_7_file_name']) else: if not os.path.exists(ARGV_OPTIONS['use_ranks_7']): raise IOError, "Hand ranks 7 file not found: %s" % ARGV_OPTIONS[ 'use_ranks_7'] ranks_7_path = os.path.abspath(ARGV_OPTIONS['use_ranks_7']) if ARGV_OPTIONS['use_ranks_9'] is None: ranks_9_path = file_join(INSTALL_DATA_FILES_PATH, ARGV_OPTIONS['hand_ranks_9_file_name']) else: if not os.path.exists(ARGV_OPTIONS['use_ranks_9']): raise IOError, "Hand ranks 9 file not found: %s" % ARGV_OPTIONS[ 'use_ranks_9'] ranks_9_path = os.path.abspath(ARGV_OPTIONS['use_ranks_9']) if GENERATE_HAND_RANKS and ARGV_OPTIONS['use_ranks_7'] is None: rayeval_module.generate_handranks_7(ranks_7_path, not ARGV_OPTIONS['no_ranks_test']) if GENERATE_HAND_RANKS and ARGV_OPTIONS['use_ranks_9'] is None: rayeval_module.generate_handranks_9(ranks_9_path, ranks_7_path, not ARGV_OPTIONS['no_ranks_test']) if GENERATE_HAND_RANKS or ARGV_OPTIONS[ 'use_ranks_7'] is not None or ARGV_OPTIONS[ 'use_ranks_9'] is not None: f = open(resource_filename('rayeval', "__rayeval_ranks_path__.txt"), 'w') f.write(ranks_7_path + "\n") f.write(ranks_9_path) f.close()
def run(self): filtered_data_files = [] for item in self.data_files: if len(item) == 2 and len(item[1]) > 0 and item[1][0] == ':hand_ranks': global INSTALL_DATA_FILES_PATH global GENERATE_HAND_RANKS global ARGV_OPTIONS GENERATE_HAND_RANKS = not ARGV_OPTIONS['without_build_ranks'] if ARGV_OPTIONS['ranks_dir'] is not None: INSTALL_DATA_FILES_PATH = ARGV_OPTIONS['ranks_dir'] else: INSTALL_DATA_FILES_PATH = file_join(self.install_dir, item[0]) if not os.path.exists(INSTALL_DATA_FILES_PATH): os.mkdir(INSTALL_DATA_FILES_PATH) else: filtered_data_files.append(item) self.data_files = filtered_data_files install_data.run(self)
def run(self): filtered_data_files = [] for item in self.data_files: if len(item) == 2 and len( item[1]) > 0 and item[1][0] == ':hand_ranks': global INSTALL_DATA_FILES_PATH global GENERATE_HAND_RANKS global ARGV_OPTIONS GENERATE_HAND_RANKS = not ARGV_OPTIONS['without_build_ranks'] if ARGV_OPTIONS['ranks_dir'] is not None: INSTALL_DATA_FILES_PATH = ARGV_OPTIONS['ranks_dir'] else: INSTALL_DATA_FILES_PATH = file_join( self.install_dir, item[0]) if not os.path.exists(INSTALL_DATA_FILES_PATH): os.mkdir(INSTALL_DATA_FILES_PATH) else: filtered_data_files.append(item) self.data_files = filtered_data_files install_data.run(self)
def migrate_tuto(tutos, title="Exporting mini tuto"): if len(tutos) == 0: return for i in progressbar(xrange(len(tutos)), title, 100): current = tutos[i] if not os.path.exists(current.get_path(False)): sys.stderr.write( 'Invalid physical path to repository « {} », skipping\n'. format(current.get_path(False))) continue exported = PublishableContent() exported.slug = current.slug exported.type = "TUTORIAL" exported.title = current.title exported.sha_draft = current.sha_draft exported.sha_beta = current.sha_beta exported.sha_validation = current.sha_validation exported.licence = current.licence exported.update_date = current.update exported.creation_date = current.create_at exported.description = current.description exported.js_support = current.js_support exported.source = current.source exported.pubdate = current.pubdate exported.save() try: clean_commit = copy_and_clean_repo(current.get_path(False), exported.get_repo_path(False)) except InvalidGitRepositoryError as e: exported.delete() sys.stderr.write( 'Repository in « {} » is invalid, skipping\n'.format(e)) continue if clean_commit: exported.sha_draft = clean_commit # save clean up in old module to avoid any trouble current.sha_draft = clean_commit current.save() exported.gallery = current.gallery exported.image = current.image [ exported.subcategory.add(category) for category in current.subcategory.all() ] [exported.helps.add(help) for help in current.helps.all()] [exported.authors.add(author) for author in current.authors.all()] exported.save() # now, re create the manifest.json versioned = exported.load_version() # this loop is there because of old .tuto import that failed with their chapter intros for container in versioned.traverse(True): if container.parent is None: continue # in old .tuto file chapter intro are represented as chapter_slug/introduction.md # instead of part_slug/chapter_slug/introduction.md corrected_intro_path = file_join( container.get_path(relative=False), "introduction.md") corrected_ccl_path = file_join(container.get_path(relative=False), "conclusion.md") if container.get_path(True) not in container.introduction: if file_exists(corrected_intro_path): container.introduction = file_join( container.get_path(relative=True), "introduction.md") else: container.introduction = None if container.get_path(True) not in container.conclusion: if file_exists(corrected_ccl_path): container.conclusion = file_join( container.get_path(relative=True), "conclusion.md") else: container.conclusion = None versioned.licence = exported.licence versioned.type = "TUTORIAL" versioned.dump_json() versioned.repository.index.add(['manifest.json' ]) # index new manifest before commit exported.sha_draft = versioned.commit_changes(u"Migration version 2") exported.old_pk = current.pk exported.save() # export beta forum post former_topic = Topic.objects.filter(key=current.pk).first() if former_topic is not None: former_topic.related_publishable_content = exported former_topic.save() former_first_post = former_topic.first_post() text = former_first_post.text text = text.replace(current.get_absolute_url_beta(), exported.get_absolute_url_beta()) former_first_post.update_content(text) former_first_post.save() exported.beta_topic = former_topic exported.save() # extract notes reacts = Note.objects.filter(tutorial__pk=current.pk)\ .select_related("author")\ .order_by("pubdate")\ .all() migrate_validation( exported, TutorialValidation.objects.filter(tutorial__pk=current.pk)) if current.last_note: export_comments(reacts, exported, TutorialRead, current.last_note.pk) if current.sha_public is not None and current.sha_public != "": published = publish_content( exported, exported.load_version(current.sha_public), False) exported.pubdate = current.pubdate exported.sha_public = current.sha_public exported.public_version = published exported.save() published.content_public_slug = exported.slug published.publication_date = current.pubdate published.save() # set mapping map_previous = PublishedContent() map_previous.content_public_slug = current.slug map_previous.content_pk = current.pk map_previous.content_type = 'TUTORIAL' map_previous.must_redirect = True # will send HTTP 301 if visited ! map_previous.content = exported map_previous.save() # fix strange notification bug authors = list(exported.authors.all()) reads_to_delete = ContentRead.objects\ .filter(content=exported)\ .exclude(user__pk__in=ContentReaction.objects .filter(related_content=exported) .exclude(author__in=authors) .values_list("author__pk", flat=True)) for read in reads_to_delete.all(): read.delete()
) parser.add_argument('hand_id', metavar='hand_id', type=str, help='Hand (or game) id') parser.add_argument('-d', '--dir', type=str, dest='dir', help='directory with hand history files') parser.add_argument('-f', '--files', type=str, dest='files', help='list hand history files') parser.add_argument('-o', type=str, dest='out', help='file name to print found hands (by default stdout)') parser.add_argument('--no-progressbar', action="store_true", dest='no_progressbar', help='don\'t print a progressbar') parser.add_argument('--find-all', action="store_true", help='search for all occurrences of the hand_id') parser.add_argument('--version', action='version', version='%(prog)s 1.0.0') args = parser.parse_args() files = [] if args.dir is not None: for f in os.listdir(args.dir): files.append(file_join(args.dir, f)) elif args.files is not None: files = args.files else: parser.print_help() exit(1) hand_id = args.hand_id find_all = args.find_all out = sys.stdout if args.out is None else open(args.out, 'wb') files_iter = progressbar.ProgressBar()(files) if not args.no_progressbar else files for fname in files_iter: in_hand = False f = open(fname, 'rb') line = f.readline(1000)
action="store_true", dest='no_progressbar', help='don\'t print a progressbar') parser.add_argument('--find-all', action="store_true", help='search for all occurrences of the hand_id') parser.add_argument('--version', action='version', version='%(prog)s 1.0.0') args = parser.parse_args() files = [] if args.dir is not None: for f in os.listdir(args.dir): files.append(file_join(args.dir, f)) elif args.files is not None: files = args.files else: parser.print_help() exit(1) hand_id = args.hand_id find_all = args.find_all out = sys.stdout if args.out is None else open(args.out, 'wb') files_iter = progressbar.ProgressBar()( files) if not args.no_progressbar else files for fname in files_iter: in_hand = False f = open(fname, 'rb')