def getindex(self, dir): index = Path(op.join(datapath, dir, 'index.html')) io = StringIO() if index.exists(): io.write(open(index.absolute).read()) imphist = Path(op.join(datapath, dir, '.import.hist')) if imphist.exists(): io.write('\n') for l in open(imphist.absolute): ls = l.split(',', 3) io.write(' * file:%s/%s imported by user:%s at %s into %s\n' % tuple([imphist.up()] + ls)) return web.markdown(io.getvalue())
def removefile(self, dir, filename): path = Path(op.join(datapath + '/' + dir, filename)) error = '' if path.exists(): try: os.remove(path.absolute) except: error = "Could not delete the file. A good reason would be a mismatch of user rights on the server " \ "file system" else: error = "File not found. Is it already deleted?" if dir == '.' and error == '': return self.index() else: # TODO: Remove this hack raise web.HTTPRedirect("/download/?dir=%s&error=%s" % (dir, error))
def start_action_dialog(self): i1 = self.ui.input_1.currentIndex() i2 = self.ui.input_2.text() include_subfolder = self.ui.side_input_1.isChecked() if i2.strip() == '': return QtWidgets.QMessageBox.warning(self, "Warning", f"<p style=\"font-size: 10pt;\"><b>Error Found.</b> Please, give Output Directory.</p>") i2 = Path(i2) if not (i2.exists() and i2.is_dir()): return QtWidgets.QMessageBox.warning(self, "Warning", f"<p style=\"font-size: 10pt;\"><b>Error Found.</b> Output Directory not exist.</p>") i2 = str(i2) folders = self.FILEDATA.get_all_folders(include_subfolder) data = { 's2': self.ui.side_input_2.isChecked(), 's3': self.ui.side_input_3.isChecked(), 's4': self.ui.side_input_4.text(), 's5': self.ui.side_input_5.text(), 's6': self.ui.side_input_6.text(), 's7': self.ui.side_input_7.text(), 's8': self.ui.side_input_8.isChecked(), 's9': self.ui.side_input_9.isChecked(), 's10': self.ui.side_input_10.text(), 's11': self.ui.side_input_11.text(), 's12': self.ui.side_input_12.text(), 's13': self.ui.side_input_13.text(), } if self.action_dialog == None: self.action_dialog = QtWidgets.QWidget() self.action_dialog.setWindowTitle("Action") self.action_dialog.ui = Ui_ActionDialog() self.action_dialog.ui.setupUi(self.action_dialog) self.action_dialog.setFixedHeight(223) self.action_dialog.setFixedWidth(515) self.action_dialog.ui.progressBar.setMinimum(0) self.action_dialog.ui.pushButton_start.clicked.connect(self.go_for_work) self.action_dialog.ui.pushButton_cancel.clicked.connect(self.action_dialog.close) self.action_dialog.ui.pushButton_finish.clicked.connect(self.action_dialog.close) self.action_dialog.ui.pushButton_start.setEnabled(True) self.action_dialog.ui.pushButton_cancel.setEnabled(True) self.action_dialog.ui.pushButton_finish.setEnabled(False) self.action_dialog.ui.label_desDir.setText(get_prefferd_text(i2)) action = 'Copying :' action_ = 'Copied' if i1 == 1: action = 'Moving :' action_ = 'Moved' self.action_dialog.ui.label_action_going.setText(action) self.action_dialog.ui.label_action.setText(action_) self.action_dialog.ui.stackedWidget.setCurrentIndex(1) self.action_dialog.ui.label_statBar.setText("""<html><body><p align="center"><span style="font-size:18pt;">Click 'Start' to go</span></p></body></html>""") self.action_dialog.ui.label_done.setText("0") self.action_dialog.ui.label_failed.setText("0") self.action_dialog.ui.label_notAllowed.setText("0") self.action_dialog.ui.label_ignored.setText("0") self.action_dialog.ui.progressBar.setValue(0) self.action_dialog.data_data = data self.action_dialog.data_folders = folders self.action_dialog.data_action = i1 self.action_dialog.data_des = i2 self.action_dialog.action_done = 0 self.action_dialog.destroy() self.action_dialog.show()
if len(sys.argv) != 4: print("usage: climateimport.py [newfile.dat] [siteid] [archivefile.dat]") # Get filename for import from cmdline def nowstr(): return datetime.now().strftime('%Y-%m-%d %H:%M') path = Path(sys.argv[1]) i = 0 log('Wait for ' + path.absolute) while not path.exists(): time.sleep(60) i += 1 if i > 20: log('After 20 tries does ' + path.basename + ' not exist', sys.stderr) sys.exit(1) try: # Get siteid from cmdline siteid = int(sys.argv[2]) log('Process settings for ' + path.basename) # Create a TextImport ia = TextImport(path.absolute, 'philipp', siteid) # get the configuration of the text import adapter