return url inside a json rather than just a url for more flexibility

and so python's error messages don't trigger Notifications that then
fail.
This commit is contained in:
Eric House 2012-08-15 18:55:54 -07:00
parent 4b318070ca
commit e749aedd34
2 changed files with 30 additions and 9 deletions

View file

@ -48,6 +48,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.jni.CommonPrefs;
@ -287,6 +288,22 @@ public class NetUtils {
} }
} // sendToRelay } // sendToRelay
private static String urlFromJson( String json )
{
String result = null;
if ( null != json ) {
try {
JSONObject jobj = new JSONObject( json );
if ( null != jobj && jobj.has( "url" ) ) {
result = jobj.getString( "url" );
}
} catch ( org.json.JSONException jse ) {
DbgUtils.loge( jse );
}
}
return result;
}
private static HttpPost makePost( String proc ) private static HttpPost makePost( String proc )
{ {
return new HttpPost("http://www.eehouse.org/xw4/info.py/" + proc); return new HttpPost("http://www.eehouse.org/xw4/info.py/" + proc);
@ -327,7 +344,8 @@ public class NetUtils {
nvp.add( new BasicNameValuePair( "name", dal.name ) ); nvp.add( new BasicNameValuePair( "name", dal.name ) );
nvp.add( new BasicNameValuePair( "lang", langStr ) ); nvp.add( new BasicNameValuePair( "lang", langStr ) );
nvp.add( new BasicNameValuePair( "md5sum", sum ) ); nvp.add( new BasicNameValuePair( "md5sum", sum ) );
return runPost( post, nvp ); String json = runPost( post, nvp );
return urlFromJson( json );
} }
public static void checkVersions( Context context ) public static void checkVersions( Context context )
@ -349,7 +367,8 @@ public class NetUtils {
nvp.add( new BasicNameValuePair( "version", nvp.add( new BasicNameValuePair( "version",
String.format( "%d", String.format( "%d",
versionCode ) ) ); versionCode ) ) );
String url = runPost( post, nvp ); String json = runPost( post, nvp );
String url = urlFromJson( json );
if ( null != url ) { if ( null != url ) {
ApplicationInfo ai = pm.getApplicationInfo( packageName, 0); ApplicationInfo ai = pm.getApplicationInfo( packageName, 0);
String label = pm.getApplicationLabel( ai ).toString(); String label = pm.getApplicationLabel( ai ).toString();

View file

@ -3,7 +3,7 @@
# the client's version is up-to-date or with the newer version if it's # the client's version is up-to-date or with the newer version if it's
# not. May include md5 sums in liu of versions for .xwd files. # not. May include md5 sums in liu of versions for .xwd files.
import logging, shelve, hashlib, sys import logging, shelve, hashlib, sys, json
k_suffix = '.xwd' k_suffix = '.xwd'
k_filebase = "/var/www/" k_filebase = "/var/www/"
@ -56,21 +56,22 @@ def getDictSums():
# public # public
def curVersion( req, name, version ): def curVersion( req, name, version ):
global k_versions global k_versions
result = "" result = {}
logging.debug( "version: " + version ) logging.debug( "version: " + version )
if name in k_versions: if name in k_versions:
if k_versions[name]['version'] > int(version): if k_versions[name]['version'] > int(version):
logging.debug( name + " is old" ) logging.debug( name + " is old" )
result = k_urlbase + k_versions[name]['url'] result['url'] = k_urlbase + k_versions[name]['url']
result['success'] = True
else: else:
logging.debug(name + " is up-to-date") logging.debug(name + " is up-to-date")
else: else:
logging.debug( 'Error: bad name ' + name ) logging.debug( 'Error: bad name ' + name )
return result return json.dumps( result )
# public # public
def dictVersion( req, name, lang, md5sum ): def dictVersion( req, name, lang, md5sum ):
result = '' result = {}
if not name.endswith(k_suffix): name += k_suffix if not name.endswith(k_suffix): name += k_suffix
dictSums = getDictSums() dictSums = getDictSums()
path = lang + "/" + name path = lang + "/" + name
@ -81,11 +82,12 @@ def dictVersion( req, name, lang, md5sum ):
s_shelf['sums'] = dictSums s_shelf['sums'] = dictSums
if path in dictSums: if path in dictSums:
if dictSums[path] != md5sum: if dictSums[path] != md5sum:
result = k_urlbase + "and_wordlists/" + path result['url'] = k_urlbase + "and_wordlists/" + path
result['success'] = True
else: else:
logging.debug( path + " not known" ) logging.debug( path + " not known" )
s_shelf.close() s_shelf.close()
return result return json.dumps( result )
def clearShelf(): def clearShelf():
shelf = shelve.open(k_shelfFile) shelf = shelve.open(k_shelfFile)