mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-06 20:45:54 +01:00
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:
parent
4b318070ca
commit
e749aedd34
2 changed files with 30 additions and 9 deletions
|
@ -48,6 +48,7 @@ import org.apache.http.client.methods.HttpPost;
|
|||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||
|
||||
|
@ -287,6 +288,22 @@ public class NetUtils {
|
|||
}
|
||||
} // 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 )
|
||||
{
|
||||
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( "lang", langStr ) );
|
||||
nvp.add( new BasicNameValuePair( "md5sum", sum ) );
|
||||
return runPost( post, nvp );
|
||||
String json = runPost( post, nvp );
|
||||
return urlFromJson( json );
|
||||
}
|
||||
|
||||
public static void checkVersions( Context context )
|
||||
|
@ -349,7 +367,8 @@ public class NetUtils {
|
|||
nvp.add( new BasicNameValuePair( "version",
|
||||
String.format( "%d",
|
||||
versionCode ) ) );
|
||||
String url = runPost( post, nvp );
|
||||
String json = runPost( post, nvp );
|
||||
String url = urlFromJson( json );
|
||||
if ( null != url ) {
|
||||
ApplicationInfo ai = pm.getApplicationInfo( packageName, 0);
|
||||
String label = pm.getApplicationLabel( ai ).toString();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# 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.
|
||||
|
||||
import logging, shelve, hashlib, sys
|
||||
import logging, shelve, hashlib, sys, json
|
||||
|
||||
k_suffix = '.xwd'
|
||||
k_filebase = "/var/www/"
|
||||
|
@ -56,21 +56,22 @@ def getDictSums():
|
|||
# public
|
||||
def curVersion( req, name, version ):
|
||||
global k_versions
|
||||
result = ""
|
||||
result = {}
|
||||
logging.debug( "version: " + version )
|
||||
if name in k_versions:
|
||||
if k_versions[name]['version'] > int(version):
|
||||
logging.debug( name + " is old" )
|
||||
result = k_urlbase + k_versions[name]['url']
|
||||
result['url'] = k_urlbase + k_versions[name]['url']
|
||||
result['success'] = True
|
||||
else:
|
||||
logging.debug(name + " is up-to-date")
|
||||
else:
|
||||
logging.debug( 'Error: bad name ' + name )
|
||||
return result
|
||||
return json.dumps( result )
|
||||
|
||||
# public
|
||||
def dictVersion( req, name, lang, md5sum ):
|
||||
result = ''
|
||||
result = {}
|
||||
if not name.endswith(k_suffix): name += k_suffix
|
||||
dictSums = getDictSums()
|
||||
path = lang + "/" + name
|
||||
|
@ -81,11 +82,12 @@ def dictVersion( req, name, lang, md5sum ):
|
|||
s_shelf['sums'] = dictSums
|
||||
if path in dictSums:
|
||||
if dictSums[path] != md5sum:
|
||||
result = k_urlbase + "and_wordlists/" + path
|
||||
result['url'] = k_urlbase + "and_wordlists/" + path
|
||||
result['success'] = True
|
||||
else:
|
||||
logging.debug( path + " not known" )
|
||||
s_shelf.close()
|
||||
return result
|
||||
return json.dumps( result )
|
||||
|
||||
def clearShelf():
|
||||
shelf = shelve.open(k_shelfFile)
|
||||
|
|
Loading…
Add table
Reference in a new issue