Example #1
0
def link_global_to_local(target_name):
    local_link_file = get_local_link_file()
    global_link_file = get_global_link_file()

    if os.path.isfile(global_link_file):
        with open(global_link_file, 'r') as global_file:
            global_links = json.load(global_file)
        if target_name in global_links[target_key]:
            if os.path.isfile(local_link_file):
                with open(local_link_file, 'r') as link_file:
                    link_data = json.load(link_file)
            else:
                link_data = {
                                target_key: {},
                                module_key: {}
                            }
            target_path = global_links[target_key][target_name]
            link_data[target_key][target_name] = target_path

            with open(local_link_file, 'w') as link_file:
                links = json.dumps(link_data)
                link_file.write(links)
        else:
            print >>sys.stderr, 'Error module %s not linked globally' % target_name
            sys.exit(1)
    else:
        print >>sys.stderr, 'No modules are currently linked globally'
        sys.exit(1)

    print 'Successfully Linked %s: %s Locally' % (target_name, target_path)
Example #2
0
def link_global(target_path):
    target_path = os.path.abspath(target_path)
    target_json = os.path.join(target_path, 'target.json')
    if os.path.isfile(target_json):
        with open(target_json, 'r') as targ_json:
            try:
                target_data = json.load(targ_json)
                target_name = target_data['name']
            except ValueError:
                print >>sys.stderr, 'Error parsing data from: %s \nAre you sure it contains Vailid JSON data?' % target_json
                sys.exit(1)
    else:
        print >>sys.stderr, 'Error, unable to link %s does not contain a target.json' % target_path
        sys.exit(1)

    global_link_file = get_global_link_file()
    if os.path.isfile(global_link_file):
        with open(global_link_file, 'r') as meta_file:
            link_data = json.load(meta_file)
            link_data[target_key][target_name] = target_path
    else:
        link_data = {
                        target_key : {target_name : target_path},
                        module_key : {}
                    }

    #write the updated changes back to the global file
    with open(global_link_file, 'w') as meta_file:
        str_link_data = json.dumps(link_data)
        meta_file.write(str_link_data)
        print 'Successfully Linked %s: %s' % (target_name, target_path)
    return target_name
Example #3
0
def link_global_to_local(module_name):
    local_link_file = get_local_link_file()
    global_link_file = get_global_link_file()

    if os.path.isfile(global_link_file):
        with open(global_link_file, 'r') as global_file:
            global_links = json.load(global_file)

        if module_name in global_links:
            if os.path.isfile(local_link_file):
                with open(local_link_file, 'r') as link_file:
                    link_data = json.load(link_file)
            else:
                link_data = dict()
            module_path = global_links[module_name]
            link_data[module_name] = module_path

            with open(local_link_file, 'w') as link_file:
                links = json.dumps(link_data)
                link_file.write(links)
        else:
            print >>sys.stderr, 'Error module %s not linked globally' % module_name
            sys.exit(1)
    else:
        print >>sys.stderr, 'No modules are currently linked globally'
        sys.exit(1)

    print 'Successfully Linked %s: %s Locally' % (module_name, module_path)
Example #4
0
def link_global(module_path):
    module_json = os.path.join(module_path, 'module.json')
    if os.path.isfile(module_json):
        with open(module_json, 'r') as mod_json:
            module_data = json.load(mod_json)
            module_name = module_data['name']
    else:
        print >>sys.stderr, 'Error, unable to link %s does not contain a module.json' % module_path
        sys.exit(1)

    global_link_file = get_global_link_file()
    if os.path.isfile(global_link_file):
        with open(global_link_file, 'r') as meta_file:
            link_data = json.load(meta_file)
            link_data[module_key][module_name] = module_path
    else:
        link_data = {
                        module_key : {module_name : module_path},
                        target_key : {}
                    }

    #write the updated changes back to the global file
    with open(global_link_file, 'w') as meta_file:
        str_link_data = json.dumps(link_data)
        meta_file.write(str_link_data)
        print 'Successfully Linked %s: %s' % (module_name, module_path)
    return module_name
Example #5
0
def link_global(module_path):
    module_json = os.path.join(module_path, 'module.json')
    if os.path.isfile(module_json):
        with open(module_json, 'r') as mod_json:
            module_data = json.load(mod_json)
            module_name = module_data['name']
    else:
        print >>sys.stderr, 'Error, unable to link %s does not contain a module.json' % module_path
        sys.exit(1)

    global_link_file = get_global_link_file()
    if os.path.isfile(global_link_file):
        with open(global_link_file, 'r') as meta_file:
            link_data = json.load(meta_file)
            link_data[module_name] = module_path
    else:
        link_data = {module_name : module_path}

    #write the updated changes back to the global file
    with open(global_link_file, 'w') as meta_file:
        str_link_data = json.dumps(link_data)
        meta_file.write(str_link_data)
        print 'Successfully Linked %s: %s' % (module_name, module_path)
    return module_name