Example #1
0
def compile_vitamin(v, dom):

    temp_name = "temp.scad"

    #
    # Make the target directories
    #
    target_dir = "../vitamins/stl"
    if not os.path.isdir(target_dir):
        os.makedirs(target_dir)

    view_dir = "../vitamins/images"
    if not os.path.isdir(view_dir):
        os.makedirs(view_dir)

    # Compile
    print("  " + v['title'])
    fn = '../' + v['file']
    if (os.path.isfile(fn)):

        print("    Checking csg hash")
        h = openscad.get_csg_hash(temp_name, v['call'], [fn])
        os.remove(temp_name)

        hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v)

        # update hash in json
        v['hash'] = h

        # STL
        print("    STL Parts")
        for part in v['children']:
            if type(part) is DictType and part['type'] == 'part':
                stlpath = target_dir + '/' + openscad.stl_filename(
                    part['title'])
                if hashchanged or (not os.path.isfile(stlpath)):
                    print("      Rendering STL...")
                    openscad.render_stl(temp_name, stlpath, part['call'], [fn])
                else:
                    print("      STL up to date")

        # Views
        print("    Views")
        for view in v['children']:
            if type(view) is DictType and view['type'] == 'view':
                print("      " + view['title'])

                render_view(v['title'], v['call'], view_dir, view, hashchanged,
                            h, [fn], False)

                png_name = view_dir + '/' + view_filename(v['title'] + '_' +
                                                          view['title'])
                view['png_name'] = png_name

        node = add_vitamin(v, dom)

    else:
        print("    Error: scad file not found: " + v['file'])
def compile_vitamin(v, dom):

    temp_name =  "temp.scad"


    #
    # Make the target directories
    #
    target_dir = "../vitamins/stl"
    if not os.path.isdir(target_dir):
        os.makedirs(target_dir)

    view_dir = "../vitamins/images"
    if not os.path.isdir(view_dir):
        os.makedirs(view_dir)

    # Compile
    print("  "+v['title'])
    fn = '../' + v['file']
    if (os.path.isfile(fn)):

        print("    Checking csg hash")
        h = openscad.get_csg_hash(temp_name, v['call'], [fn]);
        os.remove(temp_name);

        hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v)

        # update hash in json
        v['hash'] = h

        # STL
        print("    STL Parts")
        for part in v['children']:
            if type(part) is DictType and part['type'] == 'part':
                stlpath = target_dir + '/' + openscad.stl_filename(part['title'])
                if hashchanged or (not os.path.isfile(stlpath)):
                    print("      Rendering STL...")
                    openscad.render_stl(temp_name, stlpath, part['call'], [fn])
                else:
                    print("      STL up to date")

        # Views
        print("    Views")
        for view in v['children']:
            if type(view) is DictType and view['type'] == 'view':
                print("      "+view['title'])

                render_view(v['title'], v['call'], view_dir, view, hashchanged, h, [fn], False)

                png_name = view_dir + '/' + view_filename(v['title'] + '_' + view['title'])
                view['png_name'] = png_name


        node = add_vitamin(v, dom)


    else:
        print("    Error: scad file not found: "+v['file'])
def compile_vitamin(v):

    #
    # Make the target directories
    #
    if not os.path.isdir(config.paths['vitaminsstl']):
        os.makedirs(config.paths['vitaminsstl'])

    if not os.path.isdir(config.paths['vitaminsimages2']):
        os.makedirs(config.paths['vitaminsimages2'])

    # Compile
    print("  " + v['title'])
    fn = os.path.join('..', v['file'])
    if (os.path.isfile(fn)):

        print("    Checking csg hash")
        h = openscad.get_csg_hash(config.paths['tempscad'], v['call'])
        os.remove(config.paths['tempscad'])

        hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v)

        # update hash in json
        v['hash'] = h

        # STL
        print("    STL Parts")
        if 'parts' in v:
            for part in v['parts']:
                stlpath = os.path.join(config.paths['vitaminsstl'],
                                       openscad.stl_filename(part['title']))
                if hashchanged or (not os.path.isfile(stlpath)):
                    print("      Rendering STL...")
                    openscad.render_stl(config.paths['tempscad'], stlpath,
                                        part['call'])
                else:
                    print("      STL up to date")

        # Views
        print("    Views")
        for view in v['views']:
            print("      " + view['title'])

            render_view(v['title'], v['call'], config.paths['vitaminsimages2'],
                        view, hashchanged, h)

    else:
        print("    Error: scad file not found: " + v['file'])
Example #4
0
 def get(self,mode):
     if users.is_current_user_admin():
         if mode == "log":
             t_path = 'templates/admin-editlogs.html'
             logs = models.get_logs()
             page = views.render_view(t_path, 'editlogs',logs[0])
         if mode == "stuff":
             t_path = 'templates/admin-editstuff.html'
             stuff = models.get_all_stuff()
             page = views.render_view(t_path, 'editstuff', stuff)
         if mode == "ttext":
             t_path = 'templates/admin-edittt.html'
             tt = models.get_all_tt()
             page = views.render_view(t_path, 'edittt', tt)
         self.response.out.write(page)
     else:
         self.redirect('/')
def compile_vitamin(v, dom):

    #
    # Make the target directories
    #
    if not os.path.isdir(config.paths['vitaminsimages']):
        os.makedirs(config.paths['vitaminsimages'])

    # Compile
    print("  " + v['title'])
    fn = '../' + v['file']
    if (os.path.isfile(fn)):

        print("    Checking csg hash")
        h = openscad.get_csg_hash(config.paths['tempscad'], v['call'], [fn])
        os.remove(config.paths['tempscad'])

        hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v)

        # update hash in json
        v['hash'] = h

        # Views
        print("    Views")
        for view in v['children']:
            if isinstance(view, dict) and view['type'] == 'view':
                print("      " + view['title'])

                render_view(v['title'],
                            v['call'],
                            config.paths['vitaminsimages'],
                            view,
                            hashchanged,
                            h, [fn],
                            False,
                            useVitaminSTL=False)

                png_name = os.path.join(
                    config.paths['vitaminsimages'],
                    view_filename(v['title'] + '_' + view['title']))
                view['png_name'] = png_name

        node = add_vitamin(v, dom)

    else:
        print("    Error: scad file not found: " + v['file'])
Example #6
0
 def get(self):
     if users.is_current_user_admin():
         stuff = models.get_all_stuff()
         numbers = []
         for s in stuff:
             numbers.append(s.number)
         t_path = 'templates/admin-add.html'
         admin_main = views.render_view(t_path, 'add', numbers)
         self.response.out.write(admin_main)
     else:
         self.redirect('/')
Example #7
0
def vitamins():
    print("Vitamins")
    print("--------")

    temp_name = "temp.scad"

    #
    # Make the target directories
    #
    target_dir = "../vitamins/stl"
    if not os.path.isdir(target_dir):
        os.makedirs(target_dir)

    view_dir = "../vitamins/images"
    if not os.path.isdir(view_dir):
        os.makedirs(view_dir)

    # load hardware.json
    jf = open("hardware.json", "r")
    jso = json.load(jf)
    jf.close()

    # for each machine
    for m in jso:
        if type(m) is DictType and m['type'] == 'machine':
            print(m['title'])

            vl = m['vitamins']

            for v in vl:
                print("  " + v['title'])
                fn = '../' + v['file']
                if (os.path.isfile(fn)):

                    print("    Checking csg hash")
                    h = openscad.get_csg_hash(temp_name, v['call'])
                    os.remove(temp_name)

                    hashchanged = ('hash' in v
                                   and h != v['hash']) or (not 'hash' in v)

                    # update hash in json
                    v['hash'] = h

                    # STL
                    print("    STL Parts")
                    if 'parts' in v:
                        for part in v['parts']:
                            stlpath = target_dir + '/' + openscad.stl_filename(
                                part['title'])
                            if hashchanged or (not os.path.isfile(stlpath)):
                                print("      Rendering STL...")
                                openscad.render_stl(temp_name, stlpath,
                                                    part['call'])
                            else:
                                print("      STL up to date")

                    # Views
                    print("    Views")
                    for view in v['views']:
                        print("      " + view['title'])

                        render_view(v['title'], v['call'], view_dir, view,
                                    hashchanged, h)

                else:
                    print("    Error: scad file not found: " + v['file'])

    # Save changes to json
    with open('hardware.json', 'w') as f:
        f.write(
            json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': ')))

    return 0
Example #8
0
 def get(self):
     text = models.get_tt('info')
     t_path = 'templates/public-info.html'
     info_page = views.render_view(t_path, 'info', text)
     self.response.out.write(info_page)
Example #9
0
def printed():
    print("Printed Parts")
    print("-------------")

    temp_name =  "temp.scad"

    #
    # Make the target directories
    #
    target_dir = "../printedparts/stl"
    if not os.path.isdir(target_dir):
        os.makedirs(target_dir)

    view_dir = "../printedparts/images"
    if not os.path.isdir(view_dir):
        os.makedirs(view_dir)

    # load hardware.json
    jf = open("hardware.json","r")
    jso = json.load(jf)
    jf.close()
    
    # for each machine
    for m in jso:
        if type(m) is DictType and m['type'] == 'machine':
            print(m['title'])
            
            pl = m['printed']
            
            for p in pl:
                print("  "+p['title'])
                fn = '../' + p['file']
                if (os.path.isfile(fn)):
                    
                    stlpath = target_dir + '/' + openscad.stl_filename(p['title'])
                    md5path = target_dir + '/' + openscad.stl_filename(p['title']) + '.md5'
                
                    print("    Checking csg hash")
                    # Get csg hash
                    h = openscad.get_csg_hash(temp_name, p['call']);
                    os.remove(temp_name);
                    
                    # Get old csg hash
                    oldh = ""
                    if os.path.isfile(md5path):
                        with open(md5path,'r') as f:
                            oldh = f.read()
                    
                    hashchanged = h != oldh
                    
                    # update hash in json
                    p['hash'] = h
                    
                    # save new hash
                    with open(md5path,'w') as f:
                        f.write(h)
                        
                    # STL
                    print("    STL")
                    if hashchanged or (not os.path.isfile(stlpath)):
                        print("      Rendering STL...")
                        info = openscad.render_stl(temp_name, stlpath, p['call'])
                        
                        jsontools.json_merge_missing_keys(p, info) 
                        
                    else:
                        print("      STL up to date")
                    
                    print("    views")
                    # Views
                    for view in p['views']:
                        print("      "+view['title'])
                        
                        render_view(p['title'], p['call'], view_dir, view, hashchanged, h)
                        
                else:
                    print("    Error: scad file not found: "+p['file'])
                        
            
    # Save changes to json
    with open('hardware.json', 'w') as f:
        f.write(json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': ')))
        
    return 0
Example #10
0
 def renderPage(self, page):
     logs = models.get_logs(int(page))
     t_path = 'templates/public-logs.html'
     return views.render_view(t_path, 'logs',logs)
Example #11
0
 def renderStuff(self):
     t_path = 'templates/public-stufflist.html'
     stuff = models.get_all_stuff()
     return views.render_view(t_path, 'stufflist', stuff)
Example #12
0
def printed():
    print("Printed Parts")
    print("-------------")

    temp_name = "temp.scad"

    #
    # Make the target directories
    #
    target_dir = "../printedparts/stl"
    if not os.path.isdir(target_dir):
        os.makedirs(target_dir)

    view_dir = "../printedparts/images"
    if not os.path.isdir(view_dir):
        os.makedirs(view_dir)

    # load hardware.json
    jf = open("hardware.json", "r")
    jso = json.load(jf)
    jf.close()

    # for each machine
    for m in jso:
        if type(m) is DictType and m['type'] == 'machine':
            print(m['title'])

            pl = m['printed']

            for p in pl:
                print("  " + p['title'])
                fn = '../' + p['file']
                if (os.path.isfile(fn)):

                    stlpath = target_dir + '/' + openscad.stl_filename(
                        p['title'])
                    md5path = target_dir + '/' + openscad.stl_filename(
                        p['title']) + '.md5'

                    print("    Checking csg hash")
                    # Get csg hash
                    h = openscad.get_csg_hash(temp_name, p['call'])
                    os.remove(temp_name)

                    # Get old csg hash
                    oldh = ""
                    if os.path.isfile(md5path):
                        with open(md5path, 'r') as f:
                            oldh = f.read()

                    hashchanged = h != oldh

                    # update hash in json
                    p['hash'] = h

                    # save new hash
                    with open(md5path, 'w') as f:
                        f.write(h)

                    # STL
                    print("    STL")
                    if hashchanged or (not os.path.isfile(stlpath)):
                        print("      Rendering STL...")
                        info = openscad.render_stl(temp_name, stlpath,
                                                   p['call'])

                        jsontools.json_merge_missing_keys(p, info)

                    else:
                        print("      STL up to date")

                    print("    views")
                    # Views
                    for view in p['views']:
                        print("      " + view['title'])

                        render_view(p['title'], p['call'], view_dir, view,
                                    hashchanged, h)

                else:
                    print("    Error: scad file not found: " + p['file'])

    # Save changes to json
    with open('hardware.json', 'w') as f:
        f.write(
            json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': ')))

    return 0
Example #13
0
def vitamins():
    print("Vitamins")
    print("--------")

    temp_name =  "temp.scad"

    #
    # Make the target directories
    #
    target_dir = "../vitamins/stl"
    if not os.path.isdir(target_dir):
        os.makedirs(target_dir)

    view_dir = "../vitamins/images"
    if not os.path.isdir(view_dir):
        os.makedirs(view_dir)

    # load hardware.json
    jf = open("hardware.json","r")
    jso = json.load(jf)
    jf.close()
    
    # for each machine
    for m in jso:
        if type(m) is DictType and m['type'] == 'machine':
            print(m['title'])
            
            vl = m['vitamins']
            
            for v in vl:
                print("  "+v['title'])
                fn = '../' + v['file']
                if (os.path.isfile(fn)):
                
                    print("    Checking csg hash")
                    h = openscad.get_csg_hash(temp_name, v['call']);
                    os.remove(temp_name);
                    
                    hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v)
                    
                    # update hash in json
                    v['hash'] = h
                        
                    # STL
                    print("    STL Parts")
                    if 'parts' in v:
                        for part in v['parts']:
                            stlpath = target_dir + '/' + openscad.stl_filename(part['title'])
                            if hashchanged or (not os.path.isfile(stlpath)):
                                print("      Rendering STL...")
                                openscad.render_stl(temp_name, stlpath, part['call'])
                            else:
                                print("      STL up to date")
                    
                    # Views
                    print("    Views")
                    for view in v['views']:
                        print("      "+view['title'])
                        
                        render_view(v['title'], v['call'], view_dir, view, hashchanged, h)
                        
                        
                else:
                    print("    Error: scad file not found: "+v['file'])
                        
            
    # Save changes to json
    with open('hardware.json', 'w') as f:
        f.write(json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': ')))
        
    return 0
Example #14
0
def printed():
    print("Printed Parts")
    print("-------------")

    temp_name =  "temp.scad"

    #
    # Make the target directories
    #
    target_dir = "../printedparts/stl"
    if not os.path.isdir(target_dir):
        os.makedirs(target_dir)

    # store a list of valid STLs to aid cleanup
    stlList = []

    view_dir = "../printedparts/images"
    if not os.path.isdir(view_dir):
        os.makedirs(view_dir)

    # load hardware.json
    jf = open("hardware.json","r")
    jso = json.load(jf)
    jf.close()

    # for each machine
    for m in jso:
        if type(m) is DictType and m['type'] == 'machine':
            print(m['title'])

            pl = m['printed']

            for p in pl:
                print("  "+p['title'])
                fn = '../' + p['file']
                if (os.path.isfile(fn)):

                    stlpath = os.path.join(target_dir, openscad.stl_filename(p['title']))
                    md5path = os.path.join(target_dir, openscad.stl_filename(p['title']) + '.md5')

                    print("    Checking csg hash")
                    # Get csg hash
                    h = openscad.get_csg_hash(temp_name, p['call']);
                    os.remove(temp_name);

                    # Get old csg hash
                    oldh = ""
                    if os.path.isfile(md5path):
                        with open(md5path,'r') as f:
                            oldh = f.read()

                    hashchanged = h != oldh

                    # update hash in json
                    p['hash'] = h

                    # save new hash
                    with open(md5path,'w') as f:
                        f.write(h)

                    # STL
                    print("    STL")
                    if hashchanged or (not os.path.isfile(stlpath)):
                        print("      Rendering STL...")
                        info = openscad.render_stl(temp_name, stlpath, p['call'])
                        jsontools.json_merge_missing_keys(p, info)

                    # Slice for weight and volume
                    print("    Slice")
                    if hashchanged or ('plasticWeight' not in p):
                        # Slice part and track volume of plastic required
                        # Estimate KG of plastic from density range: 1.23-1.25 g/cm3
                        plasticInfo = slic3r.calc_plastic_required(stlpath)
                        jsontools.json_merge_missing_keys(p, plasticInfo)

                    else:
                        print("      GCode up to date")

                    print("    views")
                    # Views
                    for view in p['views']:
                        print("      "+view['title'])

                        render_view(p['title'], p['call'], view_dir, view, hashchanged, h)

                    # Add to stlList
                    stlList.append(stlpath)
                    stlList.append(md5path)

                else:
                    print("    Error: scad file not found: "+p['file'])


    # Save changes to json
    with open('hardware.json', 'w') as f:
        f.write(json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': ')))

    # clean-up orphaned stls and checksums
    print "Checking for outdated STLs..."
    for f in os.listdir(target_dir):
        fp = os.path.join(target_dir, f)
        try:
            if os.path.isfile(fp) and (fp not in stlList):
                print "Removing: "+fp
                os.remove(fp)
        except Exception, e:
            print e
Example #15
0
 def get(self, log):
     log = models.get_log(int(log))
     t_path = 'templates/public-logentry.html'
     return views.render_view(t_path, 'logentry',log)
Example #16
0
def printed():
    print("Printed Parts")
    print("-------------")

    temp_name = "temp.scad"

    #
    # Make the target directories
    #
    target_dir = "../printedparts/stl"
    if not os.path.isdir(target_dir):
        os.makedirs(target_dir)

    # store a list of valid STLs to aid cleanup
    stlList = []

    view_dir = "../printedparts/images"
    if not os.path.isdir(view_dir):
        os.makedirs(view_dir)

    # load hardware.json
    jf = open("hardware.json", "r")
    jso = json.load(jf)
    jf.close()

    # for each machine
    for m in jso:
        if type(m) is DictType and m['type'] == 'machine':
            print(m['title'])

            pl = m['printed']

            for p in pl:
                print("  " + p['title'])
                fn = '../' + p['file']
                if (os.path.isfile(fn)):

                    stlpath = os.path.join(target_dir,
                                           openscad.stl_filename(p['title']))
                    md5path = os.path.join(
                        target_dir,
                        openscad.stl_filename(p['title']) + '.md5')

                    print("    Checking csg hash")
                    # Get csg hash
                    h = openscad.get_csg_hash(temp_name, p['call'])
                    os.remove(temp_name)

                    # Get old csg hash
                    oldh = ""
                    if os.path.isfile(md5path):
                        with open(md5path, 'r') as f:
                            oldh = f.read()

                    hashchanged = h != oldh

                    # update hash in json
                    p['hash'] = h

                    # save new hash
                    with open(md5path, 'w') as f:
                        f.write(h)

                    # STL
                    print("    STL")
                    if hashchanged or (not os.path.isfile(stlpath)):
                        print("      Rendering STL...")
                        info = openscad.render_stl(temp_name, stlpath,
                                                   p['call'])
                        jsontools.json_merge_missing_keys(p, info)

                    # Slice for weight and volume
                    print("    Slice")
                    if hashchanged or ('plasticWeight' not in p):
                        # Slice part and track volume of plastic required
                        # Estimate KG of plastic from density range: 1.23-1.25 g/cm3
                        plasticInfo = slic3r.calc_plastic_required(stlpath)
                        jsontools.json_merge_missing_keys(p, plasticInfo)

                    else:
                        print("      GCode up to date")

                    print("    views")
                    # Views
                    for view in p['views']:
                        print("      " + view['title'])

                        render_view(p['title'], p['call'], view_dir, view,
                                    hashchanged, h)

                    # Add to stlList
                    stlList.append(stlpath)
                    stlList.append(md5path)

                else:
                    print("    Error: scad file not found: " + p['file'])

    # Save changes to json
    with open('hardware.json', 'w') as f:
        f.write(
            json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': ')))

    # clean-up orphaned stls and checksums
    print "Checking for outdated STLs..."
    for f in os.listdir(target_dir):
        fp = os.path.join(target_dir, f)
        try:
            if os.path.isfile(fp) and (fp not in stlList):
                print "Removing: " + fp
                os.remove(fp)
        except Exception, e:
            print e
Example #17
0
 def get(self, post, page=1):
     t_path = 'templates/public-stuffentry.html'
     stuff = models.get_stuff(int(post))
     logs = models.get_logs(int(page), int(post))
     stuff_entry = views.render_view(t_path, 'stuffentry', [stuff, logs])
     self.response.out.write(stuff_entry)