Example #1
0
def cmd_init(settings):
    sa = Host.get_session("default", settings.dbref)
    host_dict = init_host(settings)
    name = host_dict["name"]
    record = Host.fetch(filters=(Host.name == name,), sa=sa, exists=False)
    if not record:
        host = Host(name=name, date_added=datetime.now(), date_updated=datetime.now())
        sa.add(host)
        sa.commit()
        log.std("{bwhite}Added host %s record{default}", name)
    else:
        host = record
    print "host at", host_dict.path(), ":", host
Example #2
0
def cmd_init(settings):
    sa = Workspace.get_session('project', __version__)
    sa = Project.get_session('default', settings.dbref)
    #sa = get_session(settings.dbref)
    pwd = os.getcwd()
    name = os.path.basename(pwd)
    projdir = Workdir.find(pwd)
    rs = Project.search(name=name)
    if projdir:
        if not rs:
        	pass
        print("Already in existing project!")
        print(projdir[0])
        return 1
    if rs:
        print("Project with this name already exists")
        return 1
    projdir = Workdir(pwd)
    project = Project(
            name=name,
            date_added=datetime.now(),
        )
    curhost = Host.init(sa=sa) # FIXME returns localhost.
    # TODO project.hosts.append(curhost)
    repo = Repo(pwd)
    checkout = VersionControl(vc_type=repo.rtype, path=pwd, host=curhost)
    sa.add(checkout)
    project.repositories.append( checkout )# TODO: and remotes
    sa.add(project)
    sa.commit()
    projdir.init(create=True)
    print("Created project", name, projdir.metadir_id)
Example #3
0
def txs_session(prog=None, sa=None, opts=None, settings=None):
    # default SA session
    dbref = opts.dbref
    if opts.init:
        log.debug("Initializing SQLAlchemy session for %s", dbref)
    sa = SessionMixin.get_session('default', opts.dbref, opts.init)
    # Host
    hostnamestr = current_hostname(opts.init, opts.interactive)
    if opts.init:
        hostname = hostname_find([hostnamestr], sa)
        assert not hostname or not isinstance(hostname, (tuple, list)), hostname
        if not hostname:
            log.note("New Name: %s", hostnamestr)
            hostname = Name(
                    name=hostnamestr,
                    date_added=datetime.now())
            hostname.commit()
        else:
            log.warn("Name exists: %s", hostname)
        assert hostname
        host = host_find([hostname], sa)
        if not host:
            log.note("New Host: %s", hostnamestr)
            host = Host(
                    hostname=hostname,
                    date_added=datetime.now())
            host.commit()
        else:
            log.warn("Host exists: %s", host)
        assert host
    else:
        host, name = sa.query(Host, Name)\
            .join('hostname')\
            .filter(Name.name == hostnamestr).one()
        if not host:
            log.crit("Could not get host")
    urlresolver = LocalPathResolver(host, sa)
    log.info("On %s", host)
    yield Keywords(sa=sa, ur=urlresolver)
Example #4
0
def cmd_test_init(settings):
    sa = Host.get_session("default", settings.dbref)
    host_dict = init_host(settings)
    name = host_dict["name"]
    print Host.fetch(filters=(Host.name == name,), sa=sa, exists=False)
Example #5
0
def cmd_list(settings):
    sa = Host.get_session("default", settings.dbref)
    for h in sa.query(Host).all():
        print h