Тперь архив не будет удален, если мы его не качали.
This commit is contained in:
parent
d718df1fed
commit
3b1197213c
22
README.md
22
README.md
@ -50,7 +50,17 @@ _Внимание_! Только Python 2.7, только PostgreSQL, тольк
|
|||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install postgresql-9.5
|
sudo apt-get install postgresql-9.5
|
||||||
```
|
```
|
||||||
Затем создайте пользователя и базу данных.
|
Затем создайте пользователя и базу данных:
|
||||||
|
```
|
||||||
|
sudo adduser phias
|
||||||
|
sudo -u postgres psql
|
||||||
|
postgres=# CREATE EXTENSION pg_trgm;
|
||||||
|
postgres=# CREATE EXTENSION btree_gin;
|
||||||
|
postgres=# CREATE DATABASE fias_db;
|
||||||
|
postgres=# CREATE USER phias WITH password 'phias';
|
||||||
|
postgres=# GRANT ALL privileges ON DATABASE fias_db TO phias;
|
||||||
|
postgres=# ALTER USER phias WITH SUPERUSER;
|
||||||
|
```
|
||||||
|
|
||||||
3. Sphinx 2.2.1 и новее:
|
3. Sphinx 2.2.1 и новее:
|
||||||
[Windows](http://sphinxsearch.com/downloads/release/), Debian:
|
[Windows](http://sphinxsearch.com/downloads/release/), Debian:
|
||||||
@ -93,7 +103,7 @@ _Внимание_! Только Python 2.7, только PostgreSQL, тольк
|
|||||||
3. Установить sphinxapi последней версии:
|
3. Установить sphinxapi последней версии:
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install https://github.com/Romamo/sphinxapi/zipball/master
|
sudo pip install https://github.com/Romamo/sphinxapi/zipball/master
|
||||||
```
|
```
|
||||||
4. Установить, собственно, приложение:
|
4. Установить, собственно, приложение:
|
||||||
- полностью:
|
- полностью:
|
||||||
@ -106,8 +116,12 @@ _Внимание_! Только Python 2.7, только PostgreSQL, тольк
|
|||||||
cd /var/www/py-phias
|
cd /var/www/py-phias
|
||||||
sudo pip install -r requirements.txt
|
sudo pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
- как библиотеку:
|
- как repo:
|
||||||
|
|
||||||
```
|
```
|
||||||
python -m pip install ....
|
sudo mkdir -p /var/www/py-phias
|
||||||
|
sudo chown phias: /var/www/py-phias
|
||||||
|
cd /var/www
|
||||||
|
sudo -u phias -H git clone --branch=master https://github.com/jar3b/py-phias.git py-phias
|
||||||
|
sudo pip install -r requirements.txt
|
||||||
```
|
```
|
@ -15,6 +15,12 @@ from aoxmltableentry import AoXmlTableEntry
|
|||||||
class AoRar:
|
class AoRar:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
rarfile.UNRAR_TOOL = unrar_config.path
|
rarfile.UNRAR_TOOL = unrar_config.path
|
||||||
|
self.fname = None
|
||||||
|
self.mode = None
|
||||||
|
|
||||||
|
def local(self, fname):
|
||||||
|
self.fname = fname
|
||||||
|
self.mode = "local"
|
||||||
|
|
||||||
def download(self, url):
|
def download(self, url):
|
||||||
logging.info("Downloading %s", url)
|
logging.info("Downloading %s", url)
|
||||||
@ -35,11 +41,12 @@ class AoRar:
|
|||||||
raise FiasException("Error downloading. Reason : {}".format(format_exc()))
|
raise FiasException("Error downloading. Reason : {}".format(format_exc()))
|
||||||
|
|
||||||
logging.info("Downloaded %d bytes", int(request.headers['Content-length']))
|
logging.info("Downloaded %d bytes", int(request.headers['Content-length']))
|
||||||
return local_filename
|
self.fname = local_filename
|
||||||
|
self.mode = "remote"
|
||||||
|
|
||||||
def get_table_entries(self, file_name, allowed_tables):
|
def get_table_entries(self, allowed_tables):
|
||||||
if file_name and os.path.isfile(file_name):
|
if self.fname and os.path.isfile(self.fname):
|
||||||
rf = rarfile.RarFile(file_name)
|
rf = rarfile.RarFile(self.fname)
|
||||||
|
|
||||||
for arch_entry in rf.infolist():
|
for arch_entry in rf.infolist():
|
||||||
xmltable = AoXmlTableEntry.from_rar(arch_entry.filename, rf, arch_entry)
|
xmltable = AoXmlTableEntry.from_rar(arch_entry.filename, rf, arch_entry)
|
||||||
@ -47,6 +54,10 @@ class AoRar:
|
|||||||
yield xmltable
|
yield xmltable
|
||||||
else:
|
else:
|
||||||
logging.info("All entries processed")
|
logging.info("All entries processed")
|
||||||
os.remove(file_name)
|
if self.mode == "remote":
|
||||||
|
try:
|
||||||
|
os.remove(self.fname)
|
||||||
|
except:
|
||||||
|
logging.warning("Cannot delete %s, do it manually", self.fname)
|
||||||
else:
|
else:
|
||||||
logging.error("No file specified or not exists")
|
logging.error("No file specified or not exists")
|
||||||
|
@ -61,16 +61,13 @@ class Updater:
|
|||||||
|
|
||||||
def __get_updates_from_rar(self, url):
|
def __get_updates_from_rar(self, url):
|
||||||
aorar = AoRar()
|
aorar = AoRar()
|
||||||
fname = None
|
|
||||||
|
|
||||||
if url.startswith("http://") or url.startswith("https://"):
|
if url.startswith("http://") or url.startswith("https://"):
|
||||||
fname = aorar.download(url)
|
aorar.download(url)
|
||||||
if url.endswith(".rar") and path.isfile(url):
|
if url.endswith(".rar") and path.isfile(url):
|
||||||
fname = url
|
aorar.local(url)
|
||||||
|
|
||||||
assert fname, "No source was specified"
|
for table_entry in aorar.get_table_entries(allowed_tables):
|
||||||
|
|
||||||
for table_entry in aorar.get_table_entries(fname, allowed_tables):
|
|
||||||
yield table_entry
|
yield table_entry
|
||||||
|
|
||||||
def __init_update_entries(self, updates_generator):
|
def __init_update_entries(self, updates_generator):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user