Ejemplo n.º 1
0
def discover_exporter():
    patterns = __flatten_patterns_tree__(urls.urlpatterns)
    list_add_exporters = []
    list_update_exporters = []

    try:
        for pattern in patterns:
            try:
                #We try to instanciate the exporter to be sure that it will worked. If not, just print an error in the python console
                instance = get_exporter(pattern['view'])
                currentExporter = None
                try:
                    currentExporter = Exporter.objects.get(name=pattern['name'])
                except Exception, e:
                    pass

                update = Exporter.objects.filter(name=pattern['name']).update(set__url=pattern['view'], set__name=pattern['name'], set__available_for_all = pattern['available_for_all'], upsert=True, full_result=True)
                if update['updatedExisting'] == False:
                    list_add_exporters.append(pattern['name'])
                    #Check if this new exporter is available for all. If yes, we add this exporter by default for all templates
                    if pattern['available_for_all'] == True:
                        Template.objects.all().update(push__exporters=update[u'upserted'])
                else:
                    if pattern['available_for_all'] == True and currentExporter.available_for_all == False:
                        Template.objects(exporters__nin=[currentExporter]).update(push__exporters=currentExporter)

                    list_update_exporters.append(pattern['name'])

            except Exception, e:
                print('ERROR : Impossible to load the following exporter, class not found : ' + pattern['view'])
Ejemplo n.º 2
0
def start_export(request):
    if request.method == 'POST':
        #We retrieve all selected exporters
        listExporter = request.POST.getlist('my_exporters')
        instances = request.session['instancesExplore']
        listId = request.session['listIdToExport']
        #Creation of ZIP file
        in_memory = StringIO()
        zip = zipfile.ZipFile(in_memory, "a")
        is_many_inst = len(instances) > 1
        for instance in instances:
            xmlResults = []
            #Retrieve data
            sessionName = "resultsExplore" + json.loads(instance)['name']
            results = request.session[sessionName]
            if (len(results) > 0):
                for result in results:
                    if result['id'] in listId:
                        xmlResults.append(result)

            #For each data, we convert
            if len(xmlResults) > 0:
                #Init the folder name
                folder_name = None
                if is_many_inst:
                    folder_name = json.loads(instance)['name']
                #Check if the XSLT converter is asked. If yes, we start with this one because there is a specific treatment
                listXslt = request.POST.getlist('my_xslts')
                #Get the content of the file
                if len(listXslt) > 0:
                    exporter = XSLTExporter()
                    for xslt in listXslt:
                        xslt = ExporterXslt.objects.get(pk=xslt)
                        exporter._setXslt(xslt.content)
                        if folder_name == None:
                            exporter._transformAndZip(xslt.name, xmlResults, zip)
                        else:
                            exporter._transformAndZip(folder_name+"/"+xslt.name, xmlResults, zip)

                #We export for others exporters
                for exporter in listExporter:
                    exporter = get_exporter(exporter)
                    exporter._transformAndZip(folder_name, xmlResults, zip)

        zip.close()

        #ZIP file to be downloaded
        in_memory.seek(0)
        response = HttpResponse(in_memory.read())
        response["Content-Disposition"] = "attachment; filename=Query_Results.zip"
        response['Content-Type'] = 'application/x-zip'
        request.session['listIdToExport'] = ''

        return response
Ejemplo n.º 3
0
def main():

    args = arg_parser.parse_args()

    Parser = get_parser(args.lang)
    if not Parser:
        print("parser doesn't supported yet")
        return

    report = args.report
    report = get_report(report)

    top_size = args.top_size
    files_limit = args.count

    output = []
    paths = args.path
    if paths:
        for path in paths:
            if os.path.exists(path):
                parser = Parser(path, files_limit)
                output.extend(report(parser, top_size))

    git_urls = args.git_url
    if git_urls:
        for git_url in git_urls:
            git_repo = GitRepository(git_url)
            path = git_repo.clone_url()
            if path:
                parser = Parser(path, files_limit)
                output.extend(report(parser, top_size))

    if not paths and not git_urls:
        print('you should specify either path or url')
        return

    output_format = args.format
    output_file = args.output

    exporter = get_exporter(output_format)
    exporter(output, output_file)
Ejemplo n.º 4
0
def start_export(request):
    if request.method == 'POST':
        #We retrieve all selected exporters
        listExporter = request.POST.getlist('my_exporters')
        instances = request.session['instancesExplore']
        listId = request.session['listIdToExport']
        xmlResults = []
        #Creation of ZIP file
        in_memory = StringIO()
        zip = zipfile.ZipFile(in_memory, "a")
        is_many_inst = len(instances) > 1
        for instance in instances:
            #Retrieve data
            sessionName = "resultsExplore" + eval(instance)['name']
            results = request.session[sessionName]
            if (len(results) > 0):
                for result in results:
                    if result['id'] in listId:
                        xmlResults.append(result)

            #For each data, we convert
            if len(xmlResults) > 0:
                #Init the folder name
                folder_name = None
                if is_many_inst:
                    folder_name = eval(instance)['name']
                #Check if the XSLT converter is asked. If yes, we start with this one because there is a specific treatment
                listXslt = request.POST.getlist('my_xslts')
                #Get the content of the file
                if len(listXslt) > 0:
                    exporter = XSLTExporter()
                    for xslt in listXslt:
                        xslt = ExporterXslt.objects.get(pk=xslt)
                        exporter._setXslt(xslt.content)
                        if folder_name == None:
                            exporter._transformAndZip(xslt.name, xmlResults,
                                                      zip)
                        else:
                            exporter._transformAndZip(
                                folder_name + "/" + xslt.name, xmlResults, zip)

                #We export for others exporters
                for exporter in listExporter:
                    exporter = get_exporter(exporter)
                    exporter._transformAndZip(folder_name, xmlResults, zip)

        zip.close()

        #ZIP file to be downloaded
        in_memory.seek(0)
        response = HttpResponse(in_memory.read())
        response["Content-Disposition"] = "attachment; filename=Results.zip"
        response['Content-Type'] = 'application/x-zip'
        request.session['listIdToExport'] = ''

        return response
    else:
        # We retrieve the result_id for each file the user wants to export
        listId = request.GET.getlist('listId[]')
        request.session['listIdToExport'] = listId

        # Get all schemaId from the listId
        listSchemas = XMLdata.getByIDsAndDistinctBy(listId, "schema")
        # XMLdata.objects(pk__in=listId).distinct(field="schema")

        export_form = ExportForm(listSchemas)

        upload_xslt_Form = UploadXSLTForm(listSchemas)
        template = loader.get_template('explore/export_start.html')
        context = Context({
            'export_form': export_form,
            'upload_xslt_Form': upload_xslt_Form,
            'nb_elts_exp': len(export_form.EXPORT_OPTIONS),
            'nb_elts_xslt': len(upload_xslt_Form.EXPORT_OPTIONS)
        })

        return HttpResponse(json.dumps({'template': template.render(context)}),
                            content_type='application/javascript')
Ejemplo n.º 5
0
def start_export(request):
    if request.method == 'POST':
        #We retrieve all selected exporters
        listExporter = request.POST.getlist('my_exporters')
        instances = request.session['instancesExplore']
        listId = request.session['listIdToExport']
        xmlResults = []
        #Creation of ZIP file
        in_memory = StringIO()
        zip = zipfile.ZipFile(in_memory, "a")
        is_many_inst = len(instances) > 1
        for instance in instances:
            #Retrieve data
            sessionName = "resultsExplore" + eval(instance)['name']
            results = request.session[sessionName]
            if (len(results) > 0):
                for result in results:
                    if result['id'] in listId:
                        xmlResults.append(result)

            #For each data, we convert
            if len(xmlResults) > 0:
                #Init the folder name
                folder_name = None
                if is_many_inst:
                    folder_name = eval(instance)['name']
                #Check if the XSLT converter is asked. If yes, we start with this one because there is a specific treatment
                listXslt = request.POST.getlist('my_xslts')
                #Get the content of the file
                if len(listXslt) > 0:
                    exporter = XSLTExporter()
                    for xslt in listXslt:
                        xslt = ExporterXslt.objects.get(pk=xslt)
                        exporter._setXslt(xslt.content)
                        if folder_name == None:
                            exporter._transformAndZip(xslt.name, xmlResults, zip)
                        else:
                            exporter._transformAndZip(folder_name+"/"+xslt.name, xmlResults, zip)

                #We export for others exporters
                for exporter in listExporter:
                    exporter = get_exporter(exporter)
                    exporter._transformAndZip(folder_name, xmlResults, zip)

        zip.close()

        #ZIP file to be downloaded
        in_memory.seek(0)
        response = HttpResponse(in_memory.read())
        response["Content-Disposition"] = "attachment; filename=Results.zip"
        response['Content-Type'] = 'application/x-zip'
        request.session['listIdToExport'] = ''

        return response
    else:
        # We retrieve the result_id for each file the user wants to export
        listId = request.GET.getlist('listId[]')
        request.session['listIdToExport'] = listId

        # Get all schemaId from the listId
        listSchemas = XMLdata.getByIDsAndDistinctBy(listId, "schema")
            # XMLdata.objects(pk__in=listId).distinct(field="schema")

        export_form = ExportForm(listSchemas)

        upload_xslt_Form = UploadXSLTForm(listSchemas)
        template = loader.get_template('explore/export_start.html')
        context = Context({'export_form':export_form, 'upload_xslt_Form':upload_xslt_Form, 'nb_elts_exp': len(export_form.EXPORT_OPTIONS), 'nb_elts_xslt' : len(upload_xslt_Form.EXPORT_OPTIONS)})

        return HttpResponse(json.dumps({'template': template.render(context)}), content_type='application/javascript')