Ejemplo n.º 1
0
def uploadShpFile(fpath,
                  userid,
                  productTime=str(time.time()).split('.')[0],
                  name='ssy',
                  description='ssyupload',
                  type='SHP',
                  srId='4326',
                  charset='UTF-8',
                  scale='5w'):
    config.Log.info('begin upload tiff file:%s' % fpath)
    config.Log.info('userid:%s' % userid)
    token = getTokenByuserid(userid)

    if not os.path.exists(fpath):
        return None

    try:
        filename = os.path.splitext(fpath)[0]
        layername = str(uuid.uuid4())[:5]
        dirname = os.path.dirname(filename)
        newfilename = '%s\\%s' % (dirname, layername)

        zfpath = '%s%s' % (newfilename, '.zip')

        zf = zipfile.ZipFile(zfpath, 'w')
        zf.write(fpath, ('%s.shp' % layername))

        for fext in getShpExt():
            fname = '%s%s' % (filename, fext)
            if os.path.exists(fname):
                zf.write(fname, ('%s%s' % (layername, fext)))
        zf.close()

        f = open(zfpath, 'rb')
        rep = requests.post(
            'http://%s%s' %
            (config.SHP_SERVER_HOST, config.SHP_SERVER_UPLOAD_URL),
            data={
                'name': name,
                'description': description,
                'productTime': productTime,
                'type': type,
                'srId': srId,
                'charset': charset,
                'scale': scale,
                'token': token
            },
            files={'file': f})
        message = json.loads(rep.content)
        return message['metadataId']
    except:
        config.Log.info(traceback.format_exc())
        config.Log.info('upload shpfile: %s error' % fpath)
        return None
    finally:
        if zf:
            zf.close()
        if zfpath and os.path.exists(zfpath):
            f.close()
            os.remove(zfpath)
Ejemplo n.º 2
0
def createFile(userid,
               filename,
               parentId,
               metadataId,
               datatype,
               type='0',
               edittype=0):
    try:
        token = getTokenByuserid(userid)
        url = 'http://%s%s' % (config.WEBOS_DIR_HOST, config.WEBOS_MKDIR_URL)
        rep = requests.post(
            url, {
                'token': token,
                'filemanager.Name': filename,
                'filemanager.ParentID': parentId,
                'filemanager.Metadata': metadataId,
                'filemanager.dataType': datatype,
                'filemanager.Type': type,
                'filemanager.editType': edittype
            })
        obj = json.loads(rep.content)
        return obj['item']['items'][0]['id']
    except:
        config.Log.info('parentId = %s, token = %s, filename = %s' %
                        (parentId, token, filename))
        config.Log.info(rep.content)
        config.Log.info(traceback.format_exc())
        raise MsgException(ErrorCode.CreateDirOnWebosFaild,
                           u'create dir on webos failed.')
Ejemplo n.º 3
0
def listDir(userid, dirId):
    try:
        config.Log.info('goto getFavinfoByParentId: parentId=%s' % dirId)
        token = getTokenByuserid(userid)
        config.Log.info(
            'goto getFavinfoByParentId: userid = %s, parentId=%s, token = %s' %
            (userid, dirId, token))
        url = 'http://%s%s' % (config.WEBOS_DIR_HOST, config.WEBOS_LISTDIR_URL)
        rep = requests.post(url, {'token': token, 'parentId': dirId})

        obj = json.loads(rep.content)

        def _isDir(item):
            return item.get('type') == '1'

        return [{
            'id': item.get('id'),
            'path': item.get('name'),
            'type': 'dir' if _isDir(item) else 'file',
            'metadataid': item.get('metadata')
        } for item in obj['item']['items'] or []]
    except:
        config.Log.info(
            '###################token = %s, dirId = %s##############' %
            (token, dirId))
        config.Log.info(traceback.format_exc())
        raise MsgException(ErrorCode.ListDirError, u"get dir list error.")
Ejemplo n.º 4
0
def removeDir(userid, dirid):
    try:
        token = getTokenByuserid(userid)
        url = 'http://%s%s' % (config.WEBOS_DIR_HOST,
                               config.WEBOS_REMOVEDIR_URL)
        rep = requests.post(url, data={'token': token, 'ids': dirid})
    except:
        config.Log.info('dirid = %s' % dirid)
        config.Log.info(traceback.format_exc())
Ejemplo n.º 5
0
def listTaskDir(userid, taskId, userId):
    task = TaskDao.queryTask(taskId, userId)
    if not task:
        return {'code': ErrorCode.NotFindTaskById}
    token = getTokenByuserid(userid)

    def _listDir(dirid):
        ret = []
        dirs = listDir(token, dirid)
        for d in dirs:
            if d['type'] == 'dir':
                ret.append({
                    'type': 'dir',
                    'path': d['path'],
                    'children': _listDir(d['id'])
                })
            elif d['type'] == 'file':
                obj = {'type': 'file', 'path': d['path']}
                ft = checkFileType(d['path'])
                if ft == FileType.TIFF_FILE:
                    obj['url'] = tiffserver.queryWMSUrl(
                        d['metadataid'], userid)
                elif ft == FileType.SHP_FILE:
                    obj['url'] = shpserver.queryWMSUrl(d['metadataid'], userid)
                else:
                    obj['url'] = dataserver.getPreviewUrl(d['metadataid'])
                ret.append(obj)
        return ret

    dirs = listDir(token, task.dir)

    taskState = TaskStateDao.lastTaskState(taskId, userId)
    inputs = None
    outputs = None
    for d in dirs:
        if d['path'] == config.INPUT_DIR_NAME:
            inputs = _listDir(d['id'])
        elif taskState and str(d['id']) == taskState.fsId:
            outputs = _listDir(d['id'])

    return {
        'code':
        ErrorCode.NoError,
        'type':
        'dir',
        'path':
        task.name,
        'children': [{
            'type': 'dir',
            'path': config.INPUT_DIR_NAME,
            'children': inputs or []
        }, {
            'type': 'dir',
            'path': config.OUTPUT_DIR_NAME,
            'children': outputs or []
        }]
    }
Ejemplo n.º 6
0
def querytoken():
    uid = flask.session['uid']
    login_info = LoginInfoDao.queryByuid(uid)
    if login_info:
        userid = login_info.userid
        token = getTokenByuserid(userid)
        if token:
            return flask.jsonify({'token': token, 'code': ErrorCode.NoError})
        else:
            return flask.abort(401)
    else:
        return flask.jsonify({'code': ErrorCode.NotFindUser})
Ejemplo n.º 7
0
def _getQueryParamsByMetedataId(metedataid, userid):
    token = getTokenByuserid(userid)
    rep = requests.post(
        'http://%s%s' %
        (config.METEDATA_HSOT, config.METEDATA_QUERY_BY_METAID),
        data={
            'id': metedataid,
            'token': token
        })
    message = json.loads(rep.content)
    queryParams = json.loads(message['queryParams'])
    uuid = str(queryParams['uuid'])[-10:]
    wkt = str(message['wkt']['wkt'])
    srid = str(message['wkt']['srid'])
    return uuid, wkt, srid
Ejemplo n.º 8
0
def prepareDirOnWebos(userid, username, rootId, flowContent):
    # 创建输入目录
    # def __getUsername():
    #     if 'uid' in flask.session:
    #         return model.logininfo.LoginInfoDao.getUsername(flask.session['uid'])
    #     else:
    #         return ''
    # username = __getUsername()
    token = getTokenByuserid(userid)
    inputdir = webos.createDir(userid, config.INPUT_DIR_NAME, rootId)
    for idir in config.INPUT_DIRS:
        webos.createDir(userid, idir, inputdir)
    prepareOutputDirOnWebos(userid, username, rootId, json.loads(flowContent))

    return ErrorCode.NoError
Ejemplo n.º 9
0
def rename(userid, scjId, newParentId, newName):
    try:
        token = getTokenByuserid(userid)
        url = 'http://%s%s' % (config.WEBOS_DIR_HOST, config.WEBOS_EDITOR_URL)
        rep = requests.post(
            url, {
                'token': token,
                'filemanager.id': scjId,
                'filemanager.ParentID': newParentId,
                'filemanager.Name': newName
            })
        config.Log.info('rename output dir to %s . rep = %s' %
                        (newName, rep.content))
    except:
        config.Log.info(traceback.format_exc())
        raise MsgException(ErrorCode.RenameDirOnWebosFaild,
                           u'rename dir on webos failed.')
Ejemplo n.º 10
0
def uploadModuleJson(taskId, folderId, jsonFileDir, userid, state):
    token = getTokenByuserid(userid)
    jsonFiles = json.load(open(jsonFileDir), encoding='utf-8')
    jsonFiles = json.dumps(jsonFiles)
    rep = requests.post('http://%s%s' %
                        (config.EP_HOST, config.EP_UPLOAD_MODULEJSON_URL),
                        data=json.dumps(
                            {
                                'taskId': taskId,
                                'folderId': folderId,
                                'jsonFiles': jsonFiles,
                                'token': token,
                                'state': state
                            },
                            ensure_ascii=False))
    message = json.loads(rep.content)
    return message['status']
Ejemplo n.º 11
0
def queryWMSUrl(metedataid, userid):
    try:
        token = getTokenByuserid(userid)
        uuid, wkt, srid = _getQueryParamsByMetedataId(metedataid, userid)
        rep = requests.post('http://%s%s' %
                            (config.SHP_SERVER_HOST, config.SHP_WMS_URL),
                            data={
                                'token': token,
                                'grouplayerUuidLast10': uuid,
                                'wkt': wkt,
                                'width': '200',
                                'height': '200',
                                'srId': srid
                            })
        return rep.content
    except:
        config.Log.info(traceback.format_exc())
        config.Log.info("can't get shp wms url, metadataid = %s" % metedataid)
        return None
Ejemplo n.º 12
0
def prepareOutputDirOnWebos(userid, username, rootId,  flowObj):
    # 创建输出目录
    # def __getUsername():
    #     if 'uid' in flask.session:
    #         return model.logininfo.LoginInfoDao.getUsername(flask.session['uid'])
    #     else:
    #         return ''
    # username = __getUsername()
    token = getTokenByuserid(userid)
    outputdir = webos.createDir(userid, config.OUTPUT_DIR_NAME, rootId)
    # outputdir = webos.createDir(config.OUTPUT_DIR_NAME, rootId, classify = classify)

    # modules = flowObj.get('modules')
    # if not modules:
    #     return ErrorCode.NoModulesInFlow
    # for module in modules:
    #     name = module.get('name')
    #     if name:
    #         webos.createDir(name, outputdir, classify = classify)
    return outputdir
Ejemplo n.º 13
0
def listInputOutputDir(userid, taskId, userId):
    token = getTokenByuserid(userid)
    task = TaskDao.queryTask(taskId, userId)
    inputid = None
    outputid = None
    inputname = None
    outputname = None
    if not task:
        return {'code': ErrorCode.NotFindTaskById}
    dirs = listDir(userid, task.dir)
    taskState = TaskStateDao.lastTaskState(taskId, userId)
    for d in dirs:
        if d['path'] == config.INPUT_DIR_NAME:
            inputid = d['id']
            inputname = d['path']

        elif taskState and str(d['id']) == taskState.fsId:
            outputid = d['id']
            outputname = d['path']
    return {
        'code':
        ErrorCode.NoError,
        'type':
        'dir',
        'path':
        task.name,
        'children': [{
            'type': 'dir',
            'path': inputname,
            'id': inputid,
            'children': []
        }, {
            'type': 'dir',
            'path': outputname,
            'id': outputid,
            'children': []
        }]
    }
Ejemplo n.º 14
0
# coding: utf-8

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

from taskserver.log import Log
from common import webos
import config
import time
from common.userserver import getTokenByuserid

# 注册log模块
config.Log = Log
token = getTokenByuserid()
dirname = time.strftime('%Y%m%d%H%M%S')
dirid = webos.createDir(
    'Koqx+SdW7dgnuikcLmWQtjZ5OuQivSHXiOA/xBwndnPLx8Ze9r5p/ehXHjJZLHIrnFXZxSb+/Y9ApAnBwr+UKQD1c6wNfBNkqyqDGTTgq9u+soGx0R8QCUsjGC4CUyJs+ZqHNikcGy4/JeCbcmx757puWns8/j7zu3t0hN0u+uc=',
    'ssy', 'cehuiZY3-14hh39mmxian', '-2')
print dirid
webos.uploadDir(
    'Koqx+SdW7dgnuikcLmWQtjZ5OuQivSHXiOA/xBwndnPLx8Ze9r5p/ehXHjJZLHIrnFXZxSb+/Y9ApAnBwr+UKQD1c6wNfBNkqyqDGTTgq9u+soGx0R8QCUsjGC4CUyJs+ZqHNikcGy4/JeCbcmx757puWns8/j7zu3t0hN0u+uc=',
    dirid, 'ssy', u'/mnt/mfs-cli/cehuiData/ZY3/input')
config.Log.info('dirname is: %s' % dirname)
Ejemplo n.º 15
0
def findResource(userid, parentId, resName):
    token = getTokenByuserid(userid)
    for d in listDir(token, parentId):
        if d['path'] == resName:
            return d
    return None