def csvdata(cmdline): from sdaps import csvdata survey = model.survey.Survey.load(cmdline['project']) if cmdline['direction'] == 'export': return csvdata.csvdata_export(survey, survey.new_path('data_%i.csv'), cmdline['filter']) elif cmdline['direction'] == 'import': return csvdata.csvdata_import(survey, cmdline['file']) else: raise AssertionError
def csvdata(cmdline): from sdaps import csvdata from sdaps.utils.image import ImageWriter survey = model.survey.Survey.load(cmdline['project']) if cmdline['direction'] == 'export': if cmdline['output']: if cmdline['output'] == '-': outfd = os.dup(sys.stdout.fileno()) outfile = os.fdopen(outfd, 'w') else: filename = cmdline['output'] outfile = open(filename, 'w') else: filename = survey.new_path('data_%i.csv') outfile = open(filename, 'w') csvoptions = {'delimiter': cmdline['delimiter']} if cmdline['export_images'] or cmdline[ 'export_question_images'] and cmdline['output'] != '-': img_path = os.path.dirname(filename) img_prefix = os.path.join( os.path.splitext(os.path.basename(filename))[0], 'img') image_writer = ImageWriter(img_path, img_prefix) else: image_writer = None return csvdata.csvdata_export( survey, outfile, image_writer, filter=cmdline['filter'], export_images=cmdline['export_images'], export_question_images=cmdline['export_question_images'], export_quality=cmdline['export_quality'], csvoptions=csvoptions) elif cmdline['direction'] == 'import': return csvdata.csvdata_import(survey, open(cmdline['file'], 'r')) else: raise AssertionError
def csvdata(cmdline): from sdaps import csvdata from sdaps.utils.image import ImageWriter survey = model.survey.Survey.load(cmdline["project"]) if cmdline["direction"] == "export": if cmdline["output"]: if cmdline["output"] == "-": outfd = os.dup(sys.stdout.fileno()) outfile = os.fdopen(outfd, "w") else: filename = cmdline["output"] outfile = file(filename, "w") else: filename = survey.new_path("data_%i.csv") outfile = file(filename, "w") csvoptions = {"delimiter": cmdline["delimiter"]} if cmdline["export_images"] or cmdline["export_question_images"] and cmdline["output"] != "-": img_path = os.path.dirname(filename) img_prefix = os.path.join(os.path.splitext(os.path.basename(filename))[0], "img") image_writer = ImageWriter(img_path, img_prefix) else: image_writer = None return csvdata.csvdata_export( survey, outfile, image_writer, filter=cmdline["filter"], export_images=cmdline["export_images"], export_question_images=cmdline["export_question_images"], export_quality=cmdline["export_quality"], csvoptions=csvoptions, ) elif cmdline["direction"] == "import": return csvdata.csvdata_import(survey, file(cmdline["file"], "r")) else: raise AssertionError
def csvdata(cmdline): from sdaps import csvdata from sdaps.utils.image import ImageWriter survey = model.survey.Survey.load(cmdline['project']) if cmdline['direction'] == 'export': if cmdline['output']: if cmdline['output'] == '-': outfd = os.dup(sys.stdout.fileno()) outfile = os.fdopen(outfd, 'w') else: filename = cmdline['output'] outfile = open(filename, 'w') else: filename = survey.new_path('data_%i.csv') outfile = open(filename, 'w') csvoptions = { 'delimiter' : cmdline['delimiter'] } if cmdline['export_images'] or cmdline['export_question_images'] and cmdline['output'] != '-': img_path = os.path.dirname(filename) img_prefix = os.path.join(os.path.splitext(os.path.basename(filename))[0], 'img') image_writer = ImageWriter(img_path, img_prefix) else: image_writer = None return csvdata.csvdata_export(survey, outfile, image_writer, filter=cmdline['filter'], export_images=cmdline['export_images'], export_question_images=cmdline['export_question_images'], export_quality=cmdline['export_quality'], csvoptions=csvoptions) elif cmdline['direction'] == 'import': return csvdata.csvdata_import(survey, open(cmdline['file'], 'r')) else: raise AssertionError