Skip to content

Commit

Permalink
Add fastestmirror module + LRO_FASTESTMIRROR option + example
Browse files Browse the repository at this point in the history
  • Loading branch information
Tojaj committed Sep 25, 2013
1 parent d232e2e commit acf458f
Show file tree
Hide file tree
Showing 20 changed files with 656 additions and 6 deletions.
15 changes: 13 additions & 2 deletions examples/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ CC=gcc
CFLAGS= -Wall -Wextra -g -std=c99 -O3 -I../../ `pkg-config --cflags glib-2.0`
LINKFLAGS= -L../../build/librepo/ -lrepo `pkg-config --libs glib-2.0`

all: download_repo download_packages download_repo_with_callback
all: \
download_repo \
download_packages \
download_repo_with_callback \
fastestmirror

download_repo:
$(CC) $(CFLAGS) download_repo.c $(LINKFLAGS) -o download_repo
Expand All @@ -16,8 +20,15 @@ download_packages:
download_repo_with_callback:
$(CC) $(CFLAGS) download_repo_with_callback.c $(LINKFLAGS) -o download_repo_with_callback

fastestmirror:
$(CC) $(CFLAGS) fastestmirror.c $(LINKFLAGS) -o fastestmirror

clean:
rm -f download_repo download_packages download_repo_with_callback
rm -f \
download_repo \
download_packages \
download_repo_with_callback \
fastestmirror

run:
LD_LIBRARY_PATH="../../build/librepo/" ./download_repo
52 changes: 52 additions & 0 deletions examples/c/fastestmirror.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
#include <librepo/librepo.h>

static void
log_handler_cb(const gchar *log_domain G_GNUC_UNUSED,
GLogLevelFlags log_level G_GNUC_UNUSED,
const gchar *message,
gpointer user_data G_GNUC_UNUSED)
{
g_print ("%s\n", message);
}

int
main(int argc, char *argv[])
{
int rc = EXIT_SUCCESS;
GSList *list = NULL;
GError *tmp_err = NULL;

g_log_set_handler("librepo", G_LOG_LEVEL_ERROR |
G_LOG_LEVEL_CRITICAL |
G_LOG_LEVEL_DEBUG |
G_LOG_LEVEL_WARNING,
log_handler_cb, NULL);

if (argc < 2) {
g_printerr("Usage: %s <mirror_1> <mirror_2> ...\n", argv[0]);
return EXIT_FAILURE;
}

for (int x = 1; x < argc; x++)
list = g_slist_prepend(list, argv[x]);
list = g_slist_reverse(list);

gboolean ret = lr_fastestmirror(NULL, &list, &tmp_err);
if (!ret) {
g_printerr("Error encountered: %s\n", tmp_err->message);
g_error_free(tmp_err);
rc = EXIT_FAILURE;
}

for (GSList *elem = list; elem; elem = g_slist_next(elem)) {
gchar *url = elem->data;
g_print("%s\n", url);
}

g_slist_free(list);

return rc;
}
4 changes: 3 additions & 1 deletion examples/python/yum_repo_simple_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import librepo

# Metalink URL
METALINK_URL = "https://mirrors.fedoraproject.org/metalink?repo=fedora-18&arch=x86_64"
METALINK_URL = "https://mirrors.fedoraproject.org/metalink?repo=fedora-19&arch=x86_64"

# Destination directory (note: This directory must exists!)
DESTDIR = "downloaded_metadata"
Expand All @@ -28,6 +28,8 @@
h.mirrorlist = METALINK_URL
# Destination directory for metadata
h.destdir = DESTDIR
# Use the fastest mirror
h.fastestmirror = True

try:
h.perform(r)
Expand Down
2 changes: 2 additions & 0 deletions librepo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SET (librepo_SRCS
checksum.c
downloader.c
downloadtarget.c
fastestmirror.c
gpg.c
handle.c
lrmirrorlist.c
Expand All @@ -19,6 +20,7 @@ SET (librepo_SRCS

SET(librepo_HEADERS
checksum.h
fastestmirror.h
gpg.h
handle.h
librepo.h
Expand Down
Loading

0 comments on commit acf458f

Please sign in to comment.