diff options
author | Nick White <arch@njw.me.uk> | 2007-03-07 01:25:23 +0000 |
---|---|---|
committer | Nick White <arch@njw.me.uk> | 2007-03-07 01:25:23 +0000 |
commit | 49472a3a8ff731dcccd8099c4070119426c49145 (patch) | |
tree | 2f50580a790ddcfddbd1329727c95caf354a295b | |
parent | 38d38ea919c6a2e3faeaee0b036607259f7a428c (diff) |
various checks & cleanups, default usage, hook script
Add file valid checks to update
Add file checks to parse contents
Remove empty files which don't download
Automatically attempt to update contents if they cannot be opened
Add default showopts if no options are passed
Remove show struct mention in usage
Move order of usage
Add alternative media toc file option
Added commit hook script
git-archimport-id: getht@sv.gnu.org/getht--mainline--0.1--patch-6
-rw-r--r-- | TODO | 30 | ||||
-rw-r--r-- | download.c | 11 | ||||
-rw-r--r-- | getht.c | 93 | ||||
-rw-r--r-- | mediarev.c | 4 | ||||
-rw-r--r-- | mediaxml.c | 3 |
5 files changed, 104 insertions, 37 deletions
@@ -1,46 +1,40 @@ -savannah- -add news, with current status, likely time to usability, & hello - add todo to tasks tracker post a screenshot? -immediate term- -if download fails, remove attempted file -if -uf is passed, download & parse media regardless (check that same isn't added multiple times) +add to docs email hook & script - see http://www.gnuarch.org/gnuarchwiki/Using_hooks + +check if file exists but is empty handle ctrl-c by removing half-downloaded file save entered directories to config file -utilise and expand initial clean procedures +?utilise and expand initial clean procedures add sorting algo for issues, only needs a few pointers passing around, use temp iss* look online for v. basic sorting algos or write own then no more latest_iss pointer needed -add if file is readable checks to appropriate functions e.g. reading xml / rev and handle appropriately - -add new source file for freeing memory plus mem error functions - -handle file errors better - -malloc- -include cover as just another section entry - malloc sections, items, and media will ensure ease of finding existance, as no_of_sections no_of_media no_of_items can be used (embedded in struct) -handle smil files successfully +include cover as just another section entry -if no required contents file exists, attempt to retrieve it, even if update is not passed -comment source - at least all functions +add new source file for freeing memory plus mem error functions -#use autotools -integrate gettext +-other- + +#autotools +gettext + +handle smil files successfully add options to allow decent listing of issues add options to allow downloading of any issue @@ -44,7 +44,7 @@ extern char proxy_user[STR_MAX]; extern char proxy_pass[STR_MAX]; extern CURL *main_curl_handle; -void save_file(CURL *curl_handle, char *url, char *filepath) +int save_file(CURL *curl_handle, char *url, char *filepath) /* Save the file *url to *filepath */ { printf("Downloading %s\n",url); @@ -55,7 +55,10 @@ void save_file(CURL *curl_handle, char *url, char *filepath) if(curl_handle) { FILE *file; if((file = fopen(filepath,"w")) == NULL) + { fprintf(stderr,"Error: cannot open file %s for writing.\n",filepath); + return 1; + } curl_easy_setopt(curl_handle, CURLOPT_URL, url); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_func); @@ -98,7 +101,11 @@ void save_file(CURL *curl_handle, char *url, char *filepath) curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, update_progress); if(curl_easy_perform(curl_handle)) + { + remove(filepath); fprintf(stderr,"Error, could not download %s\n",url); + return 1; + } /* double d; curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &d); @@ -117,7 +124,9 @@ void save_file(CURL *curl_handle, char *url, char *filepath) else { fprintf(stderr,"Error: curl failed to initialise.\n"); printf("Could not download %s\n",url); + return 1; } + return 0; } int update_progress(void *data, double dltotal, double dlnow, @@ -31,6 +31,10 @@ #include "issue.h" #include "getht.h" +int update_contents_files(); + +med * findnewestmed(iss ** issue, int no_of_issues); + void show_iss_struct(iss ** issue, int no_of_issues); void show_med_struct(med * issue); @@ -39,8 +43,6 @@ void cleariss(iss * cur_issue); void showusage(); -med * findnewestmed(iss ** issue, int no_of_issues); - proxytype proxy_type; char proxy_addr[STR_MAX]; long proxy_port; proxyauth proxy_auth; char proxy_user[STR_MAX]; char proxy_pass[STR_MAX]; @@ -73,6 +75,7 @@ int main(int argc, char *argv[]) int downallmedia = 0, downlatestmedia = 0; int downissue = 0, downmedia = 0; int force = 0, update = 0, showstr = 0; + int option = 0; proxy_type = NONE; proxy_port = 0; @@ -105,39 +108,52 @@ int main(int argc, char *argv[]) {"force", no_argument, 0, 'f'}, {"update", no_argument, 0, 'u'}, {"tocfile", required_argument, 0, 't'}, + {"mediatocfile", required_argument, 0, 'x'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, {0, 0, 0, 0} }; - while((c = getopt_long(argc, argv, "adfhmnsuvxt:", long_opts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "adfhmnsuvx:t:", long_opts, NULL)) != -1) { switch(c) { case 'a': downall = 1; downissue = 1; + option = 1; break; case 'd': downlatest = 1; downissue = 1; + option = 1; break; case 'm': downallmedia = 1; downmedia = 1; + option = 1; break; case 'n': downlatestmedia = 1; downmedia = 1; + option = 1; break; case 'f': force = 1; + option = 1; break; case 'u': update = 1; + option = 1; break; case 's': showstr = 1; + option = 1; break; case 't': strcpy(issue_xml, strdup(optarg)); + option = 1; + break; + case 'x': + strcpy(media_xml, strdup(optarg)); + option = 1; break; case 'h': showusage(); @@ -145,6 +161,7 @@ int main(int argc, char *argv[]) break; case 'v': printf("GetHT version: %s\n",VERSION); + option = 1; return 0; break; default: @@ -152,12 +169,18 @@ int main(int argc, char *argv[]) } } + if(!option) + { + showusage(); + return 0; + } + main_curl_handle = curl_easy_init(); if(update) { - if(update_contents_files(NULL, NULL)) - fprintf(stderr,"Could not update contents files"); + if(update_contents_files()) + fprintf(stderr,"Could not update contents files\n"); } /* Parse TOC, filling issue structure */ @@ -171,6 +194,22 @@ int main(int argc, char *argv[]) { issue = parsetoc(issue_xml, &no_of_issues, &latest_index); + if(!issue) + { + if(!update) + { + printf("Cannot open contents file, trying to update contents\n"); + if(update_contents_files()) + return 1; + issue = parsetoc(issue_xml, &no_of_issues, &latest_index); + } + else + { + printf("Cannot open contents file, try running `getht --update`\n"); + return 1; + } + } + if(showstr) show_iss_struct(issue, no_of_issues); @@ -198,6 +237,22 @@ int main(int argc, char *argv[]) issue = parsemedia(media_xml, issue, &no_of_issues); + if(!issue) + { + if(!update) + { + printf("Cannot open media contents file, trying to update contents\n"); + if(update_contents_files()) + return 1; + issue = parsemedia(media_xml, issue, &no_of_issues); + } + else + { + printf("Cannot open contents file, try running `getht --update`\n"); + return 1; + } + } + if(downlatestmedia) { newest = findnewestiss(issue, no_of_issues); @@ -228,25 +283,29 @@ int main(int argc, char *argv[]) return 0; } -int update_contents_files(CURL *curl_handle, int temp) +int update_contents_files() /* Returns 0 on success, 1 on failure */ { - save_file(NULL, XML_TOC_URL, issue_xml); + if(save_file(NULL, XML_TOC_URL, issue_xml)) + return 1; - /* see if current issue's media toc has already - been written to the xml, if not do so */ - char isstitle[STR_MAX]; issdates date; + /* see if current issue's media toc has already + been written to the xml, if not do so */ if(access(issue_xml, R_OK) == 0) - cur_identifiers(issue_xml, isstitle, &date); + { + if(cur_identifiers(issue_xml, isstitle, &date)) + return 1; + } else return 1; if(media_accounted_for(media_xml, &date)) { - save_file(curl_handle, MEDIA_TOC_URL, media_rev); + if(save_file(NULL, MEDIA_TOC_URL, media_rev)) + return 1; med temp_med[MED_NO]; @@ -257,7 +316,8 @@ int update_contents_files(CURL *curl_handle, int temp) cur_identifiers(issue_xml, isstitle, &date); int med_no = -1; - parsemediagz(media_rev, temp_med, &med_no); + if(parsemediagz(media_rev, temp_med, &med_no)) + return 1; /* BUG: this blanks title too... strange * Until we can find why, just get the title again */ cur_identifiers(issue_xml, isstitle, &date); @@ -398,15 +458,14 @@ int findnewestiss(iss ** issue, int no_of_issues) void showusage() { printf("Usage: getht -u -a -d -m -n -f [-t tocfile] -h -v\n"); + printf("-u | --update Update contents files\n"); printf("-a | --download-all Download all issues\n"); printf("-d | --download-latest Download latest issue\n"); printf("-m | --download-all-media Download all media\n"); printf("-n | --download-latest-media Download latest issue's media\n"); - printf("-f | --force Force redownloading of existent issues\n"); - printf("-u | --update Update contents files\n"); + printf("-f | --force Force re-download of existing files\n"); printf("-t | --tocfile file Use alternative contents xml file\n"); + printf("-x | --mediatocfile file Use alternative media contents xml file\n"); printf("-h | --help Print this help message\n"); printf("-v | --version Print version information\n"); - printf(" ---DEBUGGING--\n"); - printf("-s Print structure information\n"); } @@ -77,6 +77,10 @@ int parsemediagz(char * media_path, med * cur_media, int * no_of_media) } strcpy(cur_line,""); /* reset cur_line */ } + + if(*no_of_media == -1) + return 1; + return 0; } @@ -132,7 +132,8 @@ iss ** parsemedia(char * filepath, iss ** issue, int * no_of_issues) xmlDocPtr media_file; xmlNodePtr node, itnode; - ready_xml(filepath, "media", &media_file, &node); + if(ready_xml(filepath, "media", &media_file, &node)) + return NULL; *node = *node->xmlChildrenNode; |