forked from binux/pyspider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from binux/master
Merge original project pull request at 2015-10-09
- Loading branch information
Showing
18 changed files
with
165 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ MAINTAINER binux <[email protected]> | |
# install python | ||
RUN apt-get update && \ | ||
apt-get install -y python python-dev python-distribute python-pip && \ | ||
apt-get install -y libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml python-mysqldb | ||
apt-get install -y libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml python-mysqldb libpq-dev | ||
|
||
# install requirements | ||
ADD requirements.txt /opt/pyspider/requirements.txt | ||
|
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -19,3 +19,4 @@ six | |
amqp>=1.3.0 | ||
redis | ||
kombu | ||
psycopg2 |
This file contains 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 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 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,69 @@ | ||
#!/usr/bin/env python | ||
# -*- encoding: utf-8 -*- | ||
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8: | ||
# Author: Binux<[email protected]> | ||
# http://binux.me | ||
# Created on 2015-09-30 23:22:46 | ||
|
||
import click | ||
import logging | ||
from pyspider.database.base.projectdb import ProjectDB | ||
from pyspider.database.base.taskdb import TaskDB | ||
from pyspider.database.base.resultdb import ResultDB | ||
from pyspider.database import connect_database | ||
from pyspider.libs.utils import unicode_obj | ||
from multiprocessing.pool import ThreadPool as Pool | ||
|
||
logging.getLogger().setLevel(logging.INFO) | ||
|
||
|
||
def taskdb_migrating(project, from_connection, to_connection): | ||
logging.info("taskdb: %s", project) | ||
f = connect_database(from_connection) | ||
t = connect_database(to_connection) | ||
t.drop(project) | ||
for status in range(1, 5): | ||
for task in f.load_tasks(status, project=project): | ||
t.insert(project, task['taskid'], task) | ||
|
||
|
||
def resultdb_migrating(project, from_connection, to_connection): | ||
logging.info("resultdb: %s", project) | ||
f = connect_database(from_connection) | ||
t = connect_database(to_connection) | ||
t.drop(project) | ||
for result in f.select(project): | ||
t.save(project, result['taskid'], result['url'], result['result']) | ||
|
||
|
||
@click.command() | ||
@click.option('--pool', default=10, help='cocurrent worker size.') | ||
@click.argument('from_connection', required=1) | ||
@click.argument('to_connection', required=1) | ||
def migrate(pool, from_connection, to_connection): | ||
""" | ||
Migrate tool for pyspider | ||
""" | ||
f = connect_database(from_connection) | ||
t = connect_database(to_connection) | ||
|
||
if isinstance(f, ProjectDB): | ||
for each in f.get_all(): | ||
each = unicode_obj(each) | ||
logging.info("projectdb: %s", each['name']) | ||
t.drop(each['name']) | ||
t.insert(each['name'], each) | ||
elif isinstance(f, TaskDB): | ||
pool = Pool(pool) | ||
pool.map( | ||
lambda x, f=from_connection, t=to_connection: taskdb_migrating(x, f, t), | ||
f.projects) | ||
elif isinstance(f, ResultDB): | ||
pool = Pool(pool) | ||
pool.map( | ||
lambda x, f=from_connection, t=to_connection: resultdb_migrating(x, f, t), | ||
f.projects) | ||
|
||
|
||
if __name__ == '__main__': | ||
migrate() |