コード例 #1
0
    def __init__(self, plugin, window):
        """
        Window handle setting up the database and file system monitor.
        """
        # defaults
        self._root = "."

        # Setup
        self._window = window
        self._plugin = plugin
        self._message_bus = self._window.get_message_bus()

        self._db = DBWrapper()
        self._monitor = None

        self._message_bus.connect('/plugins/filebrowser', 'root_changed',
                                  self.root_changed)
コード例 #2
0
ファイル: __init__.py プロジェクト: Dimama/flask-demo
def create_app():
    app = Flask(__name__)

    with app.app_context():
        current_app.db_wrapper = DBWrapper(DB_HOST, DB_PORT, DATABASE, DB_USER,
                                           DB_PASSWORD)

    api = Api(app)
    api.add_resource(Stub, '/stub')
    api.add_resource(Artist, '/artist', '/artist/<int:artist_id>')
    api.add_resource(Track, '/track', '/track/<int:track_id>')

    return app
コード例 #3
0
    def __init__(self, plugin, window):
        """
        Window handle setting up the database and file system monitor.
        """
        # defaults
        self._root = "."

        # Setup
        self._window = window
        self._plugin = plugin
        self._message_bus = self._window.get_message_bus()

        self._db = DBWrapper()
        self._monitor = None

        self._message_bus.connect('/plugins/filebrowser', 'root_changed', self.root_changed)
コード例 #4
0
def create_app():
    app = Flask(__name__)

    _ = CORS(app, resources={r"*": {"origins": "*"}})

    with app.app_context():
        current_app.db_wrapper = DBWrapper(environ['DB_HOST'],
                                           environ['DB_PORT'],
                                           environ['DATABASE'],
                                           environ['DB_USER'],
                                           environ['DB_PASSWORD'])

    api = Api(app)
    api.add_resource(Patient, "/patient")
    api.add_resource(Report, "/report")
    return app
コード例 #5
0
class FilesystemSearcher(object):
    """
    Public API to be used by the UI to ask for files.

    TODO: Do we want to include hidden files should ask the file browserstop
    """
    def __init__(self, plugin, window):
        """
        Window handle setting up the database and file system monitor.
        """
        # defaults
        self._root = "."

        # Setup
        self._window = window
        self._plugin = plugin
        self._message_bus = self._window.get_message_bus()

        self._db = DBWrapper()
        self._monitor = None

        self._message_bus.connect('/plugins/filebrowser', 'root_changed',
                                  self.root_changed)

    def root_changed(self, *args, **kwargs):
        root = kwargs.get('root', None)
        previous_root = self._root

        if not root:
            if len(args) == 2:
                msg = args[1]
                root = self._get_uri_from_msg(msg)
        self._root = root.replace("file://", "")  # FIXME: HACK

        if not self._monitor:
            self._monitor = FilesystemMonitor(self)
        self._monitor.change_root(previous_root)

        log.debug("changing root from %s -> %s" % (previous_root, self._root))

    @property
    def current_root(self):
        """
        Returns the current root location of the window.
        """
        if self.configuration.use_filebrowser:
            return urllib.unquote(self._root)
        else:
            return urllib.unquote(self.configuration.static_root_path)

    @property
    def filebrowser_current_root(self):
        return self._get_uri_from_msg(
            self._message_bus.send_sync('/plugins/filebrowser', 'get_root'))

    @property
    def configuration(self):
        return self._plugin._configuration

    def add_file(self, path, file_name):
        self._db.add_file(path, file_name)

    def remove_directory(self, path):
        self._db.remove_directory(path)

    def remove_file(self, path, name):
        self._db.remove_file(path, name)

    def increment_uri_open_count(self, uri):
        self._db.increment_file_open_count(uri.replace("file://", ""))

    def clear_database(self):
        self._db.clear_database()

    def build_exclude_list(self):
        self._monitor._build_exclude_list()

    def search(self, input):
        query = self.current_root + "%" + input
        filewrappers = []
        for row in self._db.search(query):
            # FIXME: Set data in variables so you can tell what data is returned.
            filewrappers.append(
                FileWrapper(input, self.current_root, row[0], row[1]))
        return filewrappers

    def cleanup(self):
        if self._monitor:
            self._monitor.finish()
        self._db.close()  # FIXME: Fix db clean up

    def _get_uri_from_msg(self, msg):
        if hasattr(msg, 'uri'):
            return msg.uri
        else:
            return msg.get_value('uri')
コード例 #6
0
# wait for internet connection
def connect(host='http://google.com'):
    try:
        urllib.request.urlopen(host)  #Python 3.x
        return True
    except urllib.error.URLError:
        print('not connected to internet')
        return False


while True:
    if connect():
        break
    time.sleep(5)

db = DBWrapper()

COM_PORT = '/dev/ttyACM0'  # 指定通訊埠名稱
BAUD_RATES = 9600  # 設定傳輸速率
ser_tgs = serial.Serial(COM_PORT, BAUD_RATES)  # 初始化序列通訊埠

# SDS011
import struct
from datetime import datetime

# Change this to the right port - /dev/tty* on Linux and Mac and COM* on Windows
PORT = '/dev/ttyUSB0'

UNPACK_PAT = '<ccHHHcc'
ser_sds011 = serial.Serial(PORT, 9600, bytesize=8, parity='N', stopbits=1)
コード例 #7
0
class FilesystemSearcher(object):
    """
    Public API to be used by the UI to ask for files.

    TODO: Do we want to include hidden files should ask the file browserstop
    """

    def __init__(self, plugin, window):
        """
        Window handle setting up the database and file system monitor.
        """
        # defaults
        self._root = "."

        # Setup
        self._window = window
        self._plugin = plugin
        self._message_bus = self._window.get_message_bus()

        self._db = DBWrapper()
        self._monitor = None

        self._message_bus.connect('/plugins/filebrowser', 'root_changed', self.root_changed)

    def root_changed(self, *args, **kwargs):
        root = kwargs.get('root', None)
        previous_root = self._root

        if not root:
            if len(args) == 2:
                msg = args[1]
                root = self._get_uri_from_msg(msg)
        self._root = root.replace("file://", "") # FIXME: HACK

        if not self._monitor:
            self._monitor = FilesystemMonitor(self)
        self._monitor.change_root(previous_root)

        log.debug("changing root from %s -> %s" % (previous_root, self._root))
        

    @property
    def current_root(self):
        """
        Returns the current root location of the window.
        """
        if self.configuration.get_value("USE_FILEBROWSER"):
            return urllib.unquote(self._root)
        else:
            return urllib.unquote(self.configuration.get_value('STATIC_ROOT_PATH'))

    @property
    def filebrowser_current_root(self):
        return self._get_uri_from_msg(self._message_bus.send_sync('/plugins/filebrowser', 'get_root'))

    @property
    def configuration(self):
        return self._plugin._configuration

    def add_file(self, path, file_name):
        self._db.add_file(path, file_name)

    def remove_directory(self, path):
        self._db.remove_directory(path)

    def remove_file(self, path, name):
        self._db.remove_file(path, name)

    def increment_uri_open_count(self, uri):
        self._db.increment_file_open_count(uri.replace("file://", ""))

    def clear_database(self):
        self._db.clear_database()

    def build_exclude_list(self):
        self._monitor._build_exclude_list()

    def search(self, input):
        query = self.current_root + "%" + input
        filewrappers = []
        for row in self._db.search(query):
            # FIXME: Set data in variables so you can tell what data is returned.
            filewrappers.append(FileWrapper(input, self.current_root, row[0], row[1]))
        return filewrappers

    def cleanup(self):
        if self._monitor:
            self._monitor.finish()
        self._db.close() # FIXME: Fix db clean up

    def _get_uri_from_msg(self, msg):
        if hasattr(msg, 'uri'):
            return msg.uri
        else:
            return msg.get_value('uri')