-
Notifications
You must be signed in to change notification settings - Fork 4
Add SQLite support for saveing wlans adapters. #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
muchosun
wants to merge
5
commits into
DistributedSky:master
Choose a base branch
from
muchosun:drone-employee-connect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a59139b
Add Sqlite DBC for save wlan adapters
muchosun 069d97e
Add SQLite support for saveing wlans adapters.
muchosun 24e8aa9
Add unique field for wlan
muchosun 1d40905
Add check wlan and exception for add wlan
muchosun bfaca92
Add smth modification to exception
muchosun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from sqlalchemy import create_engine | ||
| from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey | ||
| from sqlalchemy.orm import mapper | ||
| from sqlalchemy.orm import sessionmaker | ||
| from sqlalchemy.ext.declarative import declarative_base | ||
|
|
||
| Base = declarative_base() | ||
|
|
||
| class Wlans(Base): | ||
| __tablename__ = 'wlanstb' | ||
| id = Column(Integer, primary_key=True) | ||
| name = Column(String) | ||
| wlan = Column(String(30), nullable=False, unique=True) | ||
| ssid = Column(String) | ||
| password = Column(String) | ||
|
|
||
| def __init__(self, name, wlan, ssid, password): | ||
| self.name = name | ||
| self.wlan = wlan | ||
| self.ssid = ssid | ||
| self.password = password | ||
| def __repr__(self): | ||
| return "%s,%s,%s,%s" % (self.name, self.wlan, self.ssid, self.password) | ||
| #def showall(self): | ||
| #for instance in session.query(self).order_by(self.id): | ||
| #print(instance) | ||
|
|
||
| engine = create_engine('sqlite:///wlans.db', echo=True) | ||
| Session = sessionmaker(bind=engine) | ||
| Base.metadata.create_all(engine) | ||
|
|
||
| def add_wlan(name, wlan, ssid, password): | ||
| session = Session() | ||
| try: | ||
| new_wlan=Wlans(name,wlan,ssid,password) | ||
| session.add(new_wlan) | ||
| session.commit() | ||
| session.flush() | ||
| except: | ||
| print("Oops! That was no valid wlan. Try again...") | ||
|
|
||
| def update_wlan(name,wlan,ssid,password): | ||
| session = Session() | ||
| session.query(Wlans).filter(Wlans.wlan == wlan).update({Wlans.name: name, Wlans.ssid: ssid, Wlans.password: password}) | ||
| session.commit() | ||
| session.flush() | ||
|
|
||
| def check_wlan(name,wlan,ssid,password): | ||
| session = Session() | ||
| new_wlan=Wlans(name,wlan,ssid,password) | ||
| if len(new_wlan.wlan)>=8 and session.query(Wlans.wlan).filter(Wlans.wlan == new_wlan.wlan).all(): | ||
| session.flush() | ||
| update_wlan(name,wlan,ssid,password) | ||
| elif len(new_wlan.wlan)>=8: | ||
| session.flush() | ||
| add_wlan(name, wlan, ssid, password) | ||
|
|
||
| def del_wlan(name): | ||
| session = Session() | ||
| session.query(Wlans).filter(Wlans.name == name).delete() | ||
| session.commit() | ||
| session.flush() | ||
|
|
||
|
|
||
| ''' | ||
| add_wlan("1","2","3","4") | ||
| session = Session() | ||
| print session.query(Wlans).all() | ||
| if len("12345678") >= 8 and session.query(Wlans.wlan).filter(Wlans.wlan == "2").all(): | ||
| print True | ||
| else: | ||
| print False | ||
| session.flush() | ||
| ''' | ||
|
|
||
| #check_wlan("4","2","3","5") | ||
| #print session.query(Wlans).filter(Wlans.wlan == "2").update({Wlans.name: "hui"}, synchronize_session=False) | ||
| #del_wlan("Solo-1") | ||
| #print session.query(Wlans).all() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/sh | ||
| cd /home/pi/drone-employee-connect && . venv/bin/activate && PORT=80 python serve.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут, по-хорошему, можно поймать исключение, связанное с дубликатом уникального поля и делать update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Интересный стиль. Вместо того что использовать if будем провоцировать ошибки)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://wiki.c2.com/?LetItCrash