Skip to content

Commit

Permalink
merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhammond committed Apr 27, 2011
2 parents 0e6d9b2 + 615aaad commit c80fc0d
Show file tree
Hide file tree
Showing 50 changed files with 1,218 additions and 1,453 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Expand Up @@ -6,5 +6,4 @@ recursive-include linkdrop *
recursive-include grinder *
recursive-include docs *
recursive-include tools *
recursive-include web *
recursive-include wsgi *
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -5,7 +5,7 @@ BIN_DIR = bin
endif

APPNAME = server-shared-send
DEPS = server-share-core
DEPS = mozilla:server-core,github:server-share-core
VIRTUALENV = virtualenv
NOSE = $(BIN_DIR)/nosetests
NOSETESTS_ARGS = -s
Expand Down
52 changes: 40 additions & 12 deletions README.md
Expand Up @@ -25,30 +25,58 @@ Some directory explanations:

make build

If you get this error on Mac OS X:
If you are on OS X and you get errors or it does not work, see the OS X troubleshooting
section below.

/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
### Start the virtualenv

It could be because the default version of GCC is too high. If you do
source bin/activate

ls -la /usr/bin/gcc
### Running f1

And it points to gcc-4.2, then change it to point to gcc-4.0 (warning affects all gcc calls from then on):
Run the web server. 'reload' is useful for development, the webserver restarts on file changes, otherwise you can leave it off

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.0 /usr/bin/gcc
paster serve --reload development.ini

Info taken from [this web site](http://blog.coredumped.org/2009/09/snow-leopard-and-lxml.html)
Then visit: [http://127.0.0.1:5000/](http://127.0.0.1:5000/) for an index of api examples

## Troubleshooting OS X installs

### Running f1
If the **make build** command produced errors or results in not being able to start
up the server, use the following steps. It is suggested you re-clone F1 before
doing the following steps, so that it starts out with a clean environment.

Run the web server. 'reload' is useful for development, the webserver restarts on file changes, otherwise you can leave it off
1. Make sure XCode 3 is installed.

paster serve --reload development.ini
2. Build your own version of Python:

Then visit: [http://127.0.0.1:5000/](http://127.0.0.1:5000/) for an index of api examples
sudo svn co http://svn.plone.org/svn/collective/buildout/python/
sudo chown -R $USER ./python
cd python
vi buildout.cfg: then remove any references to python 2.4 and 2.5
python bootstrap.py
./bin/buildout
cd /usr/local/bin
sudo ln -s /opt/python/bin/virtualenv-2.6 virtualenv

3. Now edit your .profile to make sure that if you have MacPorts installed, its PATH and MANPATH variables
are last in the list for those environment variables.

I also removed export PYTHONPATH=/Users/aaa/hg/raindrop/server/python:$PYTHONPATH
and removed /Library/Frameworks/Python.framework/Versions/Current/bin from the $PATH variable.

4. Build C libraries via Homebrew:

Homebrew installs into /usr/local by default, and it is best if you chown the files in there to you:

sudo chown -R $USER /usr/local

If installed things before in these directories, remove these directories: /usr/local/include and /usr/local/lib

ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
brew install memcached libmemcached

Then try the **make build** command above and continue from there.

## Setting up a valid Google domain for OpenID+OAuth

Expand Down
43 changes: 29 additions & 14 deletions build.py
Expand Up @@ -39,7 +39,8 @@


CURDIR = os.path.dirname(__file__)
REPO_ROOT = 'https://github.com/mozilla/%s.git'
REPOS = {'github': ('git', 'https://github.com/mozilla/%s.git'),
'mozilla': ('hg', 'https://hg.mozilla.org/services/%s')}
PYTHON = sys.executable


Expand Down Expand Up @@ -74,21 +75,27 @@ def _envname(name):
return name.upper().replace('-', '_')


def _update_cmd(project, latest_tags=False):
def _update_cmd(project, latest_tags=False, repo_type='git'):
if latest_tags:
return 'git checkout -r "%s"' % get_latest_tag()
if repo_type == 'hg':
return 'hg up -r "%s"' % get_latest_tag()
else:
return 'git checkout -r "%s"' % get_latest_tag()
else:

# looking for an environ with a specific tag or rev
rev = os.environ.get(_envname(project))
if rev is not None:

if not verify_tag(rev):
print('Unknown tag or revision: %s' % rev)
sys.exit(1)

return 'git checkout -r "%s"' % rev
return 'git checkout'
if repo_type == 'git':
return 'git checkout -r "%s"' % rev
else:
return 'hg up -r "%s"' % rev
if repo_type == 'git':
return 'git checkout'
else:
return 'hg up'


def build_app(name, latest_tags, deps):
Expand All @@ -113,16 +120,24 @@ def build_deps(deps, latest_tags):
os.mkdir(deps_dir)

for dep in deps:
repo = REPO_ROOT % dep
target = os.path.join(deps_dir, dep)
root, name = dep.split(':')
repo_type, repo_root = REPOS[root]
repo = repo_root % name
target = os.path.join(deps_dir, name)
if os.path.exists(target):
os.chdir(target)
_run('git pull')
if repo_type == 'git':
_run('git pull')
else:
_run('hg pull')
else:
_run('git clone %s %s' % (repo, target))
os.chdir(target)
if repo_type == 'git':
_run('git clone %s %s' % (repo, target))
else:
_run('hg clone %s %s' % (repo, target))

update_cmd = _update_cmd(dep, latest_tags)
os.chdir(target)
update_cmd = _update_cmd(dep, latest_tags, repo_type)
_run(update_cmd)
_run('%s setup.py develop' % PYTHON)
finally:
Expand Down
4 changes: 4 additions & 0 deletions development.ini
Expand Up @@ -57,6 +57,10 @@ oauth.linkedin.com.request = https://api.linkedin.com/uas/oauth/requestToken
oauth.linkedin.com.access = https://api.linkedin.com/uas/oauth/accessToken
oauth.linkedin.com.authorize = https://api.linkedin.com/uas/oauth/authorize

sstatus.enabled = 0
sstatus.servers = 127.0.0.1:11211
sstatus.domains = google.com,twitter.com,facebook.com,linkedin.com

[server:main]
use = egg:Paste#http
host = 127.0.0.1
Expand Down
9 changes: 4 additions & 5 deletions f1.spec.in
Expand Up @@ -17,7 +17,7 @@
%global python_sitelib /lib/python%{python_version}/site-packages
%global python_sitearch /%{_lib}/python%{python_version}/site-packages

Name: %{f1_name_prefix}python%{pyver_sys}
Name: %{f1_name_prefix}python%{pyver}
Version: %%version%%
Release: 6%%git%%%{?dist}
Summary: Share Links Fast.
Expand Down Expand Up @@ -51,15 +51,13 @@ and love. F1 is made by Mozilla Messaging.

%build
export PYTHONPATH=$(pwd):%{f1_prefix}%{python_sitelib}:%{f1_prefix}%{python_sitearch}
mkdir web
CFLAGS="%{optflags}" %{__python}%{pyver} setup.py build
make web PYTHON=%{__python}%{pyver}

%install
export PYTHONPATH=$(pwd):%{f1_prefix}%{python_sitelib}:%{f1_prefix}%{python_sitearch}
rm -rf %{buildroot}
%{__python}%{pyver} setup.py install --single-version-externally-managed -O1 --root=$RPM_BUILD_ROOT --prefix %{f1_prefix} --record=INSTALLED_FILES
%{__install} -m 755 -d %{buildroot}%{_var}/www/f1
rsync -a web/ %{buildroot}%{_var}/www/f1/
%{__install} -m 755 -d %{buildroot}%{_sysconfdir}/f1
%{__install} -m 644 *.ini %{buildroot}%{_sysconfdir}/f1/

Expand All @@ -73,12 +71,13 @@ rsync -a web/ %{buildroot}%{_var}/www/f1/
rm -rf %{buildroot}

%files -f INSTALLED_FILES
%{_var}/www/f1
%config(noreplace) %{_sysconfdir}/f1/*ini
%defattr(-,root,root,-)
%doc README.md LICENSE PKG-INFO docs/

%changelog
* Tue Apr 26 2011 Philippe M. Chiasson <gozer@mozillamessaging.com> - 0.3.7dev-7
- Remove web content, moved to mozilla-f1-web
* Wed Apr 20 2011 Philippe M. Chiasson <gozer@mozillamessaging.com> - 0.3.7dev-6
- Compile web content before packaging (make web)
* Thu Apr 14 2011 Philippe M. Chiasson <gozer@mozillamessaging.com> - 0.3.7dev-2
Expand Down
41 changes: 41 additions & 0 deletions linkdrop/controllers/__init__.py
@@ -0,0 +1,41 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Raindrop.
#
# The Initial Developer of the Original Code is
# Mozilla Messaging, Inc..
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Tarek Ziade <tarek@mozilla.com>
#

# XXX services instance to be moved in the future application
# object once Pylons gets removed

from linkoauth import Services
from pylons import config

services = None


def get_services():
global services
if services is None:
enabled = int(config.get('sstatus.ttl', '0'))
servers = config['sstatus.servers'].split(',')
domains = config['sstatus.domains'].split(',')
ttl = int(config.get('sstatus.ttl', '60'))
services = Services(domains, servers, ttl, enabled)
return services
16 changes: 8 additions & 8 deletions linkdrop/controllers/account.py
Expand Up @@ -19,6 +19,7 @@
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Rob Miller (rmiller@mozilla.com)
#

import logging
Expand All @@ -32,13 +33,12 @@
from pylons.controllers.util import redirect
from pylons.controllers.core import HTTPException

from linkoauth.errors import AccessException
from linkdrop.controllers import get_services
from linkdrop.lib.base import BaseController
from linkdrop.lib.helpers import get_redirect_response
from linkdrop.lib.metrics import metrics

from linkoauth import get_provider
from linkoauth.base import AccessException

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -66,19 +66,19 @@ def _create_account(self, domain, userid, username):
def authorize(self, *args, **kw):
provider = request.POST['domain']
log.info("authorize request for %r", provider)
service = get_provider(provider)
return service.responder().request_access(request, url, session)
services = get_services()
return services.request_access(provider, request, url, session)

# this is not a rest api
def verify(self, *args, **kw):
provider = request.params.get('provider')
log.info("verify request for %r", provider)
service = get_provider(provider)

auth = service.responder()
acct = dict()
try:
user = auth.verify(request, url, session)
services = get_services()
user = services.verify(provider, request, url, session)

account = user['profile']['accounts'][0]
if (not user.get('oauth_token')
and not user.get('oauth_token_secret')):
Expand Down
32 changes: 16 additions & 16 deletions linkdrop/controllers/contacts.py
Expand Up @@ -19,16 +19,18 @@
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Rob Miller (rmiller@mozilla.com)
#

import logging
import json

from pylons import request

from linkoauth import get_provider
from linkoauth.base import OAuthKeysException, ServiceUnavailableException
from linkoauth.errors import (OAuthKeysException, ServiceUnavailableException,
DomainNotRegisteredError)

from linkdrop.controllers import get_services
from linkdrop.lib.base import BaseController
from linkdrop.lib.helpers import json_exception_response, api_response
from linkdrop.lib.helpers import api_entry, api_arg, get_passthrough_headers
Expand Down Expand Up @@ -84,17 +86,8 @@ class ContactsController(BaseController):
],
response={'type': 'object', 'doc': 'Portable Contacts Collection'})
def get(self, domain):
group = request.POST.get('group', None)
startIndex = int(request.POST.get('startindex', '0'))
maxResults = int(request.POST.get('maxresults', '25'))
page_data = request.POST.get('pageData', None)
account_data = request.POST.get('account', None)
provider = get_provider(domain)
if provider is None:
error = {
'message': "'domain' is invalid",
'code': constants.INVALID_PARAMS,
}
return {'result': None, 'error': error}

acct = None
if account_data:
Expand All @@ -109,11 +102,18 @@ def get(self, domain):
return {'result': None, 'error': error}

headers = get_passthrough_headers(request)
page_data = page_data and json.loads(page_data) or {}
try:
result, error = provider.api(acct).getcontacts(startIndex,
maxResults,
group,
headers)
services = get_services()
result, error = services.getcontacts(domain, acct, page_data,
headers)
except DomainNotRegisteredError:
error = {
'message': "'domain' is invalid",
'code': constants.INVALID_PARAMS,
}
return {'result': None, 'error': error}

except OAuthKeysException, e:
# more than likely we're missing oauth tokens for some reason.
error = {'provider': domain,
Expand Down

0 comments on commit c80fc0d

Please sign in to comment.