Permalink
Browse files

reformatting and todo: learning the code

  • Loading branch information...
1 parent 36e9f97 commit d61a5d126daf8e6c554ddc1bef819828ee3f2d0b Dmytro Lytovchenko committed Feb 7, 2014
Showing with 1,216 additions and 1,189 deletions.
  1. +23 −18 README.markdown
  2. +3 −0 include/epm.hrl
  3. +93 −91 src/bitbucket_api.erl
  4. +64 −63 src/epm.erl
  5. +606 −601 src/epm_core.erl
  6. +30 −30 src/epm_package.erl
  7. +142 −139 src/epm_util.erl
  8. +74 −66 src/github_api.erl
  9. +181 −181 src/yaws_html.erl
View
@@ -1,3 +1,9 @@
+# How did this project get here?
+
+http://hyperthunk.wordpress.com/2012/05/28/does-erlangotp-need-a-new-package-management-solution/
+
+--------------------
+
### epm _IS_
* an Erlang package manager meant to have _minimal_ impact on projects
* a simple and easy dependency tracker
@@ -11,13 +17,13 @@
curl "https://github.com/JacobVorreuter/epm/raw/master/epm" > epm
chmod +x epm
sudo mv epm /usr/local/bin/
-
+
epm config --set build_dir "/tmp"
epm config --set install_dir "/Users/jvorreuter/erl_libs"
epm config --set proxy_host http://my.corporate.proxy
epm config --set proxy_port 80
epm config --set net_timeout 60000 # for a slow network...
-
+
### Read the blog post
<http://www.jkvor.com/erlang-package-manager>
@@ -77,7 +83,7 @@
--get (default)
--set <key> <value>
--remove <key>
-
+
### Do it
tell epm where to install packages
@@ -86,8 +92,8 @@ tell epm where to install packages
epm v0.1.1, 2010
+ updated .epm config
-
-search for an Erlang app
+
+search for an Erlang app
jvorreuter$ ./epm search excavator
epm v0.1.1, 2010
@@ -98,15 +104,15 @@ search for an Erlang app
name: excavator
owner: JacobVorreuter
followers: 7
- homepage:
+ homepage:
description: An Erlang application for ingesting data from various sources (APIs, data feeds, web content, etc)
tags:
"0.3"
branches:
master
scheduler
-install that app that you wanted (its dependencies will be installed too)
+install that app that you wanted (its dependencies will be installed too)
jvorreuter$ ./epm install excavator
epm v0.1.1, 2010
@@ -142,7 +148,7 @@ install that app that you wanted (its dependencies will be installed too)
+ running excavator build command
+ running excavator install command
-get some info about that app you just installed
+get some info about that app you just installed
jvorreuter$ ./epm info excavator
epm v0.1.1, 2010
@@ -154,16 +160,16 @@ get some info about that app you just installed
owner: JacobVorreuter
vsn: master
install dir: /Users/jvorreuter/dev/excavator-0.3
- homepage:
+ homepage:
description: An Erlang application for ingesting data from various sources (APIs, data feeds, web content, etc)
- dependencies:
+ dependencies:
clones/mochiweb/master
mochixpath/master
dynamic_compile/master
epm/etap/master
mochiweb_server_behavior/master
-how 'bout a list of all apps I've installed?
+how 'bout a list of all apps I've installed?
jvorreuter$ ./epm list
epm v0.1.1, 2010
@@ -175,9 +181,9 @@ how 'bout a list of all apps I've installed?
owner: JacobVorreuter
vsn: master
install dir: /Users/jvorreuter/dev/excavator-0.3
- homepage:
+ homepage:
description: An Erlang application for ingesting data from various sources (APIs, data feeds, web content, etc)
- dependencies:
+ dependencies:
clones/mochiweb/master
mochixpath/master
dynamic_compile/master
@@ -195,23 +201,23 @@ how 'bout a list of all apps I've installed?
owner: JacobVorreuter
vsn: master
install dir: /Users/jvorreuter/dev/dynamic_compile-0.1
- homepage:
+ homepage:
description: compile and load erlang modules from string input
name: mochiweb_server_behavior
owner: JacobVorreuter
vsn: master
install dir: /Users/jvorreuter/dev/mochiweb_server_behavior-0.1
- homepage:
+ homepage:
description: Erlang behavior for a simple mochiweb web server
- dependencies:
+ dependencies:
clones/mochiweb/master
name: etap
owner: epm
vsn: master
install dir: /Users/jvorreuter/dev/etap-0.3.4
- homepage:
+ homepage:
description: etap is a simple erlang testing library that provides TAP compliant output.
name: mochiweb
@@ -234,4 +240,3 @@ what have I done? I must remove that terrible app. Its dependencies can stay tho
([y]/n) y
+ removing package JacobVorreuter-excavator-master from /Users/jvorreuter/dev/excavator-0.3
-
View
@@ -1,3 +1,6 @@
+-define(epm_version, "0.1.1").
+-define(epm_year, 2014).
+
-define(EXIT(Format, Args), exit(lists:flatten(io_lib:format(Format, Args)))).
-record(repository, {name, owner, description, homepage, followers, pushed, api_module}).
View
@@ -1,23 +1,23 @@
-%% OMFG, this API sucks.
+%% OMFG, this API sucks.
%%
%% explain to me how this is even remotely useful:
%% jacobvorreuter$ curl "http://api.bitbucket.org/1.0/repositories/?name=rebar"
%% {
-%% "count": 12,
-%% "query": "rebar",
+%% "count": 12,
+%% "query": "rebar",
%% "repositories": [
%% {
-%% "website": "",
-%% "slug": "rebar",
-%% "name": "rebar",
-%% "followers_count": 0,
+%% "website": "",
+%% "slug": "rebar",
+%% "name": "rebar",
+%% "followers_count": 0,
%% "description": ""
-%% },
+%% },
%% {
-%% "website": null,
-%% "slug": "rebar",
-%% "name": "rebar",
-%% "followers_count": 0,
+%% "website": null,
+%% "slug": "rebar",
+%% "name": "rebar",
+%% "followers_count": 0,
%% "description": ""
%% },
%% ...
@@ -35,52 +35,55 @@
-include("epm.hrl").
package_deps(User, ProjectName, Vsn) ->
- if
- User == undefined -> ?EXIT("get_package_deps/3 user cannot be undefined",[]);
- true -> ok
- end,
- if
- ProjectName == undefined -> ?EXIT("get_package_deps/3 name cannot be undefined",[]);
- true -> ok
- end,
- if
- Vsn == undefined -> ?EXIT("get_package_deps/3 vsn cannot be undefined",[]);
- true -> ok
- end,
- Url = lists:flatten(io_lib:format("http://bitbucket.org/~s/~s/raw/~s/~s.epm", [User, ProjectName, Vsn, ProjectName])),
- case epm_util:request_as_str(Url, "bitbucket.org") of
- Body when is_list(Body) -> proplists:get_value(deps, epm_util:eval(Body), []);
- _ -> []
- end.
-
+ if
+ User == undefined ->
+ ?EXIT("get_package_deps/3 user cannot be undefined", []);
+ true -> ok
+ end,
+ if
+ ProjectName == undefined ->
+ ?EXIT("get_package_deps/3 name cannot be undefined", []);
+ true -> ok
+ end,
+ if
+ Vsn == undefined -> ?EXIT("get_package_deps/3 vsn cannot be undefined", []);
+ true -> ok
+ end,
+ Url = lists:flatten(io_lib:format("http://bitbucket.org/~s/~s/raw/~s/~s.epm", [User, ProjectName, Vsn, ProjectName])),
+ case epm_util:request_as_str(Url, "bitbucket.org") of
+ Body when is_list(Body) ->
+ proplists:get_value(deps, epm_util:eval(Body), []);
+ _ -> []
+ end.
+
search(ProjectName) ->
- case request_as_xml("http://bitbucket.org/repo/all/?name=" ++ ProjectName) of
- {html,_,_}=Html ->
- case search_xml_for_repos(Html) of
- undefined -> [];
- Repos -> extract_repo_info_from_html(Repos)
- end;
- Err ->
- Err
- end.
-
-info(User, ProjectName) ->
- case search(ProjectName) of
- [#repository{}|_]=Repos ->
- case lists:filter(
- fun(Repo) ->
- Repo#repository.owner==User andalso
- Repo#repository.name==ProjectName
- end, Repos) of
- [R|_] -> R;
- _ -> undefined
- end;
- [] ->
- undefined;
- Err ->
- Err
- end.
-
+ case request_as_xml("http://bitbucket.org/repo/all/?name=" ++ ProjectName) of
+ {html, _, _} = Html ->
+ case search_xml_for_repos(Html) of
+ undefined -> [];
+ Repos -> extract_repo_info_from_html(Repos)
+ end;
+ Err ->
+ Err
+ end.
+
+info(User, ProjectName) ->
+ case search(ProjectName) of
+ [#repository{}|_] = Repos ->
+ case lists:filter(
+ fun(Repo) ->
+ Repo#repository.owner == User andalso
+ Repo#repository.name == ProjectName
+ end , Repos) of
+ [R|_] -> R;
+ _ -> undefined
+ end;
+ [] ->
+ undefined;
+ Err ->
+ Err
+ end.
+
tags(User, ProjectName) ->
Xml = request_as_xml(lists:flatten(io_lib:format("http://api.bitbucket.org/1.0/repositories/~s/~s/tags/?format=xml", [User, ProjectName]))),
case Xml of
@@ -102,26 +105,26 @@ branches(User, ProjectName) ->
download_package(Repo, Vsn) ->
Url = lists:flatten(io_lib:format("http://bitbucket.org/~s/~s/get/~s.tar.gz", [Repo#repository.owner, Repo#repository.name, Vsn])),
epm_package:download_tarball(Repo, Url).
-
+
default_vsn() -> "tip".
request_as_xml(Url) ->
- case epm_util:request_as_str(Url, "bitbucket.org") of
- Body when is_list(Body) ->
- case yaws_html:h2e(Body) of
- {ehtml,[],[_,Xml]} -> Xml;
- _ -> poorly_formatted_xml
- end;
- Err ->
- Err
- end.
-
+ case epm_util:request_as_str(Url, "bitbucket.org") of
+ Body when is_list(Body) ->
+ case yaws_html:h2e(Body) of
+ {ehtml, [], [_, Xml]} -> Xml;
+ _ -> poorly_formatted_xml
+ end;
+ Err ->
+ Err
+ end.
+
%% fake xpaths
-search_xml_for_repos({'div',[{class,"repos-all"}|_],Repos}) ->
+search_xml_for_repos({'div',[{class,"repos-all"}|_],Repos}) ->
Repos;
search_xml_for_repos({_,_,Children}) ->
- search_xml_for_repos(Children);
+ search_xml_for_repos(Children);
search_xml_for_repos([Child|Tail]) when not is_integer(Child) ->
case search_xml_for_repos(Child) of
undefined ->
@@ -132,24 +135,23 @@ search_xml_for_repos([Child|Tail]) when not is_integer(Child) ->
search_xml_for_repos(_) -> undefined.
extract_repo_info_from_html(Repos) ->
- lists:foldl(
- fun({'div',_,Props}, Acc) ->
- case Props of
- [{'div',_,_},{span,[],[{a,_,User},_,{a,_,RepoName}]},{br,_},Desc|_] ->
- Desc1 = string:strip(re:replace(Desc, "[\\t\\n]", "", [global, {return, list}])),
- Desc2 =
- case Desc1 of
- "Clone URL" ++ _ -> undefined;
- _ -> Desc1
- end,
- [#repository{
- owner = User,
- name = RepoName,
- description = Desc2,
- api_module = ?MODULE
- }|Acc];
- _ ->
- Acc
- end
- end, [], lists:reverse(Repos)).
-
+ lists:foldl(
+ fun({'div', _, Props}, Acc) ->
+ case Props of
+ [{'div', _, _}, {span, [], [{a, _, User}, _, {a, _, RepoName}]}, {br, _}, Desc|_] ->
+ Desc1 = string:strip(re:replace(Desc, "[\\t\\n]", "", [global, {return, list}])),
+ Desc2 =
+ case Desc1 of
+ "Clone URL" ++ _ -> undefined;
+ _ -> Desc1
+ end,
+ [#repository{
+ owner = User ,
+ name = RepoName ,
+ description = Desc2,
+ api_module = ?MODULE
+ }|Acc];
+ _ ->
+ Acc
+ end
+ end, [], lists:reverse(Repos)).
Oops, something went wrong.

0 comments on commit d61a5d1

Please sign in to comment.