From 3153931ddb14cda5f912d56d9fe2760b81b15506 Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 27 Apr 2012 07:57:44 +0000 Subject: [PATCH] .uppdev git-svn-id: svn://ultimatepp.org/upp/trunk@4860 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppdev/ArrayCtrl/main.cpp | 153 +++++++++++--------- uppdev/FileSel/FileSel.upp | 18 +-- uppdev/FileSel/init | 4 + uppdev/FileSel/main.cpp | 60 ++++---- uppdev/HTTPClient/HTTPClient.cpp | 21 +-- uppdev/HTTPClient/HTTPClient.upp | 3 +- uppdev/HTTPClient/init | 1 + uppdev/MySQLSch/MySQLSch.cpp | 26 +++- uppdev/SQL_MySql/SQL_MySql.upp | 21 +-- uppdev/SQL_MySql/init | 4 + uppdev/SQL_MySql/main.cpp | 38 ++--- uppdev/SqlExp/SqlExp.cpp | 7 +- uppdev/SqlExp/SqlExp.upp | 21 +-- uppdev/google_upload/google_upload.cpp | 8 ++ uppdev/google_upload/google_upload.upp | 11 ++ uppdev/google_upload/init | 5 + uppdev/google_upload/up.py | 192 +++++++++++++++++++++++++ uppdev/testssl/init | 1 + uppdev/testssl/testssl.cpp | 20 ++- uppdev/testssl/testssl.upp | 3 +- 20 files changed, 444 insertions(+), 173 deletions(-) create mode 100644 uppdev/FileSel/init create mode 100644 uppdev/SQL_MySql/init create mode 100644 uppdev/google_upload/google_upload.cpp create mode 100644 uppdev/google_upload/google_upload.upp create mode 100644 uppdev/google_upload/init create mode 100644 uppdev/google_upload/up.py diff --git a/uppdev/ArrayCtrl/main.cpp b/uppdev/ArrayCtrl/main.cpp index f44b3f855..f3675f493 100644 --- a/uppdev/ArrayCtrl/main.cpp +++ b/uppdev/ArrayCtrl/main.cpp @@ -1,71 +1,82 @@ -#include - -using namespace Upp; - -struct App : TopWindow { - ArrayCtrl a, b; - Splitter s; - - StatusBar status; - - void DnD(PasteClip& d) - { - if(AcceptText(d)) - a.Add(GetString(d), GetString(d)); - } - - void DnDInsert(int line, PasteClip& d) - { - if(AcceptInternal(d, "array")) - a.InsertDrop(line, d); - if(AcceptText(d)) { - a.Insert(line); - a.Set(line, 0, GetString(d)); - a.SetCursor(line); - } - } - - void DnDInsertB(int line, PasteClip& d) - { - } - - void Drag() - { - } - - void DragB() - { - } - - typedef App CLASSNAME; - - App() { - a.AddColumn("\1Text alsdfjla fdlajd flajd falsjkd fla fals fj"); - a.MultiSelect(); - a.NoGrid(); - a.WhenDropInsert = THISBACK(DnDInsert); - a.WhenDrop = THISBACK(DnD); - a.WhenDrag = THISBACK(Drag); - - b.AddColumn("Text"); - b.MultiSelect(); - b.WhenDropInsert = THISBACK(DnDInsertB); - b.WhenDrag = THISBACK(DragB); - - Add(s.Horz(a, b)); - for(int i = 0; i < 200; i++) { - a.Add(i); - b.Add(FormatIntRoman(i, true)); - if((i & 3) == 0) - a.AddSeparator(); - } - Sizeable(); - AddFrame(status); - } -}; - -GUI_APP_MAIN -{ - DUMP("Test"); - App().Run(); -} +#include + +using namespace Upp; + +struct App : TopWindow { + ArrayCtrl a, b; + Splitter s; + + StatusBar status; + + void DnD(PasteClip& d) + { + if(AcceptText(d)) + a.Add(GetString(d), GetString(d)); + } + + void DnDInsert(int line, PasteClip& d) + { + if(AcceptInternal(d, "array")) + a.InsertDrop(line, d); + if(AcceptText(d)) { + a.Insert(line); + a.Set(line, 0, GetString(d)); + a.SetCursor(line); + } + } + + void DnDInsertB(int line, PasteClip& d) + { + } + + void Drag() + { + } + + void DragB() + { + } + + void A() + { + Exclamation("LeftDouble"); + } + + void B() + { + Exclamation("LeftClick"); + } + + typedef App CLASSNAME; + + App() { + a.AddColumn("\1Text alsdfjla fdlajd flajd falsjkd fla fals fj").HeaderTab().WhenLeftDouble = THISBACK(A); + a.AddColumn("asdf").HeaderTab().WhenLeftClick = THISBACK(B); + a.MultiSelect(); + a.NoGrid(); + a.WhenDropInsert = THISBACK(DnDInsert); + a.WhenDrop = THISBACK(DnD); + a.WhenDrag = THISBACK(Drag); + + b.AddColumn("Text"); + b.MultiSelect(); + b.WhenDropInsert = THISBACK(DnDInsertB); + b.WhenDrag = THISBACK(DragB); + + Add(s.Horz(a, b)); + for(int i = 0; i < 200; i++) { + a.Add(i); + b.Add(FormatIntRoman(i, true)); + if((i & 3) == 0) + a.AddSeparator(); + } + Sizeable(); + AddFrame(status); + } +}; + +GUI_APP_MAIN +{ + DUMP("Test"); + App().Run(); +} diff --git a/uppdev/FileSel/FileSel.upp b/uppdev/FileSel/FileSel.upp index 61fa029d4..5872304d3 100644 --- a/uppdev/FileSel/FileSel.upp +++ b/uppdev/FileSel/FileSel.upp @@ -1,9 +1,9 @@ -uses - CtrlLib; - -file - - "main.cpp"; - -mainconfig - "" = "GUI"; +uses + CtrlLib; + +file + main.cpp; + +mainconfig + "" = "GUI"; + diff --git a/uppdev/FileSel/init b/uppdev/FileSel/init new file mode 100644 index 000000000..1967588ed --- /dev/null +++ b/uppdev/FileSel/init @@ -0,0 +1,4 @@ +#ifndef _FileSel_icpp_init_stub +#define _FileSel_icpp_init_stub +#include "CtrlLib/init" +#endif diff --git a/uppdev/FileSel/main.cpp b/uppdev/FileSel/main.cpp index 12c66c937..593f0933b 100644 --- a/uppdev/FileSel/main.cpp +++ b/uppdev/FileSel/main.cpp @@ -1,30 +1,30 @@ -#include - -using namespace Upp; - -GUI_APP_MAIN -{ - SetDefaultCharset(CHARSET_UTF8); - FileSel fs; - String fn; - fs.BaseDir("U:\\"); - fs.AllFilesType() - .Type( t_("archive FIDE (txt)"), "*.txt") //type 1 - .Type( t_("archive VEG (csv)"), "*.csv;*.veg") //type 2 - .Type( t_("national archive with Fixed Length (txt)"), "*.txt") //type 3 - .Type( t_("archive FSI Italy (csv)"), "*.csv"); //type 4 - fs.DefaultExt("hhh"); - -// fs.NoMkDirOption(); -// fs.Multi(); -// fs.ActiveDir("/usr/include"); -// fs.NoEditFileName(); -// fs.ActiveDir("u:\\"); -// fs.PreSelect("U:/log.txt"); -// fs.ActiveType(3); - for(;;) { - if(!fs.ExecuteSaveAs()) - break; - PromptOK(DeQtf(~fs)); - } -} +#include + +using namespace Upp; + +GUI_APP_MAIN +{ + SetDefaultCharset(CHARSET_UTF8); + FileSel fs; + String fn; +// fs.BaseDir("U:\\"); + fs.AllFilesType() + .Type( t_("archive FIDE (txt)"), "*.txt") //type 1 + .Type( t_("archive VEG (csv)"), "*.csv;*.veg") //type 2 + .Type( t_("national archive with Fixed Length (txt)"), "*.txt") //type 3 + .Type( t_("archive FSI Italy (csv)"), "*.csv"); //type 4 + fs.DefaultExt("hhh"); + +// fs.NoMkDirOption(); +// fs.Multi(); +// fs.ActiveDir("/usr/include"); +// fs.NoEditFileName(); +// fs.ActiveDir("u:\\"); +// fs.PreSelect("U:/log.txt"); +// fs.ActiveType(3); + for(;;) { + if(!fs.ExecuteSaveAs()) + break; + PromptOK(DeQtf(~fs)); + } +} diff --git a/uppdev/HTTPClient/HTTPClient.cpp b/uppdev/HTTPClient/HTTPClient.cpp index 7eb174f41..c7fa08720 100644 --- a/uppdev/HTTPClient/HTTPClient.cpp +++ b/uppdev/HTTPClient/HTTPClient.cpp @@ -1,8 +1,13 @@ -#include - -using namespace Upp; - -CONSOLE_APP_MAIN -{ - Cout() << HttpClient("www.rosettacode.org").ExecuteRedirect(); -} +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + + HttpClient::Trace(); + HttpsClient h; + h.URL("www.google.com"); + h.Proxy("90.182.182.154", 8080); + DDUMP(h.ExecuteRedirect()); +} diff --git a/uppdev/HTTPClient/HTTPClient.upp b/uppdev/HTTPClient/HTTPClient.upp index b2181a7de..bea3b7924 100644 --- a/uppdev/HTTPClient/HTTPClient.upp +++ b/uppdev/HTTPClient/HTTPClient.upp @@ -1,6 +1,7 @@ uses Core, - Web; + Web, + Web/SSL; file HTTPClient.cpp; diff --git a/uppdev/HTTPClient/init b/uppdev/HTTPClient/init index 3da0e1708..206336fea 100644 --- a/uppdev/HTTPClient/init +++ b/uppdev/HTTPClient/init @@ -2,4 +2,5 @@ #define _HTTPClient_icpp_init_stub #include "Core/init" #include "Web/init" +#include "Web/SSL/init" #endif diff --git a/uppdev/MySQLSch/MySQLSch.cpp b/uppdev/MySQLSch/MySQLSch.cpp index 2c4b1f827..68233d976 100644 --- a/uppdev/MySQLSch/MySQLSch.cpp +++ b/uppdev/MySQLSch/MySQLSch.cpp @@ -2,18 +2,34 @@ using namespace Upp; +SQLID(ADDRESSBOOK); +SQLID(FIRSTNAME); +SQLID(ID); + CONSOLE_APP_MAIN { MySqlSession session; // substitute your 'username' and 'password' here: - if(!session.Connect("root", "heslo", "test", "10.0.0.19")) { + if(!session.Connect("root", "Passw0rd", "adrbook", "localhost")) { + DDUMP(session.GetErrorCodeString()); printf("Can't connect with MySql\n"); return; } - Sql sql(session); - sql.Execute("use test"); + SQL = session; + + session.SetTrace(); + + Sql sql; + sql.Execute("use adrbook"); sql.Execute("show tables"); while(sql.Fetch()) - Cout() << (String)sql[0] << '\n'; - SaveFile("u:/lego.sch", ExportSch(session, "test")); + DDUMP((String)sql[0]); + + SQL * Insert(ADDRESSBOOK)(FIRSTNAME, "Pepíček"); + + DDUMP(SQL.GetInsertedId()); + + sql * Select(SqlAll().Of(ADDRESSBOOK)).From(ADDRESSBOOK); + while(sql.Fetch()) + DDUMP(sql.GetRowMap()); } diff --git a/uppdev/SQL_MySql/SQL_MySql.upp b/uppdev/SQL_MySql/SQL_MySql.upp index aa08ff6ab..1de1c3e6e 100644 --- a/uppdev/SQL_MySql/SQL_MySql.upp +++ b/uppdev/SQL_MySql/SQL_MySql.upp @@ -1,10 +1,11 @@ -description "Logging to MySql"; - -uses - MySql; - -file - main.cpp; - -mainconfig - "" = "MT"; +description "Logging to MySql\377"; + +uses + MySql; + +file + main.cpp; + +mainconfig + "" = "MT"; + diff --git a/uppdev/SQL_MySql/init b/uppdev/SQL_MySql/init new file mode 100644 index 000000000..32cbf64c0 --- /dev/null +++ b/uppdev/SQL_MySql/init @@ -0,0 +1,4 @@ +#ifndef _SQL_MySql_icpp_init_stub +#define _SQL_MySql_icpp_init_stub +#include "MySql/init" +#endif diff --git a/uppdev/SQL_MySql/main.cpp b/uppdev/SQL_MySql/main.cpp index 647ed5a14..52d598b42 100644 --- a/uppdev/SQL_MySql/main.cpp +++ b/uppdev/SQL_MySql/main.cpp @@ -1,19 +1,19 @@ -#include - -using namespace Upp; - - -CONSOLE_APP_MAIN -{ - MySqlSession session; - // substitute your 'username' and 'password' here: - if(!session.Connect("root", "koblih", "mysql", "localhost")) { - printf("Can't connect with MySql\n"); - return; - } - Sql sql(session); - sql.Execute("use mysql"); - sql.Execute("show tables"); - while(sql.Fetch()) - Cout() << (String)sql[0] << '\n'; -} +#include + +using namespace Upp; + + +CONSOLE_APP_MAIN +{ + MySqlSession session; + // substitute your 'username' and 'password' here: + if(!session.Connect("root", "Passw0rd", "mysql", "localhost")) { + printf("Can't connect with MySql\n"); + return; + } + Sql sql(session); + sql.Execute("use mysql"); + sql.Execute("show tables"); + while(sql.Fetch()) + Cout() << (String)sql[0] << '\n'; +} diff --git a/uppdev/SqlExp/SqlExp.cpp b/uppdev/SqlExp/SqlExp.cpp index 7f59193ea..d8609db21 100644 --- a/uppdev/SqlExp/SqlExp.cpp +++ b/uppdev/SqlExp/SqlExp.cpp @@ -3,8 +3,6 @@ using namespace Upp; -#define SQLID(x) SqlId x(#x) - SQLID(COLUMN); SQLID(COLUMN1); SQLID(COLUMN2); @@ -39,6 +37,9 @@ void Put(String s, const char *splits) void Exp(const char *s, SqlStatement sql) { + DDUMP(s); + DDUMP(sql.Get(PGSQL)); + qtf << "\n:: "; Put(s, ".From;.Where;.OrderBy"); qtf << "\n:: "; @@ -47,6 +48,8 @@ void Exp(const char *s, SqlStatement sql) CONSOLE_APP_MAIN { + DLOG(SqlCompile(PGSQL, String().Cat() << '\t' << TABLE(COLUMN1, COLUMN2) << '\t' << " from \t" << TABLE << "\t")); +// return; qtf << "[C1 {{1:1 SqlExp C`+`+:: PostgreSQL"; EXP(Select(COLUMN).From(TABLE)); EXP(Select(COLUMN.Of(TABLE)).From(TABLE)); diff --git a/uppdev/SqlExp/SqlExp.upp b/uppdev/SqlExp/SqlExp.upp index 425847994..cdb63efe3 100644 --- a/uppdev/SqlExp/SqlExp.upp +++ b/uppdev/SqlExp/SqlExp.upp @@ -1,10 +1,11 @@ -uses - Core, - Sql, - RichText; - -file - SqlExp.cpp; - -mainconfig - "" = ""; +uses + Core, + Sql, + RichText; + +file + SqlExp.cpp; + +mainconfig + "" = ""; + diff --git a/uppdev/google_upload/google_upload.cpp b/uppdev/google_upload/google_upload.cpp new file mode 100644 index 000000000..245c62879 --- /dev/null +++ b/uppdev/google_upload/google_upload.cpp @@ -0,0 +1,8 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + +} diff --git a/uppdev/google_upload/google_upload.upp b/uppdev/google_upload/google_upload.upp new file mode 100644 index 000000000..51f7e45d5 --- /dev/null +++ b/uppdev/google_upload/google_upload.upp @@ -0,0 +1,11 @@ +uses + Core, + Web/SSL; + +file + up.py, + google_upload.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/uppdev/google_upload/init b/uppdev/google_upload/init new file mode 100644 index 000000000..b44bd5c57 --- /dev/null +++ b/uppdev/google_upload/init @@ -0,0 +1,5 @@ +#ifndef _google_upload_icpp_init_stub +#define _google_upload_icpp_init_stub +#include "Core/init" +#include "Web/SSL/init" +#endif diff --git a/uppdev/google_upload/up.py b/uppdev/google_upload/up.py new file mode 100644 index 000000000..dc8925aae --- /dev/null +++ b/uppdev/google_upload/up.py @@ -0,0 +1,192 @@ + + +def upload(file, project_name, user_name, password, summary, labels=None): + """Upload a file to a Google Code project's file server. + + Args: + file: The local path to the file. + project_name: The name of your project on Google Code. + user_name: Your Google account name. + password: The googlecode.com password for your account. + Note that this is NOT your global Google Account password! + summary: A small description for the file. + labels: an optional list of label strings with which to tag the file. + + Returns: a tuple: + http_status: 201 if the upload succeeded, something else if an + error occured. + http_reason: The human-readable string associated with http_status + file_url: If the upload succeeded, the URL of the file on Google + Code, None otherwise. + """ + # The login is the user part of user@gmail.com. If the login provided + # is in the full user@domain form, strip it down. + if user_name.endswith('@gmail.com'): + user_name = user_name[:user_name.index('@gmail.com')] + + form_fields = [('summary', summary)] + if labels is not None: + form_fields.extend([('label', l.strip()) for l in labels]) + + content_type, body = encode_upload_request(form_fields, file) + + upload_host = '%s.googlecode.com' % project_name + upload_uri = '/files' + auth_token = base64.b64encode('%s:%s'% (user_name, password)) + headers = { + 'Authorization': 'Basic %s' % auth_token, + 'User-Agent': 'Googlecode.com uploader v0.9.4', + 'Content-Type': content_type, + } + + server = httplib.HTTPSConnection(upload_host) + server.request('POST', upload_uri, body, headers) + resp = server.getresponse() + server.close() + + if resp.status == 201: + location = resp.getheader('Location', None) + else: + location = None + return resp.status, resp.reason, location + + +def encode_upload_request(fields, file_path): + """Encode the given fields and file into a multipart form body. + + fields is a sequence of (name, value) pairs. file is the path of + the file to upload. The file will be uploaded to Google Code with + the same file name. + + Returns: (content_type, body) ready for httplib.HTTP instance + """ + BOUNDARY = '----------Googlecode_boundary_reindeer_flotilla' + CRLF = '\r\n' + + body = [] + + # Add the metadata about the upload first + for key, value in fields: + body.extend( + ['--' + BOUNDARY, + 'Content-Disposition: form-data; name="%s"' % key, + '', + value, + ]) + + # Now add the file itself + file_name = os.path.basename(file_path) + f = open(file_path, 'rb') + file_content = f.read() + f.close() + + body.extend( + ['--' + BOUNDARY, + 'Content-Disposition: form-data; name="filename"; filename="%s"' + % file_name, + # The upload server determines the mime-type, no need to set it. + 'Content-Type: application/octet-stream', + '', + file_content, + ]) + + # Finalize the form body + body.extend(['--' + BOUNDARY + '--', '']) + + return 'multipart/form-data; boundary=%s' % BOUNDARY, CRLF.join(body) + + +def upload_find_auth(file_path, project_name, summary, labels=None, + user_name=None, password=None, tries=3): + """Find credentials and upload a file to a Google Code project's file server. + + file_path, project_name, summary, and labels are passed as-is to upload. + + Args: + file_path: The local path to the file. + project_name: The name of your project on Google Code. + summary: A small description for the file. + labels: an optional list of label strings with which to tag the file. + config_dir: Path to Subversion configuration directory, 'none', or None. + user_name: Your Google account name. + tries: How many attempts to make. + """ + + while tries > 0: + if user_name is None: + # Read username if not specified or loaded from svn config, or on + # subsequent tries. + sys.stdout.write('Please enter your googlecode.com username: ') + sys.stdout.flush() + user_name = sys.stdin.readline().rstrip() + if password is None: + # Read password if not loaded from svn config, or on subsequent tries. + print 'Please enter your googlecode.com password.' + print '** Note that this is NOT your Gmail account password! **' + print 'It is the password you use to access Subversion repositories,' + print 'and can be found here: http://code.google.com/hosting/settings' + password = getpass.getpass() + + status, reason, url = upload(file_path, project_name, user_name, password, + summary, labels) + # Returns 403 Forbidden instead of 401 Unauthorized for bad + # credentials as of 2007-07-17. + if status in [httplib.FORBIDDEN, httplib.UNAUTHORIZED]: + # Rest for another try. + user_name = password = None + tries = tries - 1 + else: + # We're done. + break + + return status, reason, url + + +def main(): + parser = optparse.OptionParser(usage='googlecode-upload.py -s SUMMARY ' + '-p PROJECT [options] FILE') + parser.add_option('-s', '--summary', dest='summary', + help='Short description of the file') + parser.add_option('-p', '--project', dest='project', + help='Google Code project name') + parser.add_option('-u', '--user', dest='user', + help='Your Google Code username') + parser.add_option('-w', '--password', dest='password', + help='Your Google Code password') + parser.add_option('-l', '--labels', dest='labels', + help='An optional list of comma-separated labels to attach ' + 'to the file') + + options, args = parser.parse_args() + + if not options.summary: + parser.error('File summary is missing.') + elif not options.project: + parser.error('Project name is missing.') + elif len(args) < 1: + parser.error('File to upload not provided.') + elif len(args) > 1: + parser.error('Only one file may be specified.') + + file_path = args[0] + + if options.labels: + labels = options.labels.split(',') + else: + labels = None + + status, reason, url = upload_find_auth(file_path, options.project, + options.summary, labels, + options.user, options.password) + if url: + print 'The file was uploaded successfully.' + print 'URL: %s' % url + return 0 + else: + print 'An error occurred. Your file was not uploaded.' + print 'Google Code upload server said: %s (%s)' % (reason, status) + return 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/uppdev/testssl/init b/uppdev/testssl/init index dfc32af4f..616066e5a 100644 --- a/uppdev/testssl/init +++ b/uppdev/testssl/init @@ -2,4 +2,5 @@ #define _testssl_icpp_init_stub #include "Core/init" #include "Web\SSL/init" +#include "Core/SSL/init" #endif diff --git a/uppdev/testssl/testssl.cpp b/uppdev/testssl/testssl.cpp index 98225b11a..2c083fc6b 100644 --- a/uppdev/testssl/testssl.cpp +++ b/uppdev/testssl/testssl.cpp @@ -1,7 +1,13 @@ -#include - -CONSOLE_APP_MAIN -{ - -} - +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + HttpClient::Trace(); + HttpsClient client; + client.URL("www.google.cz"); + DDUMP(client.Execute()); + +} + diff --git a/uppdev/testssl/testssl.upp b/uppdev/testssl/testssl.upp index 25991f11a..8a31aa8b0 100644 --- a/uppdev/testssl/testssl.upp +++ b/uppdev/testssl/testssl.upp @@ -1,6 +1,7 @@ uses Core, - Web\SSL; + Web\SSL, + Core/SSL; file testssl.cpp;