summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-11-26 22:03:38 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-11-26 22:03:38 +0900
commit83983c560a44e8f6025893c8aae8db94c3370342 (patch)
tree36050daea9b1f76a77063fcd5b6f765645e13312
parent4345456ff42414d9ddccdb231e2cfce2a4f7a41d (diff)
tool has nicer .. progress
-rw-r--r--mrk.c32
-rw-r--r--mrklib.h2
-rw-r--r--mrklib_package.c12
-rw-r--r--mrklib_svc.c5
4 files changed, 40 insertions, 11 deletions
diff --git a/mrk.c b/mrk.c
index f75e4ca..d9b802f 100644
--- a/mrk.c
+++ b/mrk.c
@@ -31,23 +31,36 @@ _cb_disconnect(void *data, Mrk *server)
31} 31}
32 32
33static void 33static void
34status(double pos)
35{
36 int i, p;
37
38 p = pos * 60;
39 putchar('\r');
40 putchar('[');
41 for (i = 0; i < p; i++) putchar('#');
42 printf("] %2.1f%%", pos * 100.0);
43}
44
45static void
34_cb_upload_begin(void *data, Mrk *server) 46_cb_upload_begin(void *data, Mrk *server)
35{ 47{
36 printf("["); 48 status(0.0);
37 fflush(stdout); 49 fflush(stdout);
38} 50}
39 51
40static void 52static void
41_cb_upload_progress(void *data, Mrk *server, double pos) 53_cb_upload_progress(void *data, Mrk *server, double pos)
42{ 54{
43 printf("%1.02f_", pos); 55 status(pos);
44 fflush(stdout); 56 fflush(stdout);
45} 57}
46 58
47static void 59static void
48_cb_upload_end(void *data, Mrk *server) 60_cb_upload_end(void *data, Mrk *server)
49{ 61{
50 printf("]\n"); 62 status(1.0);
63 printf("\n");
51 fflush(stdout); 64 fflush(stdout);
52} 65}
53 66
@@ -61,21 +74,22 @@ _cb_upload_success(void *data, Mrk *server, Eina_Bool success)
61static void 74static void
62_cb_download_begin(void *data, Mrk *server) 75_cb_download_begin(void *data, Mrk *server)
63{ 76{
64 printf("["); 77 status(0.0);
65 fflush(stdout); 78 fflush(stdout);
66} 79}
67 80
68static void 81static void
69_cb_download_progress(void *data, Mrk *server, double pos) 82_cb_download_progress(void *data, Mrk *server, double pos)
70{ 83{
71 printf("%1.02f_", pos); 84 status(pos);
72 fflush(stdout); 85 fflush(stdout);
73} 86}
74 87
75static void 88static void
76_cb_download_end(void *data, Mrk *server) 89_cb_download_end(void *data, Mrk *server)
77{ 90{
78 printf("]\n"); 91 status(1.0);
92 printf("\n");
79 fflush(stdout); 93 fflush(stdout);
80} 94}
81 95
@@ -100,7 +114,8 @@ _cb_download_success(void *data, Mrk *server, const char *file)
100 } 114 }
101 else if (install_bin) 115 else if (install_bin)
102 { 116 {
103 if (!mrk_package_bin_install(file)) _mrk_err("Failed to install\n"); 117 if (!mrk_package_bin_install(file, os, arch))
118 _mrk_err("Failed to install\n");
104 if (!mrk_package_bin_clean()) _mrk_err("Failed to clean\n"); 119 if (!mrk_package_bin_clean()) _mrk_err("Failed to clean\n");
105 ecore_file_unlink(file); 120 ecore_file_unlink(file);
106 } 121 }
@@ -209,7 +224,8 @@ main(int argc, char **argv)
209 else if (!strcmp(argv[1], "inst")) 224 else if (!strcmp(argv[1], "inst"))
210 { 225 {
211 if (argc < 2) _mrk_err("Must provide FILE.MKB\n"); 226 if (argc < 2) _mrk_err("Must provide FILE.MKB\n");
212 if (!mrk_package_bin_install(argv[2])) _mrk_err("Failed to install\n"); 227 if (!mrk_package_bin_install(argv[2], os, arch))
228 _mrk_err("Failed to install\n");
213 if (!mrk_package_bin_clean()) _mrk_err("Failed to clean\n"); 229 if (!mrk_package_bin_clean()) _mrk_err("Failed to clean\n");
214 } 230 }
215 else if (!strcmp(argv[1], "clean")) 231 else if (!strcmp(argv[1], "clean"))
diff --git a/mrklib.h b/mrklib.h
index ac87880..3d0e839 100644
--- a/mrklib.h
+++ b/mrklib.h
@@ -133,7 +133,7 @@ EAPI Eina_Bool mrk_build_package_src(Mrk_Build *bld, const char *buildfile, con
133 133
134EAPI Eina_Bool mrk_package_src_extract(const char *file, const char *dst); 134EAPI Eina_Bool mrk_package_src_extract(const char *file, const char *dst);
135EAPI Eina_Bool mrk_package_bin_clean(void); 135EAPI Eina_Bool mrk_package_bin_clean(void);
136EAPI Eina_Bool mrk_package_bin_install(const char *file); 136EAPI Eina_Bool mrk_package_bin_install(const char *file, const char *os, const char *arch);
137EAPI Eina_Bool mrk_package_bin_remove(const char *name); 137EAPI Eina_Bool mrk_package_bin_remove(const char *name);
138 138
139// XXX: .mrk parsing api handled/exposed and other related functions 139// XXX: .mrk parsing api handled/exposed and other related functions
diff --git a/mrklib_package.c b/mrklib_package.c
index a355317..25154d4 100644
--- a/mrklib_package.c
+++ b/mrklib_package.c
@@ -156,7 +156,7 @@ mrk_package_bin_clean(void)
156} 156}
157 157
158EAPI Eina_Bool 158EAPI Eina_Bool
159mrk_package_bin_install(const char *file) 159mrk_package_bin_install(const char *file, const char *os, const char *arch)
160{ 160{
161 Eet_File *ef, *ef2; 161 Eet_File *ef, *ef2;
162#define err(reason) do { fprintf(stderr, "%s\n", reason); goto error; } while (0) 162#define err(reason) do { fprintf(stderr, "%s\n", reason); goto error; } while (0)
@@ -173,7 +173,17 @@ mrk_package_bin_install(const char *file)
173 char *s; 173 char *s;
174 Eina_List *files; 174 Eina_List *files;
175 char *name; 175 char *name;
176 char *str;
176 177
178 str = read_string(ef, "arch");
179 if (!str) err("no arch");
180 snprintf(tmp, sizeof(tmp), "%s-%s", os, arch);
181 if (strcmp(tmp, str))
182 {
183 free(str);
184 err("arch mismatch\n");
185 }
186 free(str);
177 name = read_string(ef, "name"); 187 name = read_string(ef, "name");
178 if (!name) err("no name"); 188 if (!name) err("no name");
179 if (!_mrk_util_plain_file_check(name)) err("name failed sanity check"); 189 if (!_mrk_util_plain_file_check(name)) err("name failed sanity check");
diff --git a/mrklib_svc.c b/mrklib_svc.c
index c6a8a7f..0532e3d 100644
--- a/mrklib_svc.c
+++ b/mrklib_svc.c
@@ -191,11 +191,14 @@ fail:
191 } 191 }
192 else if ((e->minor == M_DOWN_DATA) || (e->minor == M_SRC_DATA)) 192 else if ((e->minor == M_DOWN_DATA) || (e->minor == M_SRC_DATA))
193 { 193 {
194 double pos = 0.5;
195
196 if (e->ref_to > 0) pos = (double)e->ref / (double)e->ref_to;
194 if ((server->f) && (e->data) && (e->size > 0) && (e->size <= 10000)) 197 if ((server->f) && (e->data) && (e->size > 0) && (e->size <= 10000))
195 { 198 {
196 fwrite(e->data, e->size, 1, server->f); 199 fwrite(e->data, e->size, 1, server->f);
197 if (server->func.download_progress) 200 if (server->func.download_progress)
198 server->func.download_progress(server->data.download_progress, server, 0.5); 201 server->func.download_progress(server->data.download_progress, server, pos);
199 } 202 }
200 return EINA_TRUE; 203 return EINA_TRUE;
201 } 204 }