Example #1
0
def delete(request, manifest_name=None):
    if request.method == 'POST':
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect('/manifest/')
    else:
        c = RequestContext(request, {'manifest_name': manifest_name})
        c.update(csrf(request))
        return render_to_response('manifests/delete.html', c)
Example #2
0
def delete(request, manifest_name=None):
    if request.method == 'POST':
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect('/manifest/')
    else:
        c = RequestContext(request, {'manifest_name': manifest_name})
        c.update(csrf(request))
        return render_to_response('manifests/delete.html', c)
Example #3
0
def index(request, manifest_name=None):
    if request.method == 'GET':
        manifest_names = Manifest.list()
        available_sections = [
            'catalogs', 'included_manifests', 'managed_installs',
            'managed_uninstalls', 'managed_updates', 'optional_installs'
        ]
        section = request.GET.get('section', 'manifest_name')
        findtext = request.GET.get('findtext', '')
        #sort = request.GET.get('sort', 'name')
        if findtext:
            filtered_names = []
            if section == 'manifest_name':
                for name in manifest_names:
                    basename = os.path.basename(name)
                    if fnmatch.fnmatch(basename, findtext):
                        filtered_names.append(name)
            elif section == 'user_name':
                for name in manifest_names:
                    manifest = Manifest.read(name)
                    if manifest:
                        username = manifest.get(MANIFEST_USERNAME_KEY, '')
                        if fnmatch.fnmatch(username, findtext):
                            filtered_names.append(name)
            else:
                for name in manifest_names:
                    manifest = Manifest.read(name)
                    if manifest:
                        for item in manifest.get(section, []):
                            if fnmatch.fnmatch(item, findtext):
                                filtered_names.append(name)
                                break

            manifest_names = filtered_names

        manifest_list = getManifestInfo(manifest_names)
        username = None
        manifest = None

        if manifest_name:
            manifest = Manifest.read(manifest_name)
            username = manifest.get(MANIFEST_USERNAME_KEY)
            manifest_name = manifest_name.replace(':', '/')
        c = RequestContext(
            request, {
                'manifest_list': manifest_list,
                'section': section,
                'findtext': findtext,
                'available_sections': available_sections,
                'manifest_name': manifest_name,
                'manifest_user': username,
                'manifest': manifest,
                'user': request.user,
                'page': 'manifests'
            })

        return render_to_response('manifests/index.html', c)
Example #4
0
def index(request, manifest_name=None):
    if request.method == 'GET':
        manifest_names = Manifest.list()
        available_sections =   ['catalogs',
                                'included_manifests',
                                'managed_installs',
                                'managed_uninstalls',
                                'managed_updates',
                                'optional_installs']
        section = request.GET.get('section', 'manifest_name')
        findtext = request.GET.get('findtext', '')
        #sort = request.GET.get('sort', 'name')
        if findtext:
            filtered_names = []
            if section == 'manifest_name':
                for name in manifest_names:
                    basename = os.path.basename(name)
                    if fnmatch.fnmatch(basename, findtext):
                        filtered_names.append(name)
            elif section == 'user_name':
                for name in manifest_names:
                    manifest = Manifest.read(name)
                    if manifest:
                        username = manifest.get(MANIFEST_USERNAME_KEY, '')
                        if fnmatch.fnmatch(username, findtext):
                            filtered_names.append(name)
            else:
                for name in manifest_names:
                    manifest = Manifest.read(name)
                    if manifest:
                        for item in manifest.get(section, []):
                            if fnmatch.fnmatch(item, findtext):
                                filtered_names.append(name)
                                break
        
            manifest_names = filtered_names
        
        manifest_list = getManifestInfo(manifest_names)
        username = None
        manifest = None
        
        if manifest_name:
            manifest = Manifest.read(manifest_name)
            username = manifest.get(MANIFEST_USERNAME_KEY)
            manifest_name = manifest_name.replace(':', '/')
        c = RequestContext(request,     
            {'manifest_list': manifest_list,
             'section': section,
             'findtext': findtext,
             'available_sections': available_sections,
             'manifest_name': manifest_name,
             'manifest_user': username,
             'manifest': manifest,
             'user': request.user,
             'page': 'manifests'})
        
        return render_to_response('manifests/index.html', c)
Example #5
0
def delete(request, manifest_name=None):
    if not request.user.has_perm('reports.delete_machine'):
        return HttpResponse(json.dumps('error'))
    if request.method == 'POST':
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect('/%smanifest/' % SUB_PATH)
    else:
        c = RequestContext(request, {'manifest_name': manifest_name})
        c.update(csrf(request))
        return render_to_response('manifests/delete.html', c)
Example #6
0
def delete(request, manifest_name=None):
    if not request.user.has_perm("reports.delete_machine"):
        return HttpResponse(json.dumps("error"))
    if request.method == "POST":
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect("/%smanifest/" % SUB_PATH)
    else:
        c = RequestContext(request, {"manifest_name": manifest_name})
        c.update(csrf(request))
        return render_to_response("manifests/delete.html", c)
Example #7
0
def copymanifest(request):
    if request.method != 'POST':
        raise Http404
    submit = request.POST
    manifest_name = submit.get('manifest_name')
    manifest_copy = submit.get('manifest_copy')

    Manifest.copy(manifest_name, manifest_copy)

    return HttpResponse("No report submitted.\n")
Example #8
0
def copymanifest(request):
    if request.method != 'POST':
        raise Http404
    submit = request.POST
    manifest_name = submit.get('manifest_name')
    manifest_copy = submit.get('manifest_copy')

    Manifest.copy(manifest_name, manifest_copy)

    return HttpResponse("")
Example #9
0
def delete(request, manifest_name=None):
    if not request.user.has_perm('reports.delete_machine'):
        return HttpResponse(json.dumps('error'))
    if request.method == 'POST':
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect('/manifest/')
    else:
        c = RequestContext(request, {'manifest_name': manifest_name})
        c.update(csrf(request))
        return render_to_response('manifests/delete.html', c)
Example #10
0
def index(request, manifest_name=None):
    if request.method == 'GET':
        manifest_names = Manifest.list()
        available_sections =   ['catalogs',
                                'included_manifests',
                                'managed_installs',
                                'managed_uninstalls',
                                'managed_updates',
                                'optional_installs']
        section = request.GET.get('section', 'manifest_name')
        findtext = request.GET.get('findtext', '')
        sort = request.GET.get('sort', 'name')

        manifest_list = getManifestInfo(manifest_names)
        username = None
        manifest = None
        
        git_enabled = None
        if GIT:
            git_enabled = GIT

        git_branching_enabled = None
        if GIT_BRANCHING:
            git_branching_enabled = GIT_BRANCHING
            # option to show the actual branch. It takes a toll on loading speed though
            # git_branch = Manifest.getGitBranch()

        manifest_list_json = list()
        for item in manifest_list:
            manifest_list_json.append(item['name'])
        manifest_list_json = json.dumps(manifest_list_json)

        if manifest_name:
            manifest = Manifest.read(manifest_name)
            username = manifest.get(MANIFEST_USERNAME_KEY)
            manifest_name = manifest_name.replace(':', '/')
        c = RequestContext(request,     
            {'manifest_list': manifest_list,
             'manifest_list_json': manifest_list_json,
             'section': section,
             'findtext': findtext,
             'available_sections': available_sections,
             'manifest_name': manifest_name,
             'manifest_user': username,
             'manifest': manifest,
             'git_enabled': git_enabled,
             'git_branching_enabled': git_branching_enabled,
             'user': request.user,
             'page': 'manifests'})
        
        return render_to_response('manifests/index.html', c)
Example #11
0
def detail(request, manifest_path):
    if request.method == 'GET':
        print "Got read request for %s" % manifest_path
        manifest = Manifest.read(manifest_path)
        #autocomplete_data = Manifest.getAutoCompleteData(manifest_path)
        if manifest is None:
            raise Http404("%s does not exist" % manifest_path)
        c = {'plist_text': manifest,
             'pathname': manifest_path}
        return render(request, 'manifests/detail.html', context=c)
    if request.method == 'POST':
        # could be PUT, POST, or DELETE
        if request.META.has_key('HTTP_X_METHODOVERRIDE'):
            http_method = request.META['HTTP_X_METHODOVERRIDE']
            if http_method.lower() == 'delete':
                print "Got delete request for %s" % manifest_path
                if not request.user.has_perm('manifest.delete_manifestfile'):
                    raise PermissionDenied
                Manifest.delete(manifest_path, request.user)
                return HttpResponse(
                    json.dumps('success'), content_type='application/json')
            elif http_method.lower() == 'put':
                # regular POST (update/change)
                print "Got write request for %s" % manifest_path
                if not request.user.has_perm('manifest.change_manifestfile'):
                    raise PermissionDenied
                if request.is_ajax():
                    json_data = json.loads(request.body)
                    if json_data and 'plist_data' in json_data:
                        plist_data = json_data['plist_data'].encode('utf-8')
                        Manifest.write(
                            json_data['plist_data'], manifest_path,
                            request.user)
                        return HttpResponse(
                            json.dumps('success'),
                            content_type='application/json')
            else:
                print "Got unknown HTTP_X_METHODOVERRIDE for %s: %s" % (
                    manifest_path, http_method)
        else:
            # true POST request; create new resource
            print "Got create request for %s" % manifest_path
            try:
                json_data = json.loads(request.body)
            except ValueError:
                json_data = None
            if json_data and 'plist_data' in json_data:
                plist_data = json_data['plist_data'].encode('utf-8')
                Manifest.write(
                    json_data['plist_data'], manifest_path,
                    request.user)
            else:
                plist_data = Manifest.new(manifest_path, request.user)
            c = {'plist_text': plist_data,
                 'pathname': manifest_path,}
            return render(request, 'manifests/detail.html', context=c)
Example #12
0
def set_manifest(filename: str):
    with db_session_handler() as db_session:
        file_date = datetime.strptime(filename.split('.')[1], '%Y%m%d')
        logger.info(f'appending to manifest')
        new_record = {
            'TABLE': 'member_eligibility',
            'LOAD_DATE': file_date,
        }
        db_session.add(Manifest(**new_record))
Example #13
0
def getManifestInfo(manifest_names):
    manifest_list = []
    for name in manifest_names:
        m_dict = {}
        m_dict['name'] = name
        manifest = Manifest.read(name)
        m_dict['user'] = manifest.get(MANIFEST_USERNAME_KEY, '')
        manifest_list.append(m_dict) 
    return manifest_list
Example #14
0
def getManifestInfo(manifest_names):
    manifest_list = []
    for name in manifest_names:
        m_dict = {}
        m_dict['name'] = name
        manifest = Manifest.read(name)
        #m_dict['user'] = manifest.get(MANIFEST_USERNAME_KEY, '')
        manifest_list.append(m_dict)
    return manifest_list
Example #15
0
def detail(request, manifest_path):
    if request.method == 'GET':
        print "Got read request for %s" % manifest_path
        manifest = Manifest.read(manifest_path)
        #autocomplete_data = Manifest.getAutoCompleteData(manifest_path)
        if manifest is None:
            raise Http404("%s does not exist" % manifest_path)
        c = {'plist_text': manifest, 'pathname': manifest_path}
        return render(request, 'manifests/detail.html', context=c)
    if request.method == 'POST':
        # could be PUT, POST, or DELETE
        if request.META.has_key('HTTP_X_METHODOVERRIDE'):
            http_method = request.META['HTTP_X_METHODOVERRIDE']
            if http_method.lower() == 'delete':
                print "Got delete request for %s" % manifest_path
                if not request.user.has_perm('manifest.delete_manifestfile'):
                    raise PermissionDenied
                Manifest.delete(manifest_path, request.user)
                return HttpResponse(json.dumps('success'),
                                    content_type='application/json')
            elif http_method.lower() == 'put':
                # regular POST (update/change)
                print "Got write request for %s" % manifest_path
                if not request.user.has_perm('manifest.change_manifestfile'):
                    raise PermissionDenied
                if request.is_ajax():
                    json_data = json.loads(request.body)
                    if json_data and 'plist_data' in json_data:
                        plist_data = json_data['plist_data'].encode('utf-8')
                        Manifest.write(json_data['plist_data'], manifest_path,
                                       request.user)
                        return HttpResponse(json.dumps('success'),
                                            content_type='application/json')
            else:
                print "Got unknown HTTP_X_METHODOVERRIDE for %s: %s" % (
                    manifest_path, http_method)
        else:
            # true POST request; create new resource
            print "Got create request for %s" % manifest_path
            try:
                json_data = json.loads(request.body)
            except ValueError:
                json_data = None
            if json_data and 'plist_data' in json_data:
                plist_data = json_data['plist_data'].encode('utf-8')
                Manifest.write(json_data['plist_data'], manifest_path,
                               request.user)
            else:
                plist_data = Manifest.new(manifest_path, request.user)
            c = {
                'plist_text': plist_data,
                'pathname': manifest_path,
            }
            return render(request, 'manifests/detail.html', context=c)
Example #16
0
def json_manifest_names(request):
    valid_manifest_names = Manifest.list()
    valid_manifest_names.sort()
    term = request.GET.get('term', '').lower()
    if term:
        suggestions = [ item for item in valid_manifest_names
                        if term in item.lower() ]
    else:
        suggestions = valid_manifest_names
    return HttpResponse(json.dumps(suggestions),
                        mimetype='application/json')
Example #17
0
def index(request):
    if request.is_ajax():
        print "Got json request for manifests"
        manifest_list = Manifest.list()
        # send it back in JSON format
        return HttpResponse(json.dumps(manifest_list),
                            content_type='application/json')
    else:
        print "Got index request for manifests"
        c = {'page': 'manifests'}
        return render(request, 'manifests/manifests.html', context=c)
Example #18
0
def index(request):
    if request.is_ajax():
        print "Got json request for manifests"
        manifest_list = Manifest.list()
        # send it back in JSON format
        return HttpResponse(json.dumps(manifest_list),
                            content_type='application/json')
    else:
        print "Got index request for manifests"
        c = {'page': 'manifests'}
        return render(request, 'manifests/manifests.html', context=c)
Example #19
0
def detail(request, manifest_name):
    if request.method == 'POST':
        if not request.user.has_perm('reports.change_machine'):
            return HttpResponse(json.dumps('error'))
        if request.is_ajax():
            json_data = json.loads(request.raw_post_data)
            if json_data:
                manifest_detail = Manifest.read(manifest_name)
                for key in json_data.keys():
                    manifest_detail[key] = json_data[key]
                Manifest.write(manifest_name, manifest_detail,
                               request.user)
            return HttpResponse(json.dumps('success'))
    if request.method == 'GET':
        manifest = Manifest.read(manifest_name)
        valid_install_items = Manifest.getValidInstallItems(manifest_name)
        valid_catalogs = Catalog.list()
        valid_manifest_names = Manifest.list()
        manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '')
        
        c = RequestContext(request, 
            {'manifest_name': manifest_name.replace(':', '/'),
            'manifest_user': manifest_user,
            'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE,
            'manifest': manifest,
            'valid_install_items': valid_install_items,
            'valid_catalogs': valid_catalogs,
            'valid_manifest_names': valid_manifest_names,
            'user': request.user,
            'page': 'manifests'})
        c.update(csrf(request))
        return render_to_response('manifests/detail.html', c)
Example #20
0
def index(request, manifest_name=None):
    if request.method == 'GET':
        manifest_names = Manifest.list()
        available_sections =   ['catalogs',
                                'included_manifests',
                                'managed_installs',
                                'managed_uninstalls',
                                'managed_updates',
                                'optional_installs']
        section = request.GET.get('section', 'manifest_name')
        findtext = request.GET.get('findtext', '')
        sort = request.GET.get('sort', 'name')

        manifest_list = getManifestInfo(manifest_names)
        username = None
        manifest = None
        
        manifest_list_josn = list()
        for item in manifest_list:
            manifest_list_josn.append(item['name'])
        manifest_list_josn = json.dumps(manifest_list_josn)

        if manifest_name:
            manifest = Manifest.read(manifest_name)
            username = manifest.get(MANIFEST_USERNAME_KEY)
            manifest_name = manifest_name.replace(':', '/')
        c = RequestContext(request,     
            {'manifest_list': manifest_list,
             'manifest_list_josn': manifest_list_josn,
             'section': section,
             'findtext': findtext,
             'available_sections': available_sections,
             'manifest_name': manifest_name,
             'manifest_user': username,
             'manifest': manifest,
             'user': request.user,
             'page': 'manifests'})
        
        return render_to_response('manifests/index.html', c)
Example #21
0
def new(request):
    if request.method == "POST":  # If the form has been submitted...
        form = NewManifestForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            # Redirect after POST
            manifest = Manifest.new()
            manifest_name = form.cleaned_data["manifest_name"]
            user_name = form.cleaned_data.get("user_name", "")
            manifest[MANIFEST_USERNAME_KEY] = user_name
            Manifest.write(manifest_name, manifest, request.user)
            return HttpResponseRedirect("/%smanifest/view/%s" % (SUB_PATH, manifest_name))
        else:
            # form not valid, try again
            c = RequestContext(request, {"form": form})
    else:
        form = NewManifestForm()  # An unbound form
        c = RequestContext(request, {"form": form})
        c.update(csrf(request))

    return render_to_response("manifests/new.html", c)
Example #22
0
def new(request):
    if request.method == 'POST':  # If the form has been submitted...
        form = NewManifestForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            # Redirect after POST
            manifest = Manifest.new()
            manifest_name = form.cleaned_data['manifest_name']
            user_name = form.cleaned_data.get('user_name', '')
            manifest[MANIFEST_USERNAME_KEY] = user_name
            Manifest.write(manifest_name, manifest, request.user)
            return HttpResponseRedirect('/manifest/view/%s' % manifest_name)
        else:
            # form not valid, try again
            c = RequestContext(request, {'form': form})
    else:
        form = NewManifestForm()  # An unbound form
        c = RequestContext(request, {'form': form})
        c.update(csrf(request))

    return render_to_response('manifests/new.html', c)
Example #23
0
def index(request, manifest_name=None):
    if request.method == 'GET':
        manifest_names = Manifest.list()
        available_sections = [
            'catalogs', 'included_manifests', 'managed_installs',
            'managed_uninstalls', 'managed_updates', 'optional_installs'
        ]
        section = request.GET.get('section', 'manifest_name')
        findtext = request.GET.get('findtext', '')
        sort = request.GET.get('sort', 'name')

        manifest_list = getManifestInfo(manifest_names)
        username = None
        manifest = None

        manifest_list_josn = list()
        for item in manifest_list:
            manifest_list_josn.append(item['name'])
        manifest_list_josn = json.dumps(manifest_list_josn)

        if manifest_name:
            manifest = Manifest.read(manifest_name)
            username = manifest.get(MANIFEST_USERNAME_KEY)
            manifest_name = manifest_name.replace(':', '/')
        c = RequestContext(
            request, {
                'manifest_list': manifest_list,
                'manifest_list_josn': manifest_list_josn,
                'section': section,
                'findtext': findtext,
                'available_sections': available_sections,
                'manifest_name': manifest_name,
                'manifest_user': username,
                'manifest': manifest,
                'user': request.user,
                'page': 'manifests'
            })

        return render_to_response('manifests/index.html', c)
Example #24
0
def detail(request, manifest_name):
    if request.method == 'POST':
        if not request.user.has_perm('manifests.change_manifests'):
            return HttpResponse(json.dumps('error'))
        if request.is_ajax():
            json_data = json.loads(request.body)
            if json_data:
                manifest_detail = Manifest.read(manifest_name)
                for key in json_data.keys():
                    manifest_detail[key] = json_data[key]
                Manifest.write(manifest_name, manifest_detail, request.user)
            return HttpResponse(json.dumps('success'))
    if request.method == 'GET':
        if not request.user.has_perm('manifests.can_view_manifests'):
            return HttpResponse(json.dumps('error'))
        manifest = Manifest.read(manifest_name)
        #valid_install_items = Manifest.getValidInstallItems(manifest_name)
        install_items = Manifest.getInstallItemNames(manifest_name)
        valid_install_items = (install_items['suggested'] +
                               install_items['updates'] +
                               install_items['with_version'])
        suggested_install_items = install_items['suggested']
        valid_catalogs = Catalog.list()
        valid_manifest_names = Manifest.list()
        autocomplete_data = json.dumps({
            'items': install_items['suggested'],
            'catalogs': valid_catalogs,
            'manifests': valid_manifest_names
        })
        manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '')

        c = RequestContext(
            request, {
                'manifest_name': manifest_name.replace(':', '/'),
                'manifest_user': manifest_user,
                'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE,
                'manifest': manifest,
                'valid_install_items': valid_install_items,
                'install_items': install_items,
                'valid_catalogs': valid_catalogs,
                'valid_manifest_names': valid_manifest_names,
                'autocomplete_data': autocomplete_data,
                'user': request.user,
                'page': 'manifests'
            })
        c.update(csrf(request))
        return render_to_response('manifests/detail.html', c)
Example #25
0
def detail(request, manifest_name):
    if request.method == 'POST':
        if not request.user.has_perm('manifests.change_manifests'):
            return HttpResponse(json.dumps('error'))
        if request.is_ajax():
            json_data = json.loads(request.body)
            if json_data:
                manifest_detail = Manifest.read(manifest_name)
                for key in json_data.keys():
                    manifest_detail[key] = json_data[key]
                Manifest.write(manifest_name, manifest_detail,
                               request.user)
            return HttpResponse(json.dumps('success'))
    if request.method == 'GET':
        if not request.user.has_perm('manifests.can_view_manifests'):
            return HttpResponse(json.dumps('error'))
        manifest = Manifest.read(manifest_name)
        #valid_install_items = Manifest.getValidInstallItems(manifest_name)
        install_items = Manifest.getInstallItemNames(manifest_name)
        valid_install_items = (install_items['suggested'] + 
                               install_items['updates'] +
                                install_items['with_version'])
        suggested_install_items = install_items['suggested']
        valid_catalogs = Catalog.list()
        valid_manifest_names = Manifest.list()
        autocomplete_data = json.dumps({
            'items': install_items['suggested'],
            'catalogs': valid_catalogs,
            'manifests': valid_manifest_names
        })
        manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '')
        
        c = RequestContext(request, 
            {'manifest_name': manifest_name.replace(':', '/'),
            'manifest_user': manifest_user,
            'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE,
            'manifest': manifest,
            'valid_install_items': valid_install_items,
            'install_items': install_items,
            'valid_catalogs': valid_catalogs,
            'valid_manifest_names': valid_manifest_names,
            'autocomplete_data': autocomplete_data,
            'user': request.user,
            'page': 'manifests'})
        c.update(csrf(request))
        return render_to_response('manifests/detail.html', c)
Example #26
0
def detail(request, manifest_name):
    if request.method == "POST":
        if not request.user.has_perm("reports.change_machine"):
            return HttpResponse(json.dumps("error"))
        if request.is_ajax():
            json_data = json.loads(request.body)
            if json_data:
                manifest_detail = Manifest.read(manifest_name)
                for key in json_data.keys():
                    manifest_detail[key] = json_data[key]
                Manifest.write(manifest_name, manifest_detail, request.user)
            return HttpResponse(json.dumps("success"))
    if request.method == "GET":
        manifest = Manifest.read(manifest_name)
        # valid_install_items = Manifest.getValidInstallItems(manifest_name)
        install_items = Manifest.getInstallItemNames(manifest_name)
        valid_install_items = install_items["suggested"] + install_items["updates"] + install_items["with_version"]
        suggested_install_items = install_items["suggested"]
        valid_catalogs = Catalog.list()
        valid_manifest_names = Manifest.list()
        autocomplete_data = json.dumps(
            {"items": install_items["suggested"], "catalogs": valid_catalogs, "manifests": valid_manifest_names}
        )
        manifest_user = manifest.get(MANIFEST_USERNAME_KEY, "")

        c = RequestContext(
            request,
            {
                "manifest_name": manifest_name.replace(":", "/"),
                "manifest_user": manifest_user,
                "manifest_user_is_editable": MANIFEST_USERNAME_IS_EDITABLE,
                "manifest": manifest,
                "valid_install_items": valid_install_items,
                "install_items": install_items,
                "valid_catalogs": valid_catalogs,
                "valid_manifest_names": valid_manifest_names,
                "autocomplete_data": autocomplete_data,
                "user": request.user,
                "page": "manifests",
            },
        )
        c.update(csrf(request))
        return render_to_response("manifests/detail.html", c)
Example #27
0
def collect():

    run('deps component hook before_update')

    # The first argument should be the manifest file
    manifest_starting_path = sys.argv[1]

    manifests = Manifest.collect_manifests(
        manifest_starting_path
    )  # potentially recursive collection exposed as list

    # Manifest Processing
    output = {'manifests': {}}
    lockfiles = []
    direct_deps = []
    for manifest in manifests:
        print('Collecting contents of {filename}:'.format(
            filename=manifest.filename))
        print(manifest.content)

        output['manifests'][manifest.filename] = {
            'current': {
                'dependencies': manifest.dio_dependencies()
            }
        }

        # Add any lockfiles for this manifest for later processing
        if manifest.lockfile:
            lockfiles.append(manifest.lockfile)

        # Record direct dependencies
        direct_deps.extend([dep.key for dep in manifest.dependencies()])

    run('deps component collect {}'.format(write_json_to_temp_file(output)))

    # Lockfile Processing
    lockfile_output = {'lockfiles': {}}
    for lockfile in lockfiles:
        print('Collecting contents of {filename}:'.format(
            filename=lockfile.filename))
        print(lockfile.content)

        current_fingerprint = lockfile.fingerprint()
        current_dependencies = lockfile.dio_dependencies(
            direct_dependencies=direct_deps)
        lockfile_output['lockfiles'][lockfile.filename] = {
            'current': {
                'fingerprint': current_fingerprint,
                'dependencies': current_dependencies,
            }
        }

        lockfile.native_update()  # use the native tools to update the lockfile

        if current_fingerprint != lockfile.fingerprint():
            lockfile_output['lockfiles'][lockfile.filename]['updated'] = {
                'fingerprint':
                lockfile.fingerprint(),
                'dependencies':
                lockfile.dio_dependencies(direct_dependencies=direct_deps),
            }

        run('deps component collect {}'.format(
            write_json_to_temp_file(lockfile_output)))
Example #28
0
def gitpull(request, manifest_name=None):
    if request.method == 'GET':
        Manifest.gitPull()
    return HttpResponseRedirect('/manifest/')
Example #29
0
def detail(request, manifest_name):
    if request.method == 'POST':
        if not request.user.has_perm('manifests.change_manifests'):
            return HttpResponse(json.dumps('error'))
        if request.is_ajax():
            json_data = json.loads(request.body)
            if json_data:
                manifest_detail = Manifest.read(manifest_name)
                for key in json_data.keys():
                    manifest_detail[key] = json_data[key]
                Manifest.write(manifest_name, manifest_detail,
                               request.user)
            logger.info("ManifestWrite instigated.")
            return HttpResponse(json.dumps('success'))
    
    if request.method == 'GET':
        if not request.user.has_perm('manifests.can_view_manifests'):
            return HttpResponse(json.dumps('error'))
        manifest = Manifest.read(manifest_name)
        #valid_install_items = Manifest.getValidInstallItems(manifest_name)
        install_items = Manifest.getInstallItemNames(manifest_name)
        valid_install_items =  (install_items['suggested'] + 
                                install_items['updates'] +
                                install_items['with_version'])
        suggested_install_items = install_items['suggested']
        valid_catalogs = Catalog.list()
        valid_manifest_names = Manifest.list()
        autocomplete_data = json.dumps({
            'items': install_items['suggested'],
            'catalogs': valid_catalogs,
            'manifests': valid_manifest_names
        })
        manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '')
        manifest_restriction = manifest.get(MANIFEST_RESTRICTION_KEY, '')
        user_groups = Group.objects.values_list('name', flat=True)
        
        if manifest_restriction:
            manifest_restriction_is_editable = None
            if request.user.is_superuser:
                manifest_restriction_is_editable = 'yes'
            elif request.user.is_staff and 'staff' in manifest_restriction:
                manifest_restriction_is_editable = 'yes'
            else:
                for item in manifest_restriction:
                    if Manifest.can_edit_restricted_manifest(request.user, item):
                        manifest_restriction_is_editable = 'yes'
        else:
            manifest_restriction_is_editable = 'unrestricted'
 
        git_branching_enabled = None
        if GIT_BRANCHING:
            git_branching_enabled = GIT_BRANCHING

        c = RequestContext(request, 
            {'manifest_name': manifest_name.replace(':', '/'),
            'manifest_user': manifest_user,
            'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE,
            'manifest': manifest,
            'valid_install_items': valid_install_items,
            'install_items': install_items,
            'valid_catalogs': valid_catalogs,
            'valid_manifest_names': valid_manifest_names,
            'autocomplete_data': autocomplete_data,
            'git_branching_enabled': git_branching_enabled,
            'restriction_key': MANIFEST_RESTRICTION_KEY,
            'manifest_restriction': manifest_restriction,
            'manifest_restriction_is_editable': manifest_restriction_is_editable,
            'user_groups': user_groups,
            'user': request.user,
            'page': 'manifests'})
        c.update(csrf(request))
        return render_to_response('manifests/detail.html', c)
Example #30
0
 def clean_manifest_name(self):
     manifest_names = Manifest.list()
     if self.cleaned_data['manifest_name'] in manifest_names:
         raise forms.ValidationError('Manifest name already exists!')
     return self.cleaned_data['manifest_name']
Example #31
0
def act():
    with open('/dependencies/input_data.json', 'r') as f:
        data = json.load(f)

    # create a new branch for this update
    run('deps component branch')

    for lockfile_path, lockfile_data in data.get('lockfiles', {}).items():
        # If "lockfiles" are present then it means that there are updates to
        # those lockfiles that you can make. The most basic way to handle this
        # is to use whatever "update" command is provided by the package
        # manager, and then commit and push the entire update. You can try to be
        # more granular than that if you want, but performing the entire "update"
        # at once is an easier place to start.

        # Granular, package by package upgrades
        # for dep_name, dep_data in lockfile_data['updated']['dependencies'].items():
        #     lockfile = LockFile(lockfile_path)
        #     dep_version = dep_data['installed']['name']
        #
        #     # Prefix the version with "==" automatically if it (shouldn't) have it
        #     if re.match('^\d', dep_version):
        #         dep_version = '==' + dep_version
        #     run(['pipenv', 'install', '{dep_name}{dep_version}'.format(dep_name=dep_name, dep_version=dep_version)])
        #     dep_name_ver = '{dep_name}{dep_version}'.format(dep_name=dep_name, dep_version=dep_version)
        #     lockfile.native_update(dep_name_ver)

        # # All at once
        lockfile = LockFile(lockfile_path)
        lockfile.native_update()

        # 1) Do the lockfile update
        #    Since lockfile can change frequently, you'll want to "collect" the
        #    exact update that you end up making, in case it changed slightly from
        #    the original update that it was asked to make.

        lockfile_data['updated']['dependencies'] = lockfile.dio_dependencies()
        lockfile_data['updated']['fingerprint'] = lockfile.fingerprint()

        # 2) Add and commit the changes
        run('deps component commit -m "Update {}" {}'.format(
            lockfile_path, lockfile_path))

    for manifest_path, manifest_data in data.get('manifests', {}).items():
        for dependency_name, updated_dependency_data in manifest_data[
                'updated']['dependencies'].items():
            manifest = Manifest(manifest_path)
            print('~' * 80 + '\n')
            print(manifest.content)
            print('=' * 80 + '\n')
            installed = manifest_data['current']['dependencies'][
                dependency_name]['constraint']
            version_to_update_to = updated_dependency_data['constraint']

            # automatically prefix it with == if it looks like it is an exact version
            # and wasn't prefixed already
            if re.match(r'^\d', version_to_update_to):
                version_to_update_to = '==' + version_to_update_to

            dependency = [
                x for x in manifest.dependencies() if x.key == dependency_name
            ][0]
            updated_content = manifest.updater(
                content=manifest.content,
                dependency=dependency,
                version=version_to_update_to,
                spec='',  # we'll have spec included in "version"
            )
            print(updated_content)
            print('-' * 80 + '\n')

            with open(manifest_path, 'w+') as f:
                f.write(updated_content)

            run('deps component commit -m "Update {} from {} to {}" {}'.format(
                dependency_name, installed,
                updated_dependency_data['constraint'], manifest_path))

    run('deps component pullrequest {}'.format(write_json_to_temp_file(data)))
Example #32
0
def old_json_manifest_names(request):
    valid_manifest_names = Manifest.list()
    valid_manifest_names.sort()
    return HttpResponse(json.dumps(valid_manifest_names),
                        mimetype='application/json')
Example #33
0
def json_suggested_items(request, manifest_name):
    valid_install_items = Manifest.getSuggestedInstallItems(manifest_name)
    return get_suggestions(request, valid_install_items)
Example #34
0
def index(request, manifest_name=None):
    if request.method == "GET":
        manifest_names = Manifest.list()
        available_sections = [
            "catalogs",
            "included_manifests",
            "managed_installs",
            "managed_uninstalls",
            "managed_updates",
            "optional_installs",
        ]
        section = request.GET.get("section", "manifest_name")
        findtext = request.GET.get("findtext", "")
        # sort = request.GET.get('sort', 'name')
        if findtext:
            filtered_names = []
            if section == "manifest_name":
                for name in manifest_names:
                    basename = os.path.basename(name)
                    if fnmatch.fnmatch(basename, findtext):
                        filtered_names.append(name)
            elif section == "user_name":
                for name in manifest_names:
                    manifest = Manifest.read(name)
                    if manifest:
                        username = manifest.get(MANIFEST_USERNAME_KEY, "")
                        if fnmatch.fnmatch(username, findtext):
                            filtered_names.append(name)
            else:
                for name in manifest_names:
                    manifest = Manifest.read(name)
                    if manifest:
                        for item in manifest.get(section, []):
                            if fnmatch.fnmatch(item, findtext):
                                filtered_names.append(name)
                                break

            manifest_names = filtered_names

        manifest_list = getManifestInfo(manifest_names)
        username = None
        manifest = None

        if manifest_name:
            manifest = Manifest.read(manifest_name)
            username = manifest.get(MANIFEST_USERNAME_KEY)
            manifest_name = manifest_name.replace(":", "/")
        c = RequestContext(
            request,
            {
                "manifest_list": manifest_list,
                "section": section,
                "findtext": findtext,
                "available_sections": available_sections,
                "manifest_name": manifest_name,
                "manifest_user": username,
                "manifest": manifest,
                "user": request.user,
                "page": "manifests",
            },
        )

        return render_to_response("manifests/index.html", c)
Example #35
0
 def clean_manifest_name(self):
     manifest_names = Manifest.list()
     if self.cleaned_data['manifest_name'] in manifest_names:
         raise forms.ValidationError('Manifest name already exists!')
     return self.cleaned_data['manifest_name']