예제 #1
0
  def __init__( self, master, dataStream ):
    Menu.__init__( self, master=master )
    master.config(menu=self)

    self.logger = logging(
        dataStream['sysArgs']['hostPath'], __name__ + '.Menu'
        )
    self.logger.info(
        '.__init__(master=%s, dataStream=%s)'
        % (repr(master), repr(dataStream))
        )

    try:
      image_path = os.path.join(
          dataStream['sysArgs']['hostPath'], "icons", "dirs.jpg"
          )
      image_path = PathSwitch( image_path )
      icon_dirs = Image.open(image_path)
      self.icon_dirs = ImageTk.PhotoImage(icon_dirs)
    except IOError:
        self.logger.error( "003: icon_dirs: %s" % repr(image_path) )
        raise WidgetError( 3, "icon_dirs: %s" % repr(image_path) )

    self.dataStream = dataStream
    self.master = master
예제 #2
0
  def __init__( self, master, dataStream ):
    Frame.__init__(self, master)

    self.dataStream = dataStream

    self.logger = logging(
        self.dataStream['sysArgs']['hostPath'], __name__ + '.Toolbar'
        )
    self.logger.info(
        ".__init__(master=%s, dataStream=%s)"
        % (repr(master), repr(dataStream))
        )

    # check the icons
    iconsPath = os.path.join(
        self.dataStream['sysArgs']['hostPath'], 'icons'
        )
    if not os.path.isdir(iconsPath):
      self.logger.error( '101:not found iconsPath: %s' % repr(iconsPath) )
      raise WidgetError( 101, 'not found iconsPath: %s' % repr(iconsPath) )

    try:
      icon_left = Image.open(os.path.join(iconsPath, 'left.jpg'))
      icon_right = Image.open(os.path.join(iconsPath, 'right.jpg'))
      icon_up = Image.open(os.path.join(iconsPath, 'up.jpg'))
      icon_down =  Image.open(os.path.join(iconsPath, 'down.jpg'))
    except IOError, e:
      self.logger.error( '102:icon file error: %s' % repr(e) )
      raise WidgetError( 102, 'icon file error: %s' % repr(e) )
예제 #3
0
  def __init__( self, master, dataStream ):
    Frame.__init__(self, master)
    self.logger = logging(
        dataStream['sysArgs']['hostPath'], __name__ + '.ArgsCheckBar'
        )

    self.logger.info(
        '.__init__(master=%s, dataStream=%s)' % (repr(master), repr(dataStream))
        )

    self.dataStream = dataStream
예제 #4
0
  def __init__( self, master ):
    Frame.__init__(self, master)
    self.logger = logging( os.path.abspath('.'), __name__ + '.ArgsCheckBar' )
    self.logger.info( '.__inti__(master=%s)' % repr(master) )

    #self.transient(master)
    #self.title('参数设定')
    #self.minsize(70, 150)
    #self.resizable(False, False)

    self.selectArgs = {
        'year': 1998, 'month': 2, 'day': 1, 'time': 0, \
        'lev': 500, 'lat': (0, 90), 'lon': (30, 180), \
        # physicial args flag
        'tt': 0, 'high': 0, 'wind': 0, 'rh': 0, \
        }
예제 #5
0
    def __init__(self, master):
        Frame.__init__(self, master)
        self.logger = logging(os.path.abspath('.'), __name__ + '.ArgsCheckBar')
        self.logger.info('.__inti__(master=%s)' % repr(master))

        #self.transient(master)
        #self.title('参数设定')
        #self.minsize(70, 150)
        #self.resizable(False, False)

        self.selectArgs = {
            'year': 1998, 'month': 2, 'day': 1, 'time': 0, \
            'lev': 500, 'lat': (0, 90), 'lon': (30, 180), \
        # physicial args flag

            'tt': 0, 'high': 0, 'wind': 0, 'rh': 0, \
            }
예제 #6
0
  def __init__( self, master, dataStream ):
    Frame.__init__(self, master)

    self.logger = logging(
        dataStream['sysArgs']['hostPath'], __name__ + '.FileList'
        )

    self.logger.info(
        '.__init__(master=%s, dataStream=%s)'
        % (repr(master), repr(dataStream))
        )

    self.dataStream = dataStream

    frame_top = Frame(self)
    frame_up = Frame(self)
    frame_down = Frame(self)

    frame_top.pack(fill=BOTH)
    frame_up.pack(expand=True, fill=BOTH)
    frame_down.pack(fill=BOTH)

    label = Label(
        frame_top, text='-------------操作历史-------------',
        fg='brown'
        ).pack(fill=BOTH)
    listbox = Listbox(frame_up)
    scroll_x = Scrollbar(frame_down)
    scroll_y = Scrollbar(frame_up)

    listbox.config(xscrollcommand=scroll_x.set)
    listbox.config(yscrollcommand=scroll_y.set)
    scroll_x.config(command=listbox.xview, orient=HORIZONTAL)
    scroll_y.config(command=listbox.yview)

    listbox.pack(side=LEFT, expand=True, fill=BOTH)
    scroll_y.pack(side=RIGHT, fill=BOTH)
    scroll_x.pack(fill=BOTH)

    listVar = self.dataStream['posterStatus']['fileList'][1]
    listbox.config(listvariable=listVar)
    listbox.bind('<Double-Button-1>', self._FileClick)

    self.listbox = listbox
예제 #7
0
  def __init__( self, master, dataStream ):
    Canvas.__init__(self, master)

    self.dataStream = dataStream
    self.master = master

    self.logger = logging(
        dataStream['sysArgs']['hostPath'], __name__ + '.PosterBoard'
        )
    self.logger.info(
        '.__init__(master=%s, dataStream=%s)' % (repr(master), repr(dataStream))
        )

    self.config(bd=0, highlightbackground='#435066', highlightthickness=1,
                bg='#363636')

    back_ground_path = os.path.join(
        dataStream['sysArgs']['hostPath'], 'icons', 'background.jpg'
        )
    back_ground_path = PathSwitch( back_ground_path )
    if not os.path.isfile(back_ground_path):
      self.logger.error(
          "203:back_ground_path not found: %s" % back_ground_path
          )
      raise WidgetError(
          203, "back_ground_path not found: %s" % back_ground_path
          )

    height = self.winfo_height()
    width = self.winfo_width()

    back_ground_img = Image.open(back_ground_path)
    self.dataStream['posterStatus']['posterAlbum']['back'][1] = back_ground_img

    back_ground_img = back_ground_img.copy()
    back_ground_img = back_ground_img.resize((width, height))
    back_ground_pic = ImageTk.PhotoImage(back_ground_img)
    self.dataStream['posterStatus']['posterAlbum']['back'][0] = back_ground_pic

    img_id = self.create_image(width/2, height/2, image=back_ground_pic)
    self.dataStream['posterStatus']['posterAlbum']['back'][2] = img_id
    self.bind('<Configure>', self._Resize)
예제 #8
0
    def __init__(self, master):

        # host path
        pwd = os.path.dirname(sys.executable)
        # pwd = os.path.abspath(os.getcwd())

        self.root = master

        position = [
            self.root.winfo_screenwidth(),
            self.root.winfo_screenheight()
        ]
        position = [int(position[0] / 2. - 512), int(position[1] / 2. - 340)]
        size = [1024, 630]
        self.root.geometry("%sx%s+%s+%s" %
                           (size[0], size[1], position[0], position[1]))
        self.root.state('zoomed')
        self.root.title('NCEP历史资料查询平台')

        self.dataStream = {
            # physical argument
            'phyArgs': {
                'year': [1998, IntVar()],
                'month': [2, IntVar()],
                'day': [1, IntVar()],
                'time': ['00', StringVar()],
                'high': ['500 ', StringVar()],
                'lon_fr': [30, IntVar()],
                'lon_to': [180, IntVar()],
                'lat_fr': [0, IntVar()],
                'lat_to': [90, IntVar()],
                'historia': ['刷新', StringVar()],
                'multi': ['500 高度 & 850h uv & rh',
                          StringVar()],
                # makegs.py should update:_ArgSwitch & _SdfOpen
                # Widgets.py should update: _DrawCanvas.arg_change
                'args': [
                    StringVar(),
                    [[
                        '高度', '温度', '相对湿度', '风场', 'sfcg', 'sfci', 'lftx',
                        'prwtr', 'shum', 'slp'
                    ],
                     [
                         '500 高度 & 850h uv & rh', '700 风场 & 700 相对湿度',
                         '850 风场 & 850 相对湿度', '500 高度 & 850 温度    '
                     ]]
                ],
                'surf_args': [
                    '高度',
                    '温度',
                    '相对湿度',
                    '风场',
                    '地面气压',
                    '抬升指数',
                    '水汽含量',
                    '海平面气压',
                ],
                'high_args': ['高度', '温度', '相对湿度', '风场', '绝对湿度'],
                'whether_historia': [0, IntVar()],
                'whether_custom': [0, IntVar()],
            },
            'sysArgs': {
                'hostPath': pwd,
                'gsFilePath': os.path.join(pwd, 'gsfile.gs'),
                'gsExecPath': r'X:\GrADS19\win32\grads.exe',
                'gsDataPath': 'X:\\',
                'gsDocPath': os.path.join(pwd, 'images'),
                'maxDocSize': 2.0,
                'argDataFile': os.path.join(pwd, 'arg_data.dat'),
            },
            'posterStatus': {
                'posterAlbum': {
                    'main': ['', '', -1],
                    'back': ['', '', -1]
                },
                'hintInfo': ['', StringVar()],
                'img_name': '',
                'fileList': ['', StringVar()],
            },
            'historia': {
                'histexts_win': False,
                'root': self.root,
            }
        }
        self.dataStream = dataStream(self.dataStream)

        #TODO example historic data
        self.hisTexts = {}
        if os.path.isfile(os.path.join(pwd, 'historia.dat')):
            self.hisTexts = pickle.load(
                open(os.path.join(pwd, 'historia.dat'), 'rb'))['total']

        self.logger = logging(self.dataStream['sysArgs']['hostPath'], __name__)
        self.logger.info('__init__()')

        # initiall the dataStream
        try:
            self.dataStream.load()
        except IOError:
            pass

        self.logger.debug(repr(self.dataStream))
예제 #9
0
  def __init__( self, master ):

    # host path
    pwd = os.path.dirname(sys.executable)
    # pwd = os.path.abspath(os.getcwd())

    self.root = master

    position = [self.root.winfo_screenwidth(), self.root.winfo_screenheight()]
    position = [int(position[0]/2.-512), int(position[1]/2.-340)]
    size = [1024, 630]
    self.root.geometry(
        "%sx%s+%s+%s"
        % (size[0], size[1], position[0], position[1])
        )
    self.root.state('zoomed')
    self.root.title('NCEP历史资料查询平台')

    self.dataStream = {
        # physical argument
        'phyArgs': {
            'year': [1998, IntVar()], 'month': [2, IntVar()],
            'day': [1, IntVar()], 'time': ['00', StringVar()],
            'high': ['500 ', StringVar()],
            'lon_fr': [30, IntVar()], 'lon_to': [180, IntVar()],
            'lat_fr': [0, IntVar()], 'lat_to': [90, IntVar()],
            'historia': ['刷新', StringVar()],
            'multi': ['500 高度 & 850h uv & rh', StringVar()],
            # makegs.py should update:_ArgSwitch & _SdfOpen
            # Widgets.py should update: _DrawCanvas.arg_change
            'args': [StringVar(), [['高度', '温度', '相对湿度', '风场', 'sfcg', 'sfci',
                                    'lftx', 'prwtr', 'shum', 'slp'],
                                  ['500 高度 & 850h uv & rh',
                                   '700 风场 & 700 相对湿度',
                                   '850 风场 & 850 相对湿度',
                                   '500 高度 & 850 温度    ']]],
            'surf_args': ['高度', '温度', '相对湿度', '风场', '地面气压', '抬升指数',
                          '水汽含量', '海平面气压',],
            'high_args': ['高度', '温度', '相对湿度', '风场', '绝对湿度'],
            'whether_historia': [0, IntVar()],
            'whether_custom': [0, IntVar()],
            },
        'sysArgs': {
            'hostPath': pwd,
            'gsFilePath': os.path.join(pwd, 'gsfile.gs'),
            'gsExecPath': r'X:\GrADS19\win32\grads.exe',
            'gsDataPath': 'X:\\',
            'gsDocPath': os.path.join(pwd, 'images'),
            'maxDocSize': 2.0,
            'argDataFile': os.path.join(pwd, 'arg_data.dat'),
            },
        'posterStatus': {
            'posterAlbum': {'main': ['', '', -1], 'back': ['', '', -1]},
            'hintInfo': ['', StringVar()],
            'img_name': '',
            'fileList': ['', StringVar()],
            },
        'historia':{
            'histexts_win': False,
            'root': self.root,
            }
        }
    self.dataStream = dataStream(self.dataStream)

    #TODO example historic data
    self.hisTexts = {}
    if os.path.isfile(os.path.join(pwd, 'historia.dat')):
      self.hisTexts = pickle.load(
          open(os.path.join(pwd, 'historia.dat'), 'rb')
          )['total']

    self.logger = logging(
        self.dataStream['sysArgs']['hostPath'], __name__
        )
    self.logger.info( '__init__()' )

    # initiall the dataStream
    try:
      self.dataStream.load()
    except IOError:
      pass

    self.logger.debug( repr(self.dataStream) )
예제 #10
0
    def __init__(
        self,
        gsFilePath=None,
        dataDocPath=None,
        imagePath=None,
        gradsExecPath=None,
        lat=(0, 90),
        lon=(30, 180),
        lev=500,
        timeRange=(datetime.datetime(1998, 3, 1, 0, 0, 0),
                   datetime.datetime(1998, 3, 1, 0, 0, 0)),
    ):
        """
    make a .gs file
    """

        self.logger = logging(
            os.path.abspath(os.getcwd()),
            __name__ + '.Make',
            # disabled=True
        )

        self.logger.info('.__init__(gsFilePath=%s, dataDocPath=%s, '
                         'imagePath=%s, gradsExecPath=%s, '
                         'lat=%s, lon=%s, '
                         'lev=%s, '
                         'timeRange=%s' %
                         (repr(gsFilePath), repr(dataDocPath), repr(imagePath),
                          repr(gradsExecPath), repr(lat), repr(lon), repr(lev),
                          repr(timeRange)))
        if gsFilePath:
            gs_file_path = PathSwitch(gsFilePath)
        else:
            gs_file_path = None
        if dataDocPath:
            data_file_path = PathSwitch(dataDocPath)
        else:
            data_file_path = None
        if imagePath:
            image_path = PathSwitch(imagePath)
        else:
            image_path = None

        if data_file_path:
            if not os.path.isfile(data_file_path):
                self.logger.error('001: data_file_path: %s' %
                                  repr(data_file_path))
                raise makegsError(001,
                                  'data_file_path: %s' % repr(data_file_path))

        if gs_file_path:
            gs_doc_path = os.path.split(gs_file_path)[0]
            if not os.path.exists(gs_doc_path):
                self.logger.error('002: gs_file_path: %s' % repr(gs_doc_path))
                raise makegsError(002, 'gs_file_path: %s' % repr(gs_doc_path))

        if image_path:
            if not os.path.isdir(os.path.dirname(image_path)):
                self.logger.error('004: image_path: %s' % repr(image_path))
                raise makegsError(004, 'image_path: %s' % repr(image_path))

        if gradsExecPath:
            if not os.path.isfile(gradsExecPath):
                self.logger.error('005: gradsExecPath: %s' %
                                  repr(gradsExecPath))
                raise makegsError(005,
                                  'gradsExecPath: %s' % repr(gradsExecPath))

        time_range = ['', '']
        time_range[0] = self.Datatime2Grads(timeRange[0])
        time_range[1] = self.Datatime2Grads(timeRange[1])

        self.parameter = {
            'gs_file_path': gs_file_path,
            'data_file_path': data_file_path,
            'lat': lat,
            'lon': lon,
            'lev': lev,
            'time_range': time_range,
            'image_path': imagePath,
            'grads_path': gradsExecPath,
            'whether_cint': True,
            'title': '',
            'whether_multi': False,
            'single_arg': '',
            'multi_arg': '',
            'date_time': ['', '', '', ''],
        }
예제 #11
0
  def __init__( self, port=10338, bufsize=10340 ):
    """
    create a host server
    """
    self.args = {
        'hostPort': port, \
        'bufSize': bufsize, \
        'sockDict': {}, \
        'clientDict': {}, \
        'threadDict': {}, \
        'tokenDict': {}, \
        }

    self.logger = logging( os.path.abspath(os.curdir), 'SelectServer' )

    self.args['hostSock'] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.args['hostsock'].setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    self.args['hostSock'].bind(("", port))
    self.args['hostSock'].listen(5)

    self.args['sockDict'].update({hostSock: ''})
    self.logger.debug( self.args )

    def Run( self ):
      """
      start the server
      """

      while True:
        (sread, swrite, sexc) = select.select(
            self.args['sockDict'].keys(), [], [], 0
            )

        for sock in sread:
          if sock == self.args['hostSock']:
            new_sock, (remhost, remport) = self.args['hostSock'].accept()
            new_sock.settimeout(15)
            host, port = new_sock.getpeername()
            self.logger.info(
                'accept new connection from\t%s:%s\t' % (host, port)
                )
            try:
              self.NewConnection( new_sock )
            except: continue
          else: continue

    def Collector( self, sock ):
      """
      delete a ClientInServer instance and collect the rem
      """
      #TODO
 
    def CreateClient( self, sock ):
      #TODO create a client instance

    def NewConnection( self, sock ):
      """
      accept a new connection from a client
        check its id and password, 
        create a identify toke
        assign disk room and create a .gs file
        create a ClientInServer instance
      """
      count = 0
      addr, port = sock.getpeername()

      while count < 10:
        try: 
          data = sock.recv( 10340 )
        except Exception, e:
          self.logger.error( 'create a NewConnection error: %s' % repr(e))
          count += 1
          continue

        if not data: 
          count += 1
          continue

        token, temp1, the_type, temp2, content = \
            struct.unpack(Utf( '32s2s64s2s10240s' ), data)
        if the_type.strip('\x00').decode('utf-8') != 'verify':
          count += 1
          continue

        # default ID and password is qxt@dqyb188
        content = content.decode('utf-8').strip('\x00')
        user_name, passwd = content.split('@')
        if user_name != 'qxt' or passwd != 'dqyb188':
          self.logger.info( 
              'verify error! user_name: %s, passwd: %s' % (user_name, passwd)
              )
          sock.close()
          return None
        else:
          self.logger.info(
              'user: %s is log in' % user_name)
          
          while True:
            new_token = RandomChar( 32 )
            if new_token in self.args['tokenDict'].keys(): continue

          verify_back = struck.pack(
              Utf( '32s2s64s2s10240s' ), \
              Utf( new_token ), Utf( ?? ), Utf( 'new_token' ), \
              Utf( '??' ), Utf( new_token )
              )

        send_count = 0
        while send_count <= 3:
          try:
            sock.send(verify_back)
            break
          except Exception, e:
            send_count += 1
            self.logger.error( 'send verify_back message error: %s' % e )
            continue

        if send_count > 3: break

        dirs = os.path.abspath(os.curdir)
       
        new_doc = os.path.join(dirs, new_token)
        new_doc = PathSwitch( new_doc )
        try:
          os.makedirs(new_doc)
        except Exception, e:
          sock.close()
          self.logger.error( 'failed to create a new doc: %s' % new_doc)
          raise ServerError( 001, 'failed to create a new doc: %s' % new_doc )

        try: #TODO
          new_gs = makegs.Make(
              gsFilePath=r'E:\laisky\dropbox\Dropbox\Backup\codeSource\qxt\201211_01_NCEP-displayer\test.gs', \
              dataFilePath=r'X:\pressure\air.1998.nc', \
              resultPath=r'E:\laisky\dropbox\Dropbox\Backup\codeSource\qxt\201211_01_NCEP-displayer\res', \
              gradsExecPath = r'X:\GrADS19\win32\grads.exe'
              )
        except Exception, e:
          sock.close()
          self.logger.error( 'failed to create a makegs instance' )
          raise ServerError( 002, 'failed to create a makegs instance' )
예제 #12
0
  def __init__(
      self,
      gsFilePath=None, dataDocPath=None,
      imagePath=None, gradsExecPath=None,
      lat = (0, 90), lon = (30, 180),
      lev = 500,
      timeRange = ( datetime.datetime( 1998, 3, 1, 0, 0, 0 ),
                    datetime.datetime( 1998, 3, 1, 0, 0, 0 ) ),
      ):
    """
    make a .gs file
    """

    self.logger = logging(
        os.path.abspath(os.getcwd()), __name__ + '.Make',
        # disabled=True
        )

    self.logger.info(
        '.__init__(gsFilePath=%s, dataDocPath=%s, '
        'imagePath=%s, gradsExecPath=%s, '
        'lat=%s, lon=%s, '
        'lev=%s, '
        'timeRange=%s'
        % (repr(gsFilePath), repr(dataDocPath),
           repr(imagePath), repr(gradsExecPath),
           repr(lat), repr(lon), repr(lev),
           repr(timeRange))
        )
    if gsFilePath:
      gs_file_path = PathSwitch( gsFilePath )
    else: gs_file_path = None
    if dataDocPath:
      data_file_path = PathSwitch( dataDocPath )
    else: data_file_path = None
    if imagePath:
      image_path = PathSwitch( imagePath )
    else: image_path = None

    if data_file_path:
      if not os.path.isfile( data_file_path ):
        self.logger.error( '001: data_file_path: %s' % repr( data_file_path ) )
        raise makegsError( 001, 'data_file_path: %s' % repr( data_file_path ) )

    if gs_file_path:
      gs_doc_path = os.path.split( gs_file_path )[0]
      if not os.path.exists( gs_doc_path ):
        self.logger.error( '002: gs_file_path: %s' % repr( gs_doc_path ) )
        raise makegsError( 002, 'gs_file_path: %s' % repr( gs_doc_path ) )

    if image_path:
      if not os.path.isdir( os.path.dirname(image_path) ):
        self.logger.error( '004: image_path: %s' % repr( image_path ) )
        raise makegsError( 004, 'image_path: %s' % repr( image_path ) )

    if gradsExecPath:
      if not os.path.isfile( gradsExecPath ):
        self.logger.error( '005: gradsExecPath: %s' % repr( gradsExecPath ) )
        raise makegsError( 005, 'gradsExecPath: %s' % repr( gradsExecPath ) )

    time_range = ['', '']
    time_range[0] = self.Datatime2Grads( timeRange[0] )
    time_range[1] = self.Datatime2Grads( timeRange[1] )

    self.parameter = {
        'gs_file_path': gs_file_path,
        'data_file_path': data_file_path,
        'lat': lat, 'lon': lon,
        'lev': lev,
        'time_range': time_range,
        'image_path': imagePath,
        'grads_path': gradsExecPath,
        'whether_cint': True,
        'title': '',
        'whether_multi': False,
        'single_arg': '',
        'multi_arg': '',
        'date_time': ['', '', '', ''],
        }