def download(self, src, tar): '''read a file in data lake and download it to local machine. src : the file path inside data lake/bucket. tar : file path in our local machine. Directories must exist. ''' try: if self.on_cloud: GCS.download_blob(self.bucket, src, tar) else: file_path = join(self.local_dir, src) copy(file_path, tar) except Exception as e: print('DataLakeConnector.download(), error: {}'.format(e))
def upload_from_file(self, src, tar): '''upload a file to data lake src : source file path tar : target file path, in data lake. ''' try: if self.on_cloud: GCS.upload_blob(self.bucket, src, tar) else: file_path = join(self.local_dir, tar) copy(src, file_path) except Exception as e: print('DataLakeConnector.upload_from_file(), error: {}'.format(e))
def upload_from_dict(self, src, tar): '''read a Dictionary and upload as a file in data lake. src : is a Dictionary tar : the file path inside data lake/bucket. ''' try: if self.on_cloud: s = json.dumps(src) GCS.upload_blob_from_string(self.bucket, s, tar) else: file_path = join(self.local_dir, tar) with open(file_path, 'w') as f: json.dump(src, f) except Exception as e: print('DataLakeConnector.upload_from_dict(), error: {}'.format(e))
def initGCS(self): self.GCS = GCS() x1 = XPlane.XPlane('131.204.27.9', 49005, '131.204.27.8', 49000,self.GCS,0) a1 = ArduPilot.ArduPilot('/dev/ttyUSB0',38400,self.GCS,0) self.GCS.addPair(a1,x1) x1.execute() a1.execute()
def upload_from_string(self, src, tar): '''read a string and upload as a file in data lake. src : is a string tar : the file path inside data lake/bucket. ''' try: if self.on_cloud: GCS.upload_blob_from_string(self.bucket, src, tar) else: file_path = join(self.local_dir, tar) with open(file_path, 'w') as f: f.write(src) except Exception as e: print( 'DataLakeConnector.upload_from_string(), error: {}'.format(e))
def download_as_string(self, src): '''read a file in data lake and download it to local machine. src : the file path inside data lake/bucket. tar : file path in our local machine. Directories must exist. ''' try: s = None if self.on_cloud: s = GCS.get_str_from_blob(self.bucket, src) else: file_path = join(self.local_dir, src) with open(file_path, 'r') as reader: s = reader.read() return s except Exception as e: print( 'DataLakeConnector.download_as_string(), error: {}'.format(e))
class Ui_MainWindow(object): def initGCS(self): self.GCS = GCS() x1 = XPlane.XPlane('131.204.27.9', 49005, '131.204.27.8', 49000, self.GCS, 0) a1 = ArduPilot.ArduPilot('/dev/ttyUSB0', 38400, self.GCS, 0) self.GCS.addPair(a1, x1) x1.execute() a1.execute() def writeNextWaypoint(self): # Write the GPS Waypoint lat = float(self.latTextBox.text()) lng = float(self.lngTextBox.text()) alt = float(self.altTextBox.text()) goal = ( lat, lng, alt, ) self.GCS.ID_to_ardu[0].setGoal(goal) def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(800, 600) MainWindow.setWindowTitle( QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8)) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.mapWebKit = QtWebKit.QWebView(self.centralwidget) self.mapWebKit.setGeometry(QtCore.QRect(389, 0, 411, 561)) self.mapWebKit.setUrl(QtCore.QUrl(_fromUtf8("about:blank"))) self.mapWebKit.setObjectName(_fromUtf8("mapWebKit")) self.writeNextWaypointButton = QtGui.QPushButton(self.centralwidget) self.writeNextWaypointButton.setGeometry( QtCore.QRect(219, 520, 151, 26)) self.writeNextWaypointButton.setText( QtGui.QApplication.translate("MainWindow", "write next waypoint", None, QtGui.QApplication.UnicodeUTF8)) self.writeNextWaypointButton.setObjectName( _fromUtf8("writeNextWaypointButton")) QtCore.QObject.connect(self.writeNextWaypointButton, QtCore.SIGNAL("clicked()"), self.writeNextWaypoint) self.line = QtGui.QFrame(self.centralwidget) self.line.setGeometry(QtCore.QRect(370, 0, 20, 551)) self.line.setFrameShape(QtGui.QFrame.VLine) self.line.setFrameShadow(QtGui.QFrame.Sunken) self.line.setObjectName(_fromUtf8("line")) self.latTextBox = QtGui.QLineEdit(self.centralwidget) self.latTextBox.setGeometry(QtCore.QRect(260, 430, 113, 25)) self.latTextBox.setObjectName(_fromUtf8("latTextBox")) self.lngTextBox = QtGui.QLineEdit(self.centralwidget) self.lngTextBox.setGeometry(QtCore.QRect(260, 460, 113, 25)) self.lngTextBox.setObjectName(_fromUtf8("lngTextBox")) self.altTextBox = QtGui.QLineEdit(self.centralwidget) self.altTextBox.setGeometry(QtCore.QRect(260, 490, 113, 25)) self.altTextBox.setObjectName(_fromUtf8("altTextBox")) self.latLabel = QtGui.QLabel(self.centralwidget) self.latLabel.setGeometry(QtCore.QRect(200, 440, 57, 15)) self.latLabel.setText( QtGui.QApplication.translate("MainWindow", "lat:", None, QtGui.QApplication.UnicodeUTF8)) self.latLabel.setObjectName(_fromUtf8("latLabel")) self.lngLabel = QtGui.QLabel(self.centralwidget) self.lngLabel.setGeometry(QtCore.QRect(200, 460, 57, 15)) self.lngLabel.setText( QtGui.QApplication.translate("MainWindow", "lng:", None, QtGui.QApplication.UnicodeUTF8)) self.lngLabel.setObjectName(_fromUtf8("lngLabel")) self.altLabel = QtGui.QLabel(self.centralwidget) self.altLabel.setGeometry(QtCore.QRect(200, 490, 57, 15)) self.altLabel.setText( QtGui.QApplication.translate("MainWindow", "alt:", None, QtGui.QApplication.UnicodeUTF8)) self.altLabel.setObjectName(_fromUtf8("altLabel")) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23)) self.menubar.setObjectName(_fromUtf8("menubar")) MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): pass