Exemple #1
0
def main():
    parser = OptionParser(usage="usage: %prog [options] <filename>")
    parser.add_option('-u',
                      '--user',
                      dest='username',
                      help='SQLshare user name')
    parser.add_option('-p',
                      '--password',
                      dest='password',
                      help='SQLshare password')
    parser.add_option(
        '-d',
        '--datasetname',
        dest='datasetname',
        help='Dataset name (defaults to filename if not supplied')

    (options, args) = parser.parse_args()

    if not args:
        parser.error('no input datafile')

    conn = sqlshare.SQLShare(options.username, options.password)

    if not options.datasetname:
        datasetname = os.path.basename(args[0])
    else:
        datasetname = options.datasetname

    conn.uploadone(args[0], datasetname)
def main():
    parser = OptionParser(
        usage=
        "usage: %prog [options] (add|remove|print|public|private) <user1> <user2> ... <userN>"
    )
    parser.add_option('-u',
                      '--user',
                      dest='username',
                      help='SQLshare user name')
    parser.add_option('-p',
                      '--password',
                      dest='password',
                      help='SQLshare password')
    parser.add_option('-t',
                      '--table',
                      dest='tables',
                      help='SQLshare dataset',
                      action='append')

    (options, args) = parser.parse_args()

    if not options.tables:
        parser.error('can not find datasets')

    if not args:
        parser.error('command not found')

    cmd = args[0]

    if cmd not in ('add', 'print', 'public', 'private', 'remove'):
        parser.error('unknown command: ' + cmd)

    if cmd == 'add' or cmd == 'remove':
        users = args[1:]
        if not users:
            parser.error('user list is required for %s command' % cmd)
        users = set(users)

    conn = sqlshare.SQLShare(options.username, options.password)

    perms = {}
    for table in options.tables:
        perms[table] = conn.get_permissions(table)
        if cmd == 'print':
            print perms[table]
            continue
        if cmd == 'add':
            viewers = list(set(perms[table]['authorized_viewers']) | users)
            perms[table]['authorized_viewers'] = viewers
        elif cmd == 'remove':
            viewers = list(set(perms[table]['authorized_viewers']) - users)
            perms[table]['authorized_viewers'] = viewers
            conn.set_permissions(table, **perms[table])
        elif cmd == 'public':
            perms[table]['is_public'] = True
        elif cmd == 'private':
            perms[table]['is_public'] = False
        conn.set_permissions(table, **perms[table])
def settags(dataset_pattern, tags, username, password):
    conn = sqlshare.SQLShare(username, password)
    tbls = conn.download_sql_result(
        "select name from sys.views where name like '%%%s%%'" %
        dataset_pattern)
    #tbls = conn.execute_sql("select * from sys.tables")
    for dataset in tbls.split("\n")[1:-1]:
        success = conn.set_tags(dataset.strip(), tags)
        if success: print "tags %s added to dataset %s" % (tags, dataset)
Exemple #4
0
def main():
    if len(sys.argv) < 4:
        print usage()
    else:
        username, password = sys.argv[1:3]
        filename = sys.argv[3]
        print filename
        if len(sys.argv) > 4:
            datasetname = sys.argv[4]
        else:
            datasetname = os.path.basename(filename)

        conn = sqlshare.SQLShare(username, password)
        conn.uploadone(filename, datasetname)
def main():
    if len(sys.argv) < 4:
        print usage()
    else:
        username, password = sys.argv[1:3]
        query_name = sys.argv[3]
        new_query_name = None
        table_name = None
        if len(sys.argv) > 4:
            new_query_name = sys.argv[4]

        if len(sys.argv) > 5:
            table_name = sys.argv[5]

        print query_name
        print new_query_name
        print table_name

        conn = sqlshare.SQLShare(username, password)
        print conn.materialize_table(query_name, table_name, new_query_name)
Exemple #6
0
def main():
    parser = OptionParser(
        usage="usage: %prog [options] datasetName <file1> <file2> ... <fileN>")
    parser.add_option('-u',
                      '--user',
                      dest='username',
                      help='SQLshare user name')
    parser.add_option('-p',
                      '--password',
                      dest='password',
                      help='SQLshare password')

    (options, args) = parser.parse_args()

    if len(args) < 2:
        parser.error('not enough number of arguments')

    datasetName = args[0]

    files = []
    for globPattern in args[1:]:
        files.extend(glob.glob(globPattern))

    conn = sqlshare.SQLShare(options.username, options.password)

    # check whether the dataset already exists or not
    datasetExist = conn.table_exists(datasetName)
    start = 0
    if not datasetExist:
        # upload the first file and create the dataset
        print "creating dataset %s and uploading %s" % (datasetName, files[0])
        conn.uploadone(files[0], datasetName)
        start = 1

    for fn in itertools.islice(files, start, None):
        # dataset already exists. force append always
        print "uploading %s and append to %s" % (fn, datasetName)
        conn.uploadone(fn, datasetName, True)
Exemple #7
0
def settags(dataset, tags, username, password):
  conn = sqlshare.SQLShare(username,password)
  success = conn.set_tags(dataset, tags)
  if success: print "tags %s added to dataset %s" % (tags, dataset)
def gettags(dataset, username, password):
    conn = sqlshare.SQLShare(username, password)
    info = conn.get_userinfo()
    schema = info["schema"]
    print conn.get_tags(dataset, schema=schema)
Exemple #9
0
def fetchdata(sql, format, output):
    conn = sqlshare.SQLShare()
    return conn.download_sql_result(sql, format, output)