Ejemplo n.º 1
0
def initializer(env_root, args, out=sys.stdout, err=sys.stderr):
    from templates import PACKAGE_JSON, TEST_MAIN_JS
    from preflight import create_jid
    path = os.getcwd()
    addon = os.path.basename(path)
    # if more than two arguments
    if len(args) > 2:
        print >> err, 'Too many arguments.'
        return {"result": 1}
    if len(args) == 2:
        path = os.path.join(path, args[1])
        try:
            os.mkdir(path)
            print >> out, '*', args[1], 'package directory created'
        except OSError:
            print >> out, '*', args[
                1], 'already exists, testing if directory is empty'
    # avoid clobbering existing files, but we tolerate things like .git
    existing = [fn for fn in os.listdir(path) if not fn.startswith(".")]
    if existing:
        print >> err, 'This command must be run in an empty directory.'
        return {"result": 1}
    for d in ['lib', 'data', 'test', 'doc']:
        os.mkdir(os.path.join(path, d))
        print >> out, '*', d, 'directory created'
    open(os.path.join(path, 'README.md'), 'w').write('')
    print >> out, '* README.md written'
    jid = create_jid()
    print >> out, '* generated jID automatically:', jid
    open(os.path.join(path, 'package.json'), 'w').write(PACKAGE_JSON % {
        'name': addon.lower(),
        'title': addon,
        'id': jid
    })
    print >> out, '* package.json written'
    open(os.path.join(path, 'test', 'test-main.js'), 'w').write(TEST_MAIN_JS)
    print >> out, '* test/test-main.js written'
    open(os.path.join(path, 'lib', 'main.js'), 'w').write('')
    print >> out, '* lib/main.js written'
    open(os.path.join(path, 'doc', 'main.md'), 'w').write('')
    print >> out, '* doc/main.md written'
    if len(args) == 1:
        print >> out, '\nYour sample add-on is now ready.'
        print >> out, 'Do "cfx test" to test it and "cfx run" to try it.  Have fun!'
    else:
        print >> out, '\nYour sample add-on is now ready in the \'' + args[
            1] + '\' directory.'
        print >> out, 'Change to that directory, then do "cfx test" to test it, \nand "cfx run" to try it.  Have fun!'
    return {"result": 0, "jid": jid}
Ejemplo n.º 2
0
def initializer(env_root, args, out=sys.stdout, err=sys.stderr):
    from templates import PACKAGE_JSON, TEST_MAIN_JS
    from preflight import create_jid

    path = os.getcwd()
    addon = os.path.basename(path)
    # if more than two arguments
    if len(args) > 2:
        print >> err, "Too many arguments."
        return {"result": 1}
    if len(args) == 2:
        path = os.path.join(path, args[1])
        try:
            os.mkdir(path)
            print >> out, "*", args[1], "package directory created"
        except OSError:
            print >> out, "*", args[1], "already exists, testing if directory is empty"
    # avoid clobbering existing files, but we tolerate things like .git
    existing = [fn for fn in os.listdir(path) if not fn.startswith(".")]
    if existing:
        print >> err, "This command must be run in an empty directory."
        return {"result": 1}
    for d in ["lib", "data", "test", "doc"]:
        os.mkdir(os.path.join(path, d))
        print >> out, "*", d, "directory created"
    open(os.path.join(path, "README.md"), "w").write("")
    print >> out, "* README.md written"
    jid = create_jid()
    print >> out, "* generated jID automatically:", jid
    open(os.path.join(path, "package.json"), "w").write(
        PACKAGE_JSON % {"name": addon.lower(), "fullName": addon, "id": jid}
    )
    print >> out, "* package.json written"
    open(os.path.join(path, "test", "test-main.js"), "w").write(TEST_MAIN_JS)
    print >> out, "* test/test-main.js written"
    open(os.path.join(path, "lib", "main.js"), "w").write("")
    print >> out, "* lib/main.js written"
    open(os.path.join(path, "doc", "main.md"), "w").write("")
    print >> out, "* doc/main.md written"
    if len(args) == 1:
        print >> out, "\nYour sample add-on is now ready."
        print >> out, 'Do "cfx test" to test it and "cfx run" to try it.  Have fun!'
    else:
        print >> out, "\nYour sample add-on is now ready in the '" + args[1] + "' directory."
        print >> out, 'Change to that directory, then do "cfx test" to test it, \nand "cfx run" to try it.  Have fun!'
    return {"result": 0, "jid": jid}
Ejemplo n.º 3
0
def initializer(env_root, args, out=sys.stdout, err=sys.stderr):
    from templates import PACKAGE_JSON, TEST_MAIN_JS
    from preflight import create_jid
    path = os.getcwd()
    addon = os.path.basename(path)
    # if more than two arguments
    if len(args) > 2:
        print >>err, 'Too many arguments.'
        return {"result":1}
    if len(args) == 2:
        path = os.path.join(path,args[1])
        try:
            os.mkdir(path)
            print >>out, '*', args[1], 'package directory created'
        except OSError:
            print >>out, '*', args[1], 'already exists, testing if directory is empty'
    # avoid clobbering existing files, but we tolerate things like .git
    existing = [fn for fn in os.listdir(path) if not fn.startswith(".")]
    if existing:
        print >>err, 'This command must be run in an empty directory.'
        return {"result":1}
    for d in ['lib','data','test','doc']:
        os.mkdir(os.path.join(path,d))
        print >>out, '*', d, 'directory created'
    open(os.path.join(path,'README.md'),'w').write('')
    print >>out, '* README.md written'
    jid = create_jid()
    print >>out, '* generated jID automatically:', jid
    open(os.path.join(path,'package.json'),'w').write(PACKAGE_JSON % {'name':addon.lower(),
                                                   'fullName':addon,
                                                   'id':jid })
    print >>out, '* package.json written'
    open(os.path.join(path,'test','test-main.js'),'w').write(TEST_MAIN_JS)
    print >>out, '* test/test-main.js written'
    open(os.path.join(path,'lib','main.js'),'w').write('')
    print >>out, '* lib/main.js written'
    open(os.path.join(path,'doc','main.md'),'w').write('')
    print >>out, '* doc/main.md written'
    if len(args) == 1:
        print >>out, '\nYour sample add-on is now ready.'
        print >>out, 'Do "cfx test" to test it and "cfx run" to try it.  Have fun!'
    else:
        print >>out, '\nYour sample add-on is now ready in the \'' + args[1] +  '\' directory.'
        print >>out, 'Change to that directory, then do "cfx test" to test it, \nand "cfx run" to try it.  Have fun!'
    return {"result":0, "jid":jid}