Ejemplo n.º 1
0
def savePackage():
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400

    params = request.get_json()
    img = params.get('img', None)
    Length = params.get('Length', None)
    Width = params.get('Width', None)
    Height = params.get('Height', None)
    Weight = params.get('Weight', None)
    Tracking = params.get('Tracking', None)

    if not img:
        return jsonify({"msg": "Missing img parameter"}), 400
    if not Length:
        return jsonify({"msg": "Missing Length parameter"}), 400
    if not Width:
        return jsonify({"msg": "Missing Width parameter"}), 400
    if not Height:
        return jsonify({"msg": "Missing Height parameter"}), 400
    if not Weight:
        return jsonify({"msg": "Missing Weight parameter"}), 400
    if not Tracking:
        return jsonify({"msg": "Missing Tracking parameter"}), 400

    result = cloudinary.uploader.upload("data:image/png;base64,"+img)
    ocr = cloudinary.api.update(result['public_id'],  ocr = "adv_ocr")
    # print(ocr['info']['ocr']['adv_ocr']['data'][0]['textAnnotations'][0]['description'])
    pack = Packages(tracking=Tracking, url=result['url'], length=Length, height=Width, width=Height, weight=Weight, ocr=ocr['info']['ocr']['adv_ocr']['data'][0]['textAnnotations'][0]['description'])
    db.session.add(pack)
    db.session.commit()

    return jsonify({"msg": "Package inserted"}), 200
Ejemplo n.º 2
0
 def __init__(self, name, archs, packages):
     self.name = name
     self.packages = packages
     self.archs = archs
     self.repos = {
             'stable': ['{0}-rutgers'.format(x) for x in repos],
             'testing': ['{0}-rutgers-testing'.format(x) for x in repos],
             'unstable': ['{0}-rutgers-unstable'.format(x) for x in repos],
             }
     fakepack = Packages()
     fakepack.Version = ""
     fakepack.Rel = ""
     self.newest = {}
     for genrepo in self.repos:
         for repo in self.repos[genrepo]:
             self.newest[repo] = fakepack
     for package in self.packages:
         self.newest[package[1]] = package[0]
Ejemplo n.º 3
0
 def __init__(self, name, archs, packages):
     self.name = name
     self.packages = packages
     self.archs = archs
     self.repos = {
         'stable': ['{0}-rutgers'.format(x) for x in repos],
         'testing': ['{0}-rutgers-testing'.format(x) for x in repos],
         'unstable': ['{0}-rutgers-unstable'.format(x) for x in repos],
     }
     fakepack = Packages()
     fakepack.Version = ""
     fakepack.Rel = ""
     self.newest = {}
     for genrepo in self.repos:
         for repo in self.repos[genrepo]:
             self.newest[repo] = fakepack
     for package in self.packages:
         self.newest[package[1]] = package[0]
Ejemplo n.º 4
0
def index(request):
    if request.method == 'GET':
        findtext = request.GET.get('findtext')
        all_catalog_items = Packages.detail(findtext)
    else:
        all_catalog_items = Packages.detail()
    catalog_list = Catalog.list()
    catalog_name = 'none'
    if PROD_CATALOG in catalog_list:
        catalog_name = PROD_CATALOG
    elif 'testing' in catalog_list:
        catalog_name = 'testing'
    return render_to_response('pkgs/index.html',
                              {'user': request.user,
                               'all_catalog_items': all_catalog_items,
                               'catalog_list': catalog_list,
                               'catalog_name': catalog_name,
                               'findtext': findtext,
                               'page': 'pkgs'})
Ejemplo n.º 5
0
def deleted(request):
    if request.method == 'POST': # If the form has been submitted...
        final_items_to_delete = request.POST.getlist('final_items_to_delete[]')
        tuple(final_items_to_delete)
        deleted_packages = []
        for n,pkg in enumerate(final_items_to_delete):
            pkg = pkg.split('___')
            final_items_to_delete[n] = pkg
        for pkg_name, pkg_version, pkg_location in final_items_to_delete:
            Packages.delete_pkgs(pkg_name, pkg_version)
            deleted_packages.append(pkg_location)
        Packages.makecatalogs()
        context = {'user': request.user,
                   'final_items_to_delete': final_items_to_delete,
                   'deleted_packages': deleted_packages,
                   'deleted': 'Deleted',
                   'page': 'pkgs'}
        return render_to_response('pkgs/deleted.html', context)
    else:
        return HttpResponse("No form submitted.\n")
Ejemplo n.º 6
0
def package_info():
    if ('user' in session and session['user'] == params['admin_user']):
        if request.method == 'POST':
            title = request.form.get('title')
            fee = request.form.get('fee')
            message = request.form.get('message')
            date = datetime.now()
            userDetail = User.query.filter_by(firstName=session['user'].capitalize()).first().email
            entry = Packages(title=title,fee=fee,createdBy=userDetail,modifiedBy=userDetail,createdDate=date,modifiedDate=date,message=message)
            db.session.add(entry)
            db.session.commit()
            flash('Data Saved Successfully')
    return render_template('package.html',params=params)
Ejemplo n.º 7
0
def deleted(request):
#     can_view_pkgs = request.user.has_perm('pkgs.can_view_pkgs')
#     can_view_manifests = request.user.has_perm('manifests.can_view_manifests')
#     can_view_catalogs = request.user.has_perm('catalogs.can_view_catalogs')
#     change_pkgs = request.user.has_perm('pkgs.change_pkgs')
#     delete_pkgs = request.user.has_perm('pkgs.delete_pkgs')
    if request.method == 'POST': # If the form has been submitted...
        final_items_to_delete = request.POST.getlist('final_items_to_delete[]')
        confirm_delete = request.POST.getlist('confirm_delete')
        confirm_delete_pkgs = request.POST.getlist('confirm_delete_pkgs')
        tuple(final_items_to_delete)
        deleted_packages = []
        if confirm_delete:
            for n,pkg in enumerate(final_items_to_delete):
                pkg = pkg.split('___')
                final_items_to_delete[n] = pkg
            for pkg_name, pkg_version, pkg_location in final_items_to_delete:
                try:
                    Packages.delete_pkgs(pkg_name, pkg_version, request.user)
                    deleted = 'deleted'
                except OSError as e:
                    logger.info("The error was %s" % e)
                    deleted = None
            Packages.makecatalogs(request.user)
        else:
            for pkg_location in final_items_to_delete:
                try:
                    Packages.delete_orphaned_pkg(pkg_location, request.user)
                    deleted = 'deleted'
                except OSError as e:
                    logger.info("The error was %s" % e)
                    deleted = None
            if not GIT_IGNORE_PKGS:
                Packages.makecatalogs(request.user)
        deleted_packages.append(pkg_location)
        c = RequestContext(request, {'user': request.user,
                   'final_items_to_delete': final_items_to_delete,
                   'deleted_packages': deleted_packages,
                   'deleted': deleted,
#                    'can_view_pkgs': can_view_pkgs,
#                    'can_view_manifests': can_view_manifests,
#                    'can_view_catalogs': can_view_catalogs,
#                    'change_pkgs': change_pkgs,
#                    'delete_pkgs': delete_pkgs,
                   'page': 'pkgs'})
        return render_to_response('pkgs/deleted.html', c)
    else:
        return HttpResponse("No form submitted.\n")
Ejemplo n.º 8
0
def orphaned(request):
    can_view_pkgs = request.user.has_perm('pkgs.can_view_pkgs')
    can_view_manifests = request.user.has_perm('manifests.can_view_manifests')
    can_view_catalogs = request.user.has_perm('catalogs.can_view_catalogs')
    change_pkgs = request.user.has_perm('pkgs.change_pkgs')
    delete_pkgs = request.user.has_perm('pkgs.delete_pkgs')
    orphaned_pkgs = Packages.orphaned()
    c = RequestContext(request, {'user': request.user,
                                 'orphaned_pkgs': orphaned_pkgs,
                                 'can_view_pkgs': can_view_pkgs,
                                 'can_view_manifests': can_view_manifests,
                                 'can_view_catalogs': can_view_catalogs,
                                 'change_pkgs': change_pkgs,
                                 'delete_pkgs': delete_pkgs,
                                 'page': 'pkgs'})
    return render_to_response('pkgs/orphaned.html', c)
Ejemplo n.º 9
0
def index(request, catalog_filter=None):
    can_view_pkgs = request.user.has_perm('pkgs.can_view_pkgs')
    can_view_manifests = request.user.has_perm('manifests.can_view_manifests')
    can_view_catalogs = request.user.has_perm('catalogs.can_view_catalogs')
    change_pkgs = request.user.has_perm('pkgs.change_pkgs')
    delete_pkgs = request.user.has_perm('pkgs.delete_pkgs')

    if not catalog_filter:
        catalog_filter = "all"
    
    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()

    if request.method == 'GET':
        findtext = request.GET.get('findtext')
    else:
        findtext = ""
    all_catalog_items = Packages.detail(catalog_filter, findtext)
    catalog_list = Catalog.list()
    catalog_name = 'none'
    if PROD_CATALOG in catalog_list:
        catalog_name = PROD_CATALOG
    elif 'testing' in catalog_list:
        catalog_name = 'testing'
    c = RequestContext(request, {'user': request.user,
                               'all_catalog_items': all_catalog_items,
                               'catalog_filter': catalog_filter,
                               'catalog_list': catalog_list,
                               'catalog_name': catalog_name,
                               'findtext': findtext,
                               'can_view_pkgs': can_view_pkgs,
                               'can_view_manifests': can_view_manifests,
                               'can_view_catalogs': can_view_catalogs,
                               'change_pkgs': change_pkgs,
                               'delete_pkgs': delete_pkgs,
                               'git_enabled': git_enabled,
                               'git_branching_enabled': git_branching_enabled,
                               'page': 'pkgs'})
    return render_to_response('pkgs/index.html', c)
Ejemplo n.º 10
0
def done(request):
    if request.method == 'POST': # If the form has been submitted...
        final_items_to_move = request.POST.getlist('final_items_to_move[]')
        confirm_move = request.POST.get('confirm_move')
        confirm_add = request.POST.get('confirm_add')
        confirm_remove = request.POST.get('confirm_remove')
        new_dest_catalog = request.POST.get('new_dest_catalog')
        if new_dest_catalog:
            new_dest_catalog = new_dest_catalog.lower()
        tuple(final_items_to_move)
        for n,pkg in enumerate(final_items_to_move):
            pkg = pkg.split('___')
            final_items_to_move[n] = pkg
        if confirm_remove:
            for pkg_name, pkg_version, pkg_orig in final_items_to_move:
                if pkg_orig != 'no-catalog':
                    Packages.remove(pkg_name, pkg_version, pkg_orig)
        elif confirm_add:
            for pkg_name, pkg_version, pkg_orig, pkg_catalog in final_items_to_move:
                if pkg_orig == 'no-catalog':
                    if pkg_catalog == 'set-new' and new_dest_catalog:
                        Packages.move(pkg_name, pkg_version, new_dest_catalog)
                    elif pkg_catalog != 'set-new':
                        Packages.move(pkg_name, pkg_version, pkg_catalog)
                else:
                    if pkg_catalog == 'set-new' and new_dest_catalog:
                        Packages.add(pkg_name, pkg_version, pkg_orig, new_dest_catalog)
                    elif pkg_catalog != 'set-new':
                        Packages.add(pkg_name, pkg_version, pkg_orig, pkg_catalog)
        else:
            for pkg_name, pkg_version, pkg_catalog in final_items_to_move:
                if new_dest_catalog:
                    pkg_catalog = new_dest_catalog
                elif pkg_catalog != 'set-new':
                    Packages.move(pkg_name, pkg_version, pkg_catalog)
        Packages.makecatalogs()
        context = {'user': request.user,
                   'final_items_to_move': final_items_to_move,
                   'confirm_move': confirm_move,
                   'confirm_add': confirm_add,
                   'confirm_remove': confirm_remove,
                   'done': 'Done',
                   'page': 'pkgs'}
        return render_to_response('pkgs/done.html', context)
    else:
        return HttpResponse("No form submitted.\n")
Ejemplo n.º 11
0
def gitpull(request, pkgsinfo_name=None):
    if request.method == 'GET':
        Packages.gitPull()
    return HttpResponseRedirect('/pkgs/')
Ejemplo n.º 12
0
def done(request):
#     can_view_pkgs = request.user.has_perm('pkgs.can_view_pkgs')
#     can_view_manifests = request.user.has_perm('manifests.can_view_manifests')
#     can_view_catalogs = request.user.has_perm('catalogs.can_view_catalogs')
#     change_pkgs = request.user.has_perm('pkgs.change_pkgs')
#     delete_pkgs = request.user.has_perm('pkgs.delete_pkgs')
    if request.method == 'POST': # If the form has been submitted...
        final_items_to_move = request.POST.getlist('final_items_to_move[]')
        confirm_move = request.POST.get('confirm_move')
        confirm_add = request.POST.get('confirm_add')
        confirm_remove = request.POST.get('confirm_remove')
        new_dest_catalog = request.POST.get('new_dest_catalog')
        if new_dest_catalog:
            new_dest_catalog = new_dest_catalog.lower()
        tuple(final_items_to_move)
        for n,pkg in enumerate(final_items_to_move):
            pkg = pkg.split('___')
            final_items_to_move[n] = pkg
        if confirm_remove:
            for pkg_name, pkg_version, pkg_orig in final_items_to_move:
                if pkg_orig != 'no-catalog':
                    Packages.remove(pkg_name, pkg_version, pkg_orig, request.user)
        elif confirm_add:
            for pkg_name, pkg_version, pkg_orig, pkg_catalog in final_items_to_move:
                if pkg_orig == 'no-catalog':
                    if pkg_catalog == 'set-new' and new_dest_catalog:
                        Packages.move(pkg_name, pkg_version, new_dest_catalog, 
                                      request.user)
                    elif pkg_catalog != 'set-new':
                        Packages.move(pkg_name, pkg_version, pkg_catalog, request.user)
                else:
                    if pkg_catalog == 'set-new' and new_dest_catalog:
                        Packages.add(pkg_name, pkg_version, pkg_orig, new_dest_catalog, 
                                     request.user)
                    elif pkg_catalog != 'set-new':
                        Packages.add(pkg_name, pkg_version, pkg_orig, pkg_catalog, 
                                     request.user)
        else:
            for pkg_name, pkg_version, pkg_catalog in final_items_to_move:
                if new_dest_catalog:
#                    pkg_catalog = new_dest_catalog
                    Packages.move(pkg_name, pkg_version, new_dest_catalog, request.user)
                elif pkg_catalog != 'set-new':
                    Packages.move(pkg_name, pkg_version, pkg_catalog, request.user)
        Packages.makecatalogs(request.user)
        c = RequestContext(request, {'user': request.user,
                   'final_items_to_move': final_items_to_move,
                   'confirm_move': confirm_move,
                   'confirm_add': confirm_add,
                   'confirm_remove': confirm_remove,
#                    'can_view_pkgs': can_view_pkgs,
#                    'can_view_manifests': can_view_manifests,
#                    'can_view_catalogs': can_view_catalogs,
#                    'change_pkgs': change_pkgs,
#                    'delete_pkgs': delete_pkgs,
                   'done': 'Done',
                   'page': 'pkgs'})
        return render_to_response('pkgs/done.html', c)
    else:
        return HttpResponse("No form submitted.\n")