def generate_resource(request, res_type, name, medium=None): print "Generating %s %s" % (res_type, name) output = helpers.get_output_path(request, res_type, name) file_list = helpers.get_file_list(res_type, name, medium) if res_type == 'script': script.pack(request, file_list, output, settings.RAPE_PACK) elif res_type == 'style': style.pack(request, file_list, output, settings.RAPE_PACK) else: raise Exception('Unknown resource type: %s' % res_type)
from helpers import cq_auth_header, post_multipart, get_file_list, read_file from odict import odict #------ CUSTOM PARAMS // pass in via command line ----------------------------- assert len(sys.argv) >= 5, "Supply cq_server, username, password, payloads_path, [mode] when calling this script." CQ_SERVER, USERNAME, PASSWORD, PAYLOADS_PATH = sys.argv[1:5] try: MODE = sys.argv[5] except IndexError: MODE = 'itemwise' assert MODE in ['itemwise', 'nodewise'], "Supported modes are 'itemwise' and 'nodewise'." print '> Loading %s...' % MODE HEADERS = cq_auth_header(USERNAME, PASSWORD) # USERNAME, PASSWORD for CQ user JSON_PATHS = get_file_list(PAYLOADS_PATH, '.*\.json') # directory of .json files #------------------------------------------------------------------------------ def populate_node(path, properties, **kwargs): "Organizes properties into form fields and posts the multipart form data." # properties can be handled as strings by default fields = [ (p['name'], p['value']) for p in properties if not p.has_key('type')] # properties with a type need to be hinted hinted = [ hp for hp in properties if hp.has_key('type') and hp['type'] != 'nt:file'] for hp in hinted: if hp['value'].__class__.__name__ == 'str': fields.append((hp['name'], hp['value'])) # single item else: map(lambda i: fields.append((hp['name'], i)), hp['value']) # multiple items