diff -Nru pushbullet-commons-0.4.0/data/es.atareao.pushbullet.service pushbullet-commons-0.5.6/data/es.atareao.pushbullet.service --- pushbullet-commons-0.4.0/data/es.atareao.pushbullet.service 2014-05-11 11:41:02.000000000 +0000 +++ pushbullet-commons-0.5.6/data/es.atareao.pushbullet.service 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -# Service file: /usr/share/dbus-1/services/es.atareao.pushbullet.service -[D-BUS Service] -Name=es.atareao.pushbullet -Exec="/opt/extras.ubuntu.com/pushbullet-commons/share/pushbullet-commons/pushbullet_service.py" diff -Nru pushbullet-commons-0.4.0/data/icons/address.svg pushbullet-commons-0.5.6/data/icons/address.svg --- pushbullet-commons-0.4.0/data/icons/address.svg 2014-05-04 17:10:26.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/address.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/android.svg pushbullet-commons-0.5.6/data/icons/android.svg --- pushbullet-commons-0.4.0/data/icons/android.svg 2015-03-01 20:10:31.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/android.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ - - - - - - - image/svg+xml - - - - - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/file.svg pushbullet-commons-0.5.6/data/icons/file.svg --- pushbullet-commons-0.4.0/data/icons/file.svg 2014-05-04 17:11:10.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/file.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/image.svg pushbullet-commons-0.5.6/data/icons/image.svg --- pushbullet-commons-0.4.0/data/icons/image.svg 2015-03-14 18:25:37.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/image.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/ios.svg pushbullet-commons-0.5.6/data/icons/ios.svg --- pushbullet-commons-0.4.0/data/icons/ios.svg 2015-03-01 20:10:19.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/ios.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ - - - - - - - image/svg+xml - - - - - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/link.svg pushbullet-commons-0.5.6/data/icons/link.svg --- pushbullet-commons-0.4.0/data/icons/link.svg 2014-05-04 17:11:47.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/link.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/list.svg pushbullet-commons-0.5.6/data/icons/list.svg --- pushbullet-commons-0.4.0/data/icons/list.svg 2014-05-04 17:09:44.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/list.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/note.svg pushbullet-commons-0.5.6/data/icons/note.svg --- pushbullet-commons-0.4.0/data/icons/note.svg 2014-05-04 16:49:10.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/note.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pomodoro-indicator-light-00.svg pushbullet-commons-0.5.6/data/icons/pomodoro-indicator-light-00.svg --- pushbullet-commons-0.4.0/data/icons/pomodoro-indicator-light-00.svg 2014-05-09 20:09:23.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pomodoro-indicator-light-00.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pomodoro-indicator-light-01.svg pushbullet-commons-0.5.6/data/icons/pomodoro-indicator-light-01.svg --- pushbullet-commons-0.4.0/data/icons/pomodoro-indicator-light-01.svg 2014-05-09 20:10:02.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pomodoro-indicator-light-01.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-dark.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-dark.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-dark.svg 2014-05-01 11:56:48.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-dark.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-light.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-light.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-light.svg 2014-05-01 11:56:04.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-light.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync0-dark.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync0-dark.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync0-dark.svg 2014-05-03 06:26:34.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync0-dark.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync0-light.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync0-light.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync0-light.svg 2014-05-03 06:22:53.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync0-light.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync1-dark.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync1-dark.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync1-dark.svg 2014-05-03 06:26:22.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync1-dark.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync1-light.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync1-light.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync1-light.svg 2014-05-03 06:23:17.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync1-light.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync2-dark.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync2-dark.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync2-dark.svg 2014-05-03 06:26:05.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync2-dark.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync2-light.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync2-light.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync2-light.svg 2014-05-03 06:24:33.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync2-light.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync3-dark.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync3-dark.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync3-dark.svg 2014-05-03 06:25:39.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync3-dark.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync3-light.svg pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync3-light.svg --- pushbullet-commons-0.4.0/data/icons/pushbullet-indicator-sync3-light.svg 2014-05-03 06:22:35.000000000 +0000 +++ pushbullet-commons-0.5.6/data/icons/pushbullet-indicator-sync3-light.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - diff -Nru pushbullet-commons-0.4.0/debian/changelog pushbullet-commons-0.5.6/debian/changelog --- pushbullet-commons-0.4.0/debian/changelog 2015-03-28 06:16:41.000000000 +0000 +++ pushbullet-commons-0.5.6/debian/changelog 2016-07-23 10:49:34.000000000 +0000 @@ -1,12 +1,56 @@ -pushbullet-commons (0.4.0-0extras14.04.1) trusty; urgency=medium +pushbullet-commons (0.5.6-0extras16.04.4) xenial; urgency=medium + * Added SendToDialog + + -- Lorenzo Carbonell Sat, 23 Jul 2016 12:49:27 +0200 + +pushbullet-commons (0.5.5-0extras16.04.2) xenial; urgency=medium + + * Added progreso dialog + + -- Lorenzo Carbonell Sun, 03 Jul 2016 20:08:25 +0200 + +pushbullet-commons (0.5.4-0extras16.04.0) xenial; urgency=medium + + * do in backgrounds several targets + + -- Lorenzo Carbonell Sat, 02 Jul 2016 12:41:15 +0200 + +pushbullet-commons (0.5.3-0extras16.04.2) xenial; urgency=medium + + * Added encryption to dimissal + * Added python2-3 compatibility + + -- Lorenzo Carbonell Sat, 02 Jul 2016 12:33:12 +0200 + +pushbullet-commons (0.5.2-0extras16.04.0) xenial; urgency=medium + + * Added dimissal + + -- Lorenzo Carbonell Mon, 27 Jun 2016 14:49:38 +0200 + +pushbullet-commons (0.5.1-0extras16.04.1) xenial; urgency=medium + + * Added decrypt + + -- Lorenzo Carbonell Mon, 27 Jun 2016 00:09:55 +0200 + +pushbullet-commons (0.5.0-0extras16.04.1) xenial; urgency=medium + + * No dbus dependecy + + -- Lorenzo Carbonell Sun, 26 Jun 2016 19:30:50 +0200 + +pushbullet-commons (0.4.0-0extras14.04.2) trusty; urgency=medium + + [ Lorenzo Carbonell ] * All dialogs and images here * Added restart option * Added securities * Added Python 2.7 compatibility * Send SMS - -- Lorenzo Carbonell Sat, 28 Mar 2015 07:16:32 +0100 + -- atareao Sat, 20 Jun 2015 19:41:37 +0200 pushbullet-commons (0.3.1-0extras14.04.0) trusty; urgency=medium diff -Nru pushbullet-commons-0.4.0/debian/control pushbullet-commons-0.5.6/debian/control --- pushbullet-commons-0.4.0/debian/control 2014-05-11 19:01:19.000000000 +0000 +++ pushbullet-commons-0.5.6/debian/control 2016-07-23 10:08:24.000000000 +0000 @@ -9,7 +9,10 @@ Package: pushbullet-commons Architecture: all Depends: ${misc:Depends}, ${python:Depends}, - python3-dbus, - python3-requests + gir1.2-gtk-3.0, + gir1.2-gdkpixbuf-2.0, + gir1.2-webkit-3.0, + python3-requests, + python3-cryptography Description: A library to work width pushbullet This library is necessary for pushbullet indicator and other applications diff -Nru pushbullet-commons-0.4.0/setup.py pushbullet-commons-0.5.6/setup.py --- pushbullet-commons-0.4.0/setup.py 2015-03-15 06:07:38.000000000 +0000 +++ pushbullet-commons-0.5.6/setup.py 2016-06-26 17:30:42.000000000 +0000 @@ -8,7 +8,7 @@ from distutils import cmd from distutils.command.install_data import install_data as _install_data from distutils.command.build import build as _build - + import msgfmt import os import glob @@ -19,25 +19,29 @@ import ConfigParser import codecs +USRDIR = '/opt/extras.ubuntu.com/pushbullet-commons' + DATA_FILES = [ - ('/opt/extras.ubuntu.com/pushbullet-commons/share/pushbullet-commons',['debian/changelog']), - ('/opt/extras.ubuntu.com/pushbullet-commons/share/pushbullet-commons',glob.glob('src/*.py')), - ('/opt/extras.ubuntu.com/pushbullet-commons/share/pushbullet-commons/icons',glob.glob('data/icons/*.svg')), - ('/usr/share/dbus-1/services',['data/es.atareao.pushbullet.service']), - ] + (os.path.join(USRDIR, 'share/pushbullet-commons'), + ['debian/changelog']), + (os.path.join(USRDIR, 'share/pushbullet-commons'), + glob.glob('src/*.py')), + (os.path.join(USRDIR, 'share/pushbullet-commons/icons'), + glob.glob('data/icons/*.svg')), + ] MAIN_DIR = os.getcwd() -DATA_DIR = os.path.join(MAIN_DIR,'data') -DEBIAN_DIR = os.path.join(MAIN_DIR,'debian') -LANGUAGES_DIR = os.path.join(MAIN_DIR,'po') -SRC_DIR = os.path.join(MAIN_DIR,'src') -TEMPLATE = os.path.join(LANGUAGES_DIR,'po.pot') -CHANGELOG = os.path.join(DEBIAN_DIR,'changelog') -f = open(CHANGELOG,'r') +DATA_DIR = os.path.join(MAIN_DIR, 'data') +DEBIAN_DIR = os.path.join(MAIN_DIR, 'debian') +LANGUAGES_DIR = os.path.join(MAIN_DIR, 'po') +SRC_DIR = os.path.join(MAIN_DIR, 'src') +TEMPLATE = os.path.join(LANGUAGES_DIR, 'po.pot') +CHANGELOG = os.path.join(DEBIAN_DIR, 'changelog') +f = open(CHANGELOG, 'r') line = f.readline() f.close() -pos=line.find('(') -posf=line.find('-',pos) +pos = line.find('(') +posf = line.find('-', pos) APP = line[:pos].strip().lower() VERSION = line[pos+1:posf].strip() APPNAME = APP.title() @@ -45,280 +49,324 @@ AUTHOR_EMAIL = 'lorenzo.carbonell.cerezo@gmail.com' URL = 'http://www.atareao.es' LICENSE = 'GNU General Public License (GPL)' -COMPILED_LANGUAGE_FILE = '%s.mo'%APP +COMPILED_LANGUAGE_FILE = '%s.mo' % APP + + +def get_entry(filein, msgid): + try: + po = polib.pofile(filein) + print po.metadata['Content-Type'] + for entry in po: + if entry.msgid == msgid: + return entry.msgstr + except Exception as e: + print(filein, e) + return None -def get_entry(filein,msgid): - try: - po = polib.pofile(filein) - print po.metadata['Content-Type'] - for entry in po: - if entry.msgid == msgid: - return entry.msgstr - except Exception,e: - print filein, e - pass - return None -######################################################################## def ejecuta(comando): - print ('Ejecutando... %s'%comando) - args = shlex.split(comando) - p = subprocess.Popen(args, bufsize=10000, stdout=subprocess.PIPE) - valor = p.communicate()[0] - return valor -######################################################################## + print('Ejecutando... %s' % comando) + args = shlex.split(comando) + p = subprocess.Popen(args, bufsize=10000, stdout=subprocess.PIPE) + valor = p.communicate()[0] + return valor + + def list_src(): - file_txt = os.path.join(MAIN_DIR,'files.txt') - f = open(file_txt,'w') - for file in glob.glob(os.path.join(SRC_DIR,'*.py')): - f.write('%s\n'%file) - for file in glob.glob(os.path.join(MAIN_DIR,'*.desktop.in')): - f.write('%s\n'%file) - f.close() - return file_txt + file_txt = os.path.join(MAIN_DIR, 'files.txt') + f = open(file_txt, 'w') + for file in glob.glob(os.path.join(SRC_DIR, '*.py')): + f.write('%s\n' % file) + for file in glob.glob(os.path.join(MAIN_DIR, '*.desktop.in')): + f.write('%s\n' % file) + f.close() + return file_txt + def list_languages(): - lans = [] - file_txt =os.path.join(LANGUAGES_DIR,'languages.txt') - if os.path.exists(file_txt)==True: - f = open(file_txt,'r') - for linea in f.readlines(): - lan = linea[:-1] - print lan - lans.append(lan) - f.close() - for file in glob.glob(os.path.join(LANGUAGES_DIR,'*.po')): - lan = os.path.splitext(os.path.basename(file))[0] - if lan not in lans: - lans.append(lan) - f = open(file_txt,'w') - for lan in lans: - f.write('%s\n'%lan) - f.close() - return file_txt + lans = [] + file_txt = os.path.join(LANGUAGES_DIR, 'languages.txt') + if os.path.exists(file_txt) is True: + f = open(file_txt, 'r') + for linea in f.readlines(): + lan = linea[:-1] + print lan + lans.append(lan) + f.close() + for file in glob.glob(os.path.join(LANGUAGES_DIR, '*.po')): + lan = os.path.splitext(os.path.basename(file))[0] + if lan not in lans: + lans.append(lan) + f = open(file_txt, 'w') + for lan in lans: + f.write('%s\n' % lan) + f.close() + return file_txt + def update_translations(): - file_txt =os.path.join(LANGUAGES_DIR,'languages.txt') - f = open(file_txt,'r') - for file in f.readlines(): - lan = file[:-1] - file = os.path.join(LANGUAGES_DIR,lan+'.po') - print '############################################################' - print lan - print '############################################################' - if os.path.exists(file): - command = 'msgmerge -U %s %s'%(file,TEMPLATE) - else: - command = 'msginit --output-file=%s --input=%s --locale=%s'%(file,TEMPLATE,lan) - print ejecuta(command) - edit_language_file(file) - f.close() - + file_txt = os.path.join(LANGUAGES_DIR, 'languages.txt') + f = open(file_txt, 'r') + for file in f.readlines(): + lan = file[:-1] + file = os.path.join(LANGUAGES_DIR, lan+'.po') + print '############################################################' + print lan + print '############################################################' + if os.path.exists(file): + command = 'msgmerge -U %s %s' % (file, TEMPLATE) + else: + command = 'msginit --output-file=%s --input=%s --locale=%s' % ( + file, TEMPLATE, lan) + print ejecuta(command) + edit_language_file(file) + f.close() + + def edit_language_file(file): - po = polib.pofile(file) - lang = file.split('/')[-1:][0].split('.')[0] - po.metadata['Project-Id-Version'] = '%s %s'%(APP,VERSION) - po.metadata['Report-Msgid-Bugs-To'] = AUTHOR_EMAIL - po.metadata['Language'] = lang - po.metadata['Content-Type'] = 'text/plain; charset=UTF-8' - po.metadata['Content-Transfer-Encoding'] = '8bit' - po.save() + po = polib.pofile(file) + lang = file.split('/')[-1:][0].split('.')[0] + po.metadata['Project-Id-Version'] = '%s %s' % (APP, VERSION) + po.metadata['Report-Msgid-Bugs-To'] = AUTHOR_EMAIL + po.metadata['Language'] = lang + po.metadata['Content-Type'] = 'text/plain; charset=UTF-8' + po.metadata['Content-Transfer-Encoding'] = '8bit' + po.save() + def update_desktop_file_fp(): - lns = [] - for filein in glob.glob('./po/*.po'): - ln = os.path.splitext(os.path.split(filein)[1])[0] - lns.append(ln) - for filedesktopin in glob.glob('*.desktop.in'): - desktopfile = ConfigParser.ConfigParser() - desktopfile.optionxform = str - desktopfile.readfp(codecs.open(filedesktopin,encoding = 'utf-8',mode='r')) - if len(lns)>0: - for entry in desktopfile.items('Desktop Entry'): - if entry[0].startswith('_'): - for ln in lns: - desktopfile.set('Desktop Entry','$%s[%s]'%(entry[0][1:],ln),"_('%s')"%entry[1]) - with codecs.open(filedesktopin,encoding = 'utf-8',mode='w') as outputfile: - desktopfile.write(outputfile) + lns = [] + for filein in glob.glob('./po/*.po'): + ln = os.path.splitext(os.path.split(filein)[1])[0] + lns.append(ln) + for filedesktopin in glob.glob('*.desktop.in'): + desktopfile = ConfigParser.ConfigParser() + desktopfile.optionxform = str + desktopfile.readfp( + codecs.open(filedesktopin, encoding='utf-8', mode='r')) + if len(lns) > 0: + for entry in desktopfile.items('Desktop Entry'): + if entry[0].startswith('_'): + for ln in lns: + desktopfile.set( + 'Desktop Entry', + '$%s[%s]' % (entry[0][1:], ln), + "_('%s')" % entry[1]) + with codecs.open(filedesktopin, + encoding='utf-8', + mode='w') as outputfile: + desktopfile.write(outputfile) def update_desktop_file(): - lns = [] - for filein in glob.glob('./po/*.po'): - ln = os.path.splitext(os.path.split(filein)[1])[0] - lns.append(ln) - for filedesktopin in glob.glob('*.desktop.in'): - desktopfilename = os.path.splitext(os.path.split(filedesktopin)[1])[0] - print desktopfilename - fileout = os.path.join(DATA_DIR,desktopfilename) - print fileout - if os.path.exists(fileout): - os.remove(fileout) - fileout = codecs.open('./data/%s'%desktopfilename,encoding = 'utf-8',mode='w') - fileout.write('[Desktop Entry]\n') - # - desktopfile = ConfigParser.ConfigParser() - desktopfile.optionxform = str - desktopfile.readfp(codecs.open('./%s.in'%desktopfilename,encoding = 'utf-8',mode='r')) - if len(lns)>0: - for entry in desktopfile.items('Desktop Entry'): - if not entry[0].startswith('$'): - if entry[0].startswith('_'): - fileout.write('%s = %s\n'%(entry[0][1:],entry[1])) - else: - fileout.write('%s = %s\n'%(entry[0],entry[1])) - for entry in desktopfile.items('Desktop Entry'): - if entry[0].startswith('_') and not entry[0].startswith('$'): - for ln in lns: - filepo = os.path.join(LANGUAGES_DIR,'%s.po'%ln) - msgstr = get_entry(filepo,entry[1]) - print filepo - if not msgstr or msgstr == '': - msgstr = entry[1] - - print '%s[%s]=%s'%(entry[0][1:],ln,msgstr) - fileout.write('%s[%s] = %s\n'%(entry[0][1:],ln,msgstr)) - fileout.close() - + lns = [] + for filein in glob.glob('./po/*.po'): + ln = os.path.splitext(os.path.split(filein)[1])[0] + lns.append(ln) + for filedesktopin in glob.glob('*.desktop.in'): + desktopfilename = os.path.splitext(os.path.split(filedesktopin)[1])[0] + print desktopfilename + fileout = os.path.join(DATA_DIR, desktopfilename) + print fileout + if os.path.exists(fileout): + os.remove(fileout) + fileout = codecs.open('./data/%s' % desktopfilename, + encoding='utf-8', + mode='w') + fileout.write('[Desktop Entry]\n') + # + desktopfile = ConfigParser.ConfigParser() + desktopfile.optionxform = str + desktopfile.readfp(codecs.open('./%s.in' % desktopfilename, + encoding='utf-8', + mode='r')) + if len(lns) > 0: + for entry in desktopfile.items('Desktop Entry'): + if not entry[0].startswith('$'): + if entry[0].startswith('_'): + fileout.write('%s = %s\n' % (entry[0][1:], entry[1])) + else: + fileout.write('%s = %s\n' % (entry[0], entry[1])) + for entry in desktopfile.items('Desktop Entry'): + if entry[0].startswith('_') and not entry[0].startswith('$'): + for ln in lns: + filepo = os.path.join(LANGUAGES_DIR, '%s.po' % ln) + msgstr = get_entry(filepo, entry[1]) + print filepo + if not msgstr or msgstr == '': + msgstr = entry[1] + + print '%s[%s]=%s' % (entry[0][1:], ln, msgstr) + fileout.write('%s[%s] = %s\n' % (entry[0][1:], + ln, msgstr)) + fileout.close() + + def remove_security_copies(): - for file in glob.glob(os.path.join(LANGUAGES_DIR,'*.po~')): - os.remove(file) + for file in glob.glob(os.path.join(LANGUAGES_DIR, '*.po~')): + os.remove(file) + def delete_it(file): - if os.path.exists(file): - if os.path.isdir(file): - shutil.rmtree(file) - else: - os.remove(file) - -def remove_files(dir,ext): - files = [] - for file in glob.glob(os.path.join(dir,'*')): - if file != None and os.path.exists(file): - if file and os.path.isdir(file): - morefiles = remove_files(file,ext) - if morefiles: - files.extend(morefiles) - else: - files.append(file) - for file in files: - if os.path.splitext(file)[1] == ext: - os.remove(file) + if os.path.exists(file): + if os.path.isdir(file): + shutil.rmtree(file) + else: + os.remove(file) + + +def remove_files(dir, ext): + files = [] + for file in glob.glob(os.path.join(dir, '*')): + if file is not None and os.path.exists(file): + if file and os.path.isdir(file): + morefiles = remove_files(file, ext) + if morefiles: + files.extend(morefiles) + else: + files.append(file) + for file in files: + if os.path.splitext(file)[1] == ext: + os.remove(file) + def remove_compiled_files(dir): - remove_files(dir,'.pyc') + cachedir = os.path.join(dir, '__pycache__') + if os.path.exists(cachedir): + shutil.rmtree(cachedir) + remove_files(dir, '.pyc') + def remove_languages_saved_files(dir): - remove_files(dir,'.po~') + remove_files(dir, '.po~') + def babilon(): - print '############################################################' - print 'Parent dir -> %s'%MAIN_DIR - print 'Languages dir -> %s'%LANGUAGES_DIR - print 'Source dir -> %s'%SRC_DIR - print '############################################################' - print 'Updating Desktop File First Part' - print '############################################################' - update_desktop_file_fp() - print '############################################################' - print 'Updating template' - print '############################################################' - files_file = list_src() - command = 'xgettext --msgid-bugs-address=%s --language=Python --keyword=_ --keyword=N_ --output=%s --files-from=%s'%(AUTHOR_EMAIL,TEMPLATE,files_file) - print ejecuta(command) - delete_it(files_file) - print '############################################################' - print 'List languages' - print '############################################################' - # - list_languages() - # - print '############################################################' - print 'Updating translations' - print '############################################################' - update_translations() - print '############################################################' - print 'Updating Desktop File' - print '############################################################' - update_desktop_file() - print '############################################################' - print 'Removing security copies' - print '############################################################' - remove_security_copies() - - + print '############################################################' + print 'Parent dir -> %s' % MAIN_DIR + print 'Languages dir -> %s' % LANGUAGES_DIR + print 'Source dir -> %s' % SRC_DIR + print '############################################################' + print 'Updating Desktop File First Part' + print '############################################################' + update_desktop_file_fp() + print '############################################################' + print 'Updating template' + print '############################################################' + files_file = list_src() + command = 'xgettext --msgid-bugs-address=%s --language=Python\ + --keyword=_ --keyword=N_ --output=%s --files-from=%s' % (AUTHOR_EMAIL, + TEMPLATE, files_file) + print ejecuta(command) + delete_it(files_file) + print '############################################################' + print 'List languages' + print '############################################################' + # + list_languages() + # + print '############################################################' + print 'Updating translations' + print '############################################################' + update_translations() + print '############################################################' + print 'Updating Desktop File' + print '############################################################' + update_desktop_file() + print '############################################################' + print 'Removing security copies' + print '############################################################' + remove_security_copies() + + class clean_and_compile(cmd.Command): - description = 'Clean and compile languages' - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - remove_compiled_files(SRC_DIR) - babilon() + description = 'Clean and compile languages' + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + remove_compiled_files(SRC_DIR) + babilon() + class translate(build_extra.build_extra): - sub_commands = build_extra.build_extra.sub_commands + [('clean_and_compile', None)] - def run(self): - build_extra.build_extra.run(self) - pass - - + sub_commands = build_extra.build_extra.sub_commands + [( + 'clean_and_compile', None)] + + def run(self): + build_extra.build_extra.run(self) + pass + + class build_trans(cmd.Command): - description = 'Compile .po files into .mo files' - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - po_dir = os.path.join(os.path.dirname(os.curdir), 'po') - for path, names, filenames in os.walk(po_dir): - for f in filenames: - if f.endswith('.po'): - lang = f[:len(f) - 3] - src = os.path.join(path, f) - dest_path = os.path.join('build', 'locale-langpack', lang, 'LC_MESSAGES') - dest = os.path.join(dest_path, COMPILED_LANGUAGE_FILE) - if not os.path.exists(dest_path): - os.makedirs(dest_path) - if not os.path.exists(dest): - print 'Compiling %s' % src - msgfmt.make(src, dest) - else: - src_mtime = os.stat(src)[8] - dest_mtime = os.stat(dest)[8] - if src_mtime > dest_mtime: - print 'Compiling %s' % src - msgfmt.make(src, dest) - + description = 'Compile .po files into .mo files' + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + po_dir = os.path.join(os.path.dirname(os.curdir), 'po') + for path, names, filenames in os.walk(po_dir): + for f in filenames: + if f.endswith('.po'): + lang = f[:len(f) - 3] + src = os.path.join(path, f) + dest_path = os.path.join('build', 'locale-langpack', + lang, 'LC_MESSAGES') + dest = os.path.join(dest_path, COMPILED_LANGUAGE_FILE) + if not os.path.exists(dest_path): + os.makedirs(dest_path) + if not os.path.exists(dest): + print 'Compiling %s' % src + msgfmt.make(src, dest) + else: + src_mtime = os.stat(src)[8] + dest_mtime = os.stat(dest)[8] + if src_mtime > dest_mtime: + print 'Compiling %s' % src + msgfmt.make(src, dest) + + class build(build_extra.build_extra): - sub_commands = build_extra.build_extra.sub_commands# + [('build_trans', None)] - def run(self): - build_extra.build_extra.run(self) + sub_commands = build_extra.build_extra.sub_commands + [('build_trans', + None)] + + def run(self): + build_extra.build_extra.run(self) + class install_data(_install_data): - def run(self): - ''' - for lang in os.listdir('build/locale-langpack/'): - lang_dir = os.path.join('/opt/extras.ubuntu.com/pushbullet-commons/share', 'locale-langpack', lang, 'LC_MESSAGES') - lang_file = os.path.join('build', 'locale-langpack', lang, 'LC_MESSAGES', COMPILED_LANGUAGE_FILE) - self.data_files.append( (lang_dir, [lang_file]) ) - ''' - _install_data.run(self) - + def run(self): + ''' + ### Translation ### + for lang in os.listdir('build/locale-langpack/'): + lang_dir = os.path.join( + USRDIR, + 'share', + 'locale-langpack', lang, 'LC_MESSAGES') + lang_file = os.path.join( + 'build', 'locale-langpack', lang, 'LC_MESSAGES', + COMPILED_LANGUAGE_FILE) + self.data_files.append((lang_dir, [lang_file])) + ''' + _install_data.run(self) + setup(name=APP, - version=VERSION, - author=AUTHOR, - author_email=AUTHOR_EMAIL, - url=URL, - license=LICENSE, - data_files=DATA_FILES, - cmdclass={'build': build, - 'translate':translate, - 'clean_and_compile':clean_and_compile, - 'build_trans': build_trans, - 'install_data': install_data,}) + version=VERSION, + author=AUTHOR, + author_email=AUTHOR_EMAIL, + url=URL, + license=LICENSE, + data_files=DATA_FILES, + cmdclass={'build': build, + 'translate': translate, + 'clean_and_compile': clean_and_compile, + 'build_trans': build_trans, + 'install_data': install_data}) diff -Nru pushbullet-commons-0.4.0/src/commons_comun.py pushbullet-commons-0.5.6/src/commons_comun.py --- pushbullet-commons-0.4.0/src/commons_comun.py 2015-03-18 06:04:49.000000000 +0000 +++ pushbullet-commons-0.5.6/src/commons_comun.py 2016-07-02 10:32:34.000000000 +0000 @@ -1,11 +1,9 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# comun.py +# This file is part of PushBullet-Commons # -# This file is part of PushBullet-Indicator -# -# Copyright (C) 2014-2015 +# Copyright (C) 2014-2016 # Lorenzo Carbonell Cerezo # # This program is free software: you can redistribute it and/or modify @@ -21,115 +19,122 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import requests +import os try: - from urllib.request import urlopen - from urllib.request import Request + from urllib.request import getproxies, urlopen except ImportError: - from urllib import urlopen - from urllib2 import Request - -__author__ = 'Lorenzo Carbonell ' -__copyright__ = 'Copyright (c) 2012-2015 Lorenzo Carbonell' -__license__ = 'GPLV3' -__url__ = 'http://www.atareao.es' + from urllib2 import urlopen + from urllib import getproxies -import os -import locale -import gettext - -###################################### def is_package(): - return not os.path.dirname(os.path.abspath(__file__)).endswith('src') + return not os.path.dirname(os.path.abspath(__file__)).endswith('src') ###################################### -PARAMS = { - 'oauth_access_token':None, - 'access_token':None, - 'iden':None, - 'source_user_iden':None, - 'source_device_iden':None, - } +TOKEN_PARAMS = { + 'oauth_access_token': None, + 'access_token': None, + 'source_user_iden': None, + 'source_device_iden': None, + } APP = 'pushbullet-commons' APPCONF = APP + '.conf' APPDATA = APP + '.data' APPNAME = 'PushBullet' -CONFIG_DIR = os.path.join(os.path.expanduser('~'),'.config') +CONFIG_DIR = os.path.join(os.path.expanduser('~'), '.config') CONFIG_APP_DIR = os.path.join(CONFIG_DIR, APP) CONFIG_FILE = os.path.join(CONFIG_APP_DIR, APPCONF) -DATA_FILE = os.path.join(CONFIG_APP_DIR, APPDATA) -BACKUP_FILE = os.path.join(CONFIG_APP_DIR, 'backup') -TOKEN_FILE = os.path.join(CONFIG_APP_DIR, 'token') +TOKEN_DIR = CONFIG_APP_DIR +TOKEN_FILE = os.path.join(TOKEN_DIR, 'token') if not os.path.exists(CONFIG_APP_DIR): - os.makedirs(CONFIG_APP_DIR) + os.makedirs(TOKEN_DIR) print(os.path.dirname(os.path.abspath(__file__))) if is_package(): - ROOTDIR = '/opt/extras.ubuntu.com/pushbullet-commons/share/' - LANGDIR = os.path.join(ROOTDIR, 'locale-langpack') - APPDIR = os.path.join(ROOTDIR, APP) - ICONDIR = os.path.join(APPDIR, 'icons') - SOCIALDIR = os.path.join(APPDIR, 'social') - CHANGELOG = os.path.join(APPDIR,'changelog') + ROOTDIR = '/opt/extras.ubuntu.com/pushbullet-commons/share/' + LANGDIR = os.path.join(ROOTDIR, 'locale-langpack') + APPDIR = os.path.join(ROOTDIR, APP) + ICONDIR = os.path.join(APPDIR, 'icons') + SOCIALDIR = os.path.join(APPDIR, 'social') + CHANGELOG = os.path.join(APPDIR, 'changelog') else: - ROOTDIR = os.path.dirname(__file__) - LANGDIR = os.path.join(ROOTDIR, 'template1') - APPDIR = os.path.join(ROOTDIR, APP) - ICONDIR = os.path.normpath(os.path.join(ROOTDIR, '../data/icons')) - DEBIANDIR = os.path.normpath(os.path.join(ROOTDIR, '../debian')) - CHANGELOG = os.path.join(DEBIANDIR,'changelog') + ROOTDIR = os.path.dirname(__file__) + LANGDIR = os.path.join(ROOTDIR, 'template1') + APPDIR = os.path.join(ROOTDIR, APP) + ICONDIR = os.path.normpath(os.path.join(ROOTDIR, '../data/icons')) + DEBIANDIR = os.path.normpath(os.path.join(ROOTDIR, '../debian')) + CHANGELOG = os.path.join(DEBIANDIR, 'changelog') -ICON = os.path.join(ICONDIR,'pushbullet-indicator.svg') +ICON = os.path.join(ICONDIR, 'pushbullet-indicator.svg') STATUS_ICON = {} -STATUS_ICON['light'] = (os.path.join(ICONDIR,'pushbullet-indicator-light.svg'),os.path.join(ICONDIR,'pushbullet-indicator-sync-light.svg')) -STATUS_ICON['dark'] = (os.path.join(ICONDIR,'pushbullet-indicator-dark.svg'),os.path.join(ICONDIR,'pushbullet-indicator-sync-dark.svg')) +STATUS_ICON['light'] = ( + os.path.join(ICONDIR, 'pushbullet-indicator-light.svg'), + os.path.join(ICONDIR, 'pushbullet-indicator-sync-light.svg')) +STATUS_ICON['dark'] = ( + os.path.join(ICONDIR, 'pushbullet-indicator-dark.svg'), + os.path.join(ICONDIR, 'pushbullet-indicator-sync-dark.svg')) + +ADDRESS_ICON = os.path.join(ICONDIR, 'address.svg') +FILE_ICON = os.path.join(ICONDIR, 'file.svg') +LINK_ICON = os.path.join(ICONDIR, 'link.svg') +LIST_ICON = os.path.join(ICONDIR, 'list.svg') +NOTE_ICON = os.path.join(ICONDIR, 'note.svg') +IMAGE_ICON = os.path.join(ICONDIR, 'image.svg') -ADDRESS_ICON = os.path.join(ICONDIR,'address.svg') -FILE_ICON = os.path.join(ICONDIR,'file.svg') -LINK_ICON = os.path.join(ICONDIR,'link.svg') -LIST_ICON = os.path.join(ICONDIR,'list.svg') -NOTE_ICON = os.path.join(ICONDIR,'note.svg') -IMAGE_ICON = os.path.join(ICONDIR,'image.svg') - -f = open(CHANGELOG,'r') +f = open(CHANGELOG, 'r') line = f.readline() f.close() -pos=line.find('(') -posf=line.find(')',pos) +pos = line.find('(') +posf = line.find(')', pos) VERSION = line[pos+1:posf].strip() if not is_package(): - VERSION = VERSION + '-src' -try: - current_locale, encoding = locale.getdefaultlocale() - language = gettext.translation(APP, LANGDIR, [current_locale]) - language.install() - _ = language.gettext -except Exception as e: - _ = str - -def read_from_url(url): - try: - url = url.replace(' ','%20') - request = Request(url, headers={'User-Agent' : 'Magic Browser'}) - f = urlopen(request) - json_string = f.read() - f.close() - return json_string - except: - return None + VERSION = VERSION + '-src' + + +def read_from_url(url, timeout=0): + try: + url = url.replace(' ', '%20') + ans = requests.get(url, proxies=getproxies()) + if ans.status_code == 200: + return ans.text + except Exception as e: + print(e) + return None + + +def read_json_from_url(url, timeout=0): + try: + url = url.replace(' ', '%20') + ans = requests.get(url, proxies=getproxies()) + if ans.status_code == 200: + return ans.json() + else: + print('==== **** ====') + print('Error accessing url: ', ans.status_code) + print('==== **** ====') + except Exception as e: + print(e) + return None + def internet_on(): - try: - response = urlopen('http://google.com',timeout=1) - return True - except: - pass - return False + try: + urlopen('https://www.google.com/', timeout=5) + return True + except Exception as ex1: + print(ex1) + try: + urlopen('http://www.baidu.com/', timeout=5) + return True + except Exception as ex2: + print('No internet connection available.') + print('^^^^^', ex2, '^^^^^') + return False + if __name__ == '__main__': - print(read_from_url('http://www.atareao.es')) - print(internet_on()) - + print('Internet on?', internet_on()) diff -Nru pushbullet-commons-0.4.0/src/commons_configurator.py pushbullet-commons-0.5.6/src/commons_configurator.py --- pushbullet-commons-0.4.0/src/commons_configurator.py 2015-03-15 06:57:55.000000000 +0000 +++ pushbullet-commons-0.5.6/src/commons_configurator.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# configurator.py -# -# This file is part of PushBullet-Indicator -# -# Copyright (C) 2014-2015 -# Lorenzo Carbonell Cerezo -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import codecs -import os -import json -import commons_comun - -class Configuration(object): - def __init__(self): - self.params = commons_comun.PARAMS - self.read() - - def get(self,key): - try: - return self.params[key] - except KeyError as e: - print(e) - self.params[key] = commons_comun.PARAMS[key] - return self.params[key] - - def set(self,key,value): - self.params[key] = value - - def reset(self): - if os.path.exists(commons_comun.CONFIG_FILE): - os.remove(commons_comun.CONFIG_FILE) - self.params = commons_comun.PARAMS - self.save() - - def set_defaults(self): - self.params = commons_comun.PARAMS - self.save() - - def read(self): - try: - f=codecs.open(commons_comun.CONFIG_FILE,'r','utf-8') - except IOError as e: - print(e) - self.save() - f=codecs.open(commons_comun.CONFIG_FILE,'r','utf-8') - try: - self.params = json.loads(f.read()) - except ValueError as e: - print(e) - self.save() - f.close() - - def save(self): - if not os.path.exists(commons_comun.CONFIG_APP_DIR): - os.makedirs(commons_comun.CONFIG_APP_DIR) - f=codecs.open(commons_comun.CONFIG_FILE,'w','utf-8') - f.write(json.dumps(self.params, indent=4, sort_keys=True)) - f.close() diff -Nru pushbullet-commons-0.4.0/src/configurator.py pushbullet-commons-0.5.6/src/configurator.py --- pushbullet-commons-0.4.0/src/configurator.py 2014-06-24 10:34:59.000000000 +0000 +++ pushbullet-commons-0.5.6/src/configurator.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,81 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -# -# -# Copyright (C) 2010 Lorenzo Carbonell -# lorenzo.carbonell.cerezo@gmail.com -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# -# -import codecs -import os -import json - -CONFIG_DIR = os.path.join(os.path.expanduser('~'),'.config') -CONFIG_APP_DIR = os.path.join(CONFIG_DIR, 'pushbullet') -CONFIG_FILE = os.path.join(CONFIG_APP_DIR, 'pushbullet.conf') - -DEFAULT_PARAMS = { - 'oauth_access_token':None, - 'access_token':None, - } - -class Configuration(object): - def __init__(self): - self.params = DEFAULT_PARAMS - self.read() - - def get(self,key): - try: - return self.params[key] - except KeyError as e: - print(e) - self.params[key] = DEFAULT_PARAMS[key] - return self.params[key] - - def set(self,key,value): - self.params[key] = value - - def reset(self): - if os.path.exists(CONFIG_FILE): - os.remove(CONFIG_FILE) - self.params = DEFAULT_PARAMS - self.save() - - def set_defaults(self): - self.params = DEFAULT_PARAMS - self.save() - - def read(self): - try: - f=codecs.open(CONFIG_FILE,'r','utf-8') - except IOError as e: - print(e) - self.save() - f=codecs.open(CONFIG_FILE,'r','utf-8') - try: - self.params = json.loads(f.read()) - except ValueError as e: - print(e) - self.save() - f.close() - - def save(self): - if not os.path.exists(CONFIG_APP_DIR): - os.makedirs(CONFIG_APP_DIR) - f=codecs.open(CONFIG_FILE,'w','utf-8') - f.write(json.dumps(self.params)) - f.close() diff -Nru pushbullet-commons-0.4.0/src/dialogs.py pushbullet-commons-0.5.6/src/dialogs.py --- pushbullet-commons-0.4.0/src/dialogs.py 1970-01-01 00:00:00.000000000 +0000 +++ pushbullet-commons-0.5.6/src/dialogs.py 2016-07-03 20:08:05.000000000 +0000 @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# This file is part of PushBullet-Indicator +# +# Copyright (C) 2014-2016 +# Lorenzo Carbonell Cerezo +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import gi +try: + gi.require_version('Gtk', '3.0') +except Exception as e: + print(e) + exit(1) +from gi.repository import Gtk +from gi.repository import GdkPixbuf +import commons_comun +import os +_ = str + + +class SendToDialog(Gtk.Dialog): + + def __init__(self, devices=[], contacts=[]): + Gtk.Dialog.__init__( + self, + _('PushBullet action'), + None, + Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, + (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, + Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)) + self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) + self.connect('close', self.close_application) + self.set_icon_from_file(commons_comun.ICON) + # + vbox0 = Gtk.VBox(spacing=5) + vbox0.set_border_width(5) + self.get_content_area().add(vbox0) + table_to = Gtk.Table(2, 2, False) + vbox0.pack_start(table_to, False, False, 0) + label_to = Gtk.Label(_('Send bullet to')+':') + label_to.set_alignment(0, 0.5) + table_to.attach(label_to, 0, 1, 0, 1, xpadding=5, ypadding=5) + name_store = Gtk.ListStore(str, str, GdkPixbuf.Pixbuf, str) + toall = GdkPixbuf.Pixbuf.new_from_file_at_size( + os.path.join(commons_comun.ICONDIR, "infinity.svg"), 32, 32) + tomobile = GdkPixbuf.Pixbuf.new_from_file_at_size( + os.path.join(commons_comun.ICONDIR, "mobile.svg"), 32, 32) + touser = GdkPixbuf.Pixbuf.new_from_file_at_size( + os.path.join(commons_comun.ICONDIR, "user.svg"), 32, 32) + name_store.append([_('All'), '', toall, 'all']) + for adevice in devices: + name_store.append([ + adevice['label'], adevice['device_iden'], tomobile, 'device']) + for acontact in contacts: + name_store.append([ + acontact['name'], acontact['contact_iden'], touser, 'contact']) + self.bulletTo = Gtk.ComboBox.new_with_model(name_store) + renderertext = Gtk.CellRendererText() + renderertext.props.mode = Gtk.CellRendererMode.ACTIVATABLE + self.bulletTo.pack_start(renderertext, False) + self.bulletTo.add_attribute(renderertext, "text", 0) + renderer = Gtk.CellRendererPixbuf() + self.bulletTo.pack_start(renderer, False) + self.bulletTo.add_attribute(renderer, "pixbuf", 2) + table_to.attach(self.bulletTo, 1, 2, 0, 1, xpadding=5, ypadding=5) + self.bulletTo.set_active(0) + self.show_all() + + def get_selected_in_combo(self): + tree_iter = self.bulletTo.get_active_iter() + if tree_iter is not None: + model = self.bulletTo.get_model() + label, iden, pb, ttype = model[tree_iter] + return {'label': label, 'iden': iden, 'type': ttype} + return None + + def get_response(self): + return self.get_selected_in_combo() + + def close_application(self, widget): + self.hide() + +if __name__ == "__main__": + cm = SendToDialog() + if cm.run() == Gtk.ResponseType.ACCEPT: + cm.hide() + print(cm.get_response()) + cm.destroy() + exit(0) diff -Nru pushbullet-commons-0.4.0/src/doitinbackgroundbullet.py pushbullet-commons-0.5.6/src/doitinbackgroundbullet.py --- pushbullet-commons-0.4.0/src/doitinbackgroundbullet.py 1970-01-01 00:00:00.000000000 +0000 +++ pushbullet-commons-0.5.6/src/doitinbackgroundbullet.py 2016-07-08 17:41:25.000000000 +0000 @@ -0,0 +1,165 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# This file is part of PushBullet-Commons +# +# Copyright (C) 2014-2016 +# Lorenzo Carbonell Cerezo +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from threading import Thread +from idleobject import IdleObject +from gi.repository import GObject +from progreso import Progreso +import time + + +class DoitInBackground(Thread, IdleObject): + __gsignals__ = { + 'started': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'finished': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + } + + def __init__(self, handler, *args): + IdleObject.__init__(self) + Thread.__init__(self) + self.daemon = True + self.handler = handler + self.args = args + + def run(self): + self.emit('started') + self.working = self.handler(*self.args) + self.emit('finished') + + +class DoitInBackgroundVarious(Thread, IdleObject): + __gsignals__ = { + 'started': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'start_one': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, (object,)), + 'finished_one': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, + (object,)), + 'interrupted': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'finished': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + } + + def __init__(self, handler, elements, *args): + IdleObject.__init__(self) + Thread.__init__(self) + self.daemon = True + self.handler = handler + self.elements = elements + self.args = args + self.stop = False + + def stop_it(self): + self.stop = True + + def run(self): + self.emit('started') + for element in self.elements: + if self.stop is True: + self.emit('interrupted') + return + self.emit('start_one', element) + self.handler(element, *self.args) + self.emit('finished_one', element) + self.emit('finished') + + +class DoitInBackgroundWithInterval(Thread, IdleObject): + __gsignals__ = { + 'started': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'finished': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'stoped': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + } + + def __init__(self, handler, interval, *args): + IdleObject.__init__(self) + Thread.__init__(self) + self.daemon = True + self.handler = handler + self.interval = interval + self.args = args + self.working = False + + def stop(self): + self.working = False + self.emit('stoped') + + def run(self): + self.emit('started') + self.working = True + while self.working: + self.handler(*self.args) + time.sleep(self.interval) + self.emit('finished') + + +class Ticker(Thread, IdleObject): + __gsignals__ = { + 'started': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'finished': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'stoped': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'tick': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, (str,)), + } + + def __init__(self, signal, interval): + IdleObject.__init__(self) + Thread.__init__(self) + self.daemon = True + self.signal = signal + self.interval = interval + self.working = False + + def stop(self): + self.working = False + self.emit('stoped') + + def run(self): + self.emit('started') + self.working = True + while self.working: + self.emit('tick', self.signal) + time.sleep(self.interval) + self.emit('finished') + + +def doitinbackground(handler, *args): + dib = DoitInBackground(handler, *args) + dib.start() + + +def doitinbackgroundwithinterval(handler, interval, *args): + dib = DoitInBackgroundWithInterval(handler, interval, *args) + dib.start() + + +if __name__ == '__main__': + first_time = time.time() + + def cuenta(item, first_time): + print() + time.sleep(item) + print('---', item, time.time() - first_time, '---') + + counter = 1 + various = [.1, .2, .3, .4] + dib = DoitInBackgroundVarious(cuenta, various, first_time) + dib.start() + while counter < 10: + print('====', counter, '====') + time.sleep(0.5) + counter += 1 diff -Nru pushbullet-commons-0.4.0/src/idleobject.py pushbullet-commons-0.5.6/src/idleobject.py --- pushbullet-commons-0.4.0/src/idleobject.py 1970-01-01 00:00:00.000000000 +0000 +++ pushbullet-commons-0.5.6/src/idleobject.py 2016-06-26 16:19:28.000000000 +0000 @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# This file is part of PushBullet-Commons +# +# Copyright (C) 2014-2016 +# Lorenzo Carbonell Cerezo +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from gi.repository import GObject +from gi.repository import GLib + + +class IdleObject(GObject.GObject): + """ + Override GObject.GObject to always emit signals in the main thread + by emmitting on an idle handler + """ + def __init__(self): + GObject.GObject.__init__(self) + + def emit(self, *args): + GLib.idle_add(GObject.GObject.emit, self, *args) diff -Nru pushbullet-commons-0.4.0/src/logindialog.py pushbullet-commons-0.5.6/src/logindialog.py --- pushbullet-commons-0.4.0/src/logindialog.py 2015-03-16 17:10:44.000000000 +0000 +++ pushbullet-commons-0.5.6/src/logindialog.py 2016-06-26 16:40:49.000000000 +0000 @@ -2,10 +2,11 @@ # -*- coding: utf-8 -*- # # -# LoginDialog -# +# logindialog.py # -# Copyright (C) 2012 Lorenzo Carbonell +# This file is part of PushBullet-Indicator +# +# Copyright (C) 2014-2016 Lorenzo Carbonell # lorenzo.carbonell.cerezo@gmail.com # # This program is free software: you can redistribute it and/or modify @@ -22,70 +23,91 @@ # along with this program. If not, see . # # +import gi +try: + gi.require_version('Gtk', '3.0') + gi.require_version('WebKit', '3.0') +except Exception as e: + print(e) + exit(1) from gi.repository import Gtk from gi.repository import WebKit from gi.repository import GObject -import commons_comun -URL = 'https://www.pushbullet.com/authorize?client_id=RpkMU0UUoiDMNZnY1ZLJXWLw7QYm4QRY&redirect_uri=http%3A%2F%2Fwww.atareao.es%2Ftag%2Fpushbullet-indicator&response_type=token&scope=everything' +from commons_comun import APPNAME, ICON + +URL = ''' https://www.pushbullet.com/authorize?client_id=\ +RpkMU0UUoiDMNZnY1ZLJXWLw7QYm4QRY&redirect_uri=\ +http%3A%2F%2Fwww.atareao.es%2Ftag%2Fpushbullet-indicator&\ +response_type=token&scope=everything +''' + class LoginDialog(Gtk.Dialog): - def __init__(self,url=URL): - self.code = None - Gtk.Dialog.__init__(self) - self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) - self.set_title(commons_comun.APP) - self.set_icon_from_file(commons_comun.ICON) - # - vbox = Gtk.VBox(spacing = 5) - self.get_content_area().add(vbox) - hbox1 = Gtk.HBox() - vbox.pack_start(hbox1,True,True,0) - # - self.scrolledwindow1 = Gtk.ScrolledWindow() - self.scrolledwindow1.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) - self.scrolledwindow1.set_shadow_type(Gtk.ShadowType.IN) - hbox1.pack_start(self.scrolledwindow1,True,True,0) - # - self.viewer = WebKit.WebView() - self.scrolledwindow1.add(self.viewer) - self.scrolledwindow1.set_size_request(600,730) - self.viewer.connect('navigation-policy-decision-requested', self.on_navigation_requested) - self.viewer.open(url) - # - self.show_all() - - #################################################################### - #########################BROWSER#################################### - #################################################################### - def on_navigation_requested(self, view, frame, req, nav, pol): - try: - uri = req.get_uri() - print(uri) - pos = uri.find('http://www.atareao.es/tag/pushbullet-indicator#access_token=') - if pos > -1: - self.code = uri[60:] - self.hide() - else: - pos = uri.find('http://www.atareao.es/tag/pushbullet-indicator?error=access_denied') - if pos > -1: - self.code = None - self.hide() - except Exception as e: - print(e) - print('Error') - #################################################################### - #########################ACTIONS#################################### - #################################################################### + def __init__(self, url=URL): + self.code = None + Gtk.Dialog.__init__(self) + self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) + self.set_title(APPNAME) + self.set_icon_from_file(ICON) + vbox = Gtk.VBox(spacing=5) + self.get_content_area().add(vbox) + hbox1 = Gtk.HBox() + vbox.pack_start(hbox1, True, True, 0) + self.scrolledwindow1 = Gtk.ScrolledWindow() + self.scrolledwindow1.set_policy( + Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) + self.scrolledwindow1.set_shadow_type(Gtk.ShadowType.IN) + hbox1.pack_start(self.scrolledwindow1, True, True, 0) + self.viewer = WebKit.WebView() + self.scrolledwindow1.add(self.viewer) + self.scrolledwindow1.set_size_request(600, 730) + self.viewer.connect('navigation-policy-decision-requested', + self.on_navigation_requested) + self.viewer.open(url) + # + self.show_all() + + # ################################################################### + # ########################BROWSER#################################### + # ################################################################### + + def on_navigation_requested(self, view, frame, req, nav, pol): + try: + uri = req.get_uri() + print(uri) + pos = uri.find( + 'http://www.atareao.es/tag/pushbullet-indicator#access_token=') + if pos > -1: + self.code = uri[60:] + self.hide() + else: + pos = uri.find( + 'http://www.atareao.es/tag/pushbullet-indicator?\ +error=access_denied') + if pos > -1: + self.code = None + self.hide() + except Exception as e: + print(e) + print('Error') + + # ################################################################### + # ########################ACTIONS#################################### + # ################################################################### if __name__ == '__main__': - from commons_comun import internet_on - from commons_configurator import Configuration - configuration = Configuration() - oauth_access_token = configuration.get('oauth_access_token') - if oauth_access_token is None or len(oauth_access_token)==0 and internet_on(): - ld = LoginDialog() - ld.run() - print(ld.code) - configuration.set('oauth_access_token',ld.code) - configuration.save() - exit(0) + from commons_comun import internet_on, TOKEN_DIR, TOKEN_FILE, TOKEN_PARAMS + from tokenizator import Tokenizator + tokenizator = Tokenizator( + config_file_dir=TOKEN_DIR, + config_file=TOKEN_FILE, + default_params=TOKEN_PARAMS) + oauth_access_token = tokenizator.get('oauth_access_token') + if oauth_access_token is None or len(oauth_access_token) == 0 and\ + internet_on(): + ld = LoginDialog() + ld.run() + print(ld.code) + tokenizator.set('oauth_access_token', ld.code) + tokenizator.save() + exit(0) diff -Nru pushbullet-commons-0.4.0/src/progreso.py pushbullet-commons-0.5.6/src/progreso.py --- pushbullet-commons-0.4.0/src/progreso.py 1970-01-01 00:00:00.000000000 +0000 +++ pushbullet-commons-0.5.6/src/progreso.py 2016-07-03 11:34:37.000000000 +0000 @@ -0,0 +1,132 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# pushbulletapi.py +# +# This file is part of PushBullet-Indicator +# +# Copyright (C) 2014-2016 +# Lorenzo Carbonell Cerezo +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +from gi.repository import Gtk +from gi.repository import GObject +import threading + + +class Progreso(Gtk.Dialog, threading.Thread): + __gsignals__ = { + 'i-want-stop': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + } + + def __init__(self, title, parent, max_value, label=None): + Gtk.Dialog.__init__(self, title, parent) + self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) + self.set_size_request(330, 30) + self.set_resizable(False) + self.connect('destroy', self.close) + # self.set_modal(True) + vbox = Gtk.VBox(spacing=5) + vbox.set_border_width(5) + self.get_content_area().add(vbox) + # + frame1 = Gtk.Frame() + vbox.pack_start(frame1, True, True, 0) + table = Gtk.Table(2, 2, False) + frame1.add(table) + # + self.label = Gtk.Label() + table.attach(self.label, 0, 2, 0, 1, + xpadding=5, + ypadding=5, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.EXPAND) + if label is not None: + self.label.set_label(label) + # + self.progressbar = Gtk.ProgressBar() + self.progressbar.set_size_request(300, 0) + table.attach(self.progressbar, 0, 1, 1, 2, + xpadding=5, + ypadding=5, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.EXPAND) + button_stop = Gtk.Button() + button_stop.set_size_request(40, 40) + button_stop.set_image( + Gtk.Image.new_from_stock(Gtk.STOCK_STOP, Gtk.IconSize.BUTTON)) + button_stop.connect('clicked', self.on_button_stop_clicked) + table.attach(button_stop, 1, 2, 1, 2, + xpadding=5, + ypadding=5, + xoptions=Gtk.AttachOptions.SHRINK) + self.stop = False + self.show_all() + self.max_value = max_value + self.value = 0.0 + + def get_stop(self): + return self.stop + + def on_button_stop_clicked(self, widget): + self.stop = True + self.emit('i-want-stop') + + def set_todo_label(self, widget, todo_label): + if len(todo_label) > 35: + text = '...'+todo_label[-32:] + else: + text = todo_label + self.label.set_label(text) + + def set_value(self, value): + if value >= 0 and value <= self.max_value: + self.value = value + fraction = self.value/self.max_value + self.progressbar.set_fraction(fraction) + if self.value == self.max_value: + self.hide() + + def close(self, widget=None): + self.destroy() + + def increase(self, *args): + self.value += 1.0 + fraction = self.value/self.max_value + self.progressbar.set_fraction(fraction) + if self.value == self.max_value: + self.hide() + + def decrease(self): + self.value -= 1.0 + fraction = self.value/self.max_value + self.progressbar.set_fraction(fraction) + +if __name__ == '__main__': + import time + from doitinbackground import DoitInBackground + p = Progreso('Prueba', None, 5) + + def maker(element): + print('==== %s ====' % (element)) + time.sleep(0.5) + + elements = range(0, 5) + dib = DoitInBackground(maker, elements) + p.connect('i-want-stop', dib.stop_it) + dib.connect('done', p.increase) + dib.start() + p.run() diff -Nru pushbullet-commons-0.4.0/src/pushbulletapi.py pushbullet-commons-0.5.6/src/pushbulletapi.py --- pushbullet-commons-0.4.0/src/pushbulletapi.py 2015-03-24 07:33:11.000000000 +0000 +++ pushbullet-commons-0.5.6/src/pushbulletapi.py 2016-07-08 17:42:02.000000000 +0000 @@ -5,7 +5,7 @@ # # This file is part of PushBullet-Indicator # -# Copyright (C) 2014 +# Copyright (C) 2014-2016 # Lorenzo Carbonell Cerezo # # This program is free software: you can redistribute it and/or modify @@ -21,515 +21,737 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from gi.repository import GObject import json import requests import mimetypes -from urllib.parse import quote +try: + from urllib.parse import quote +except ImportError: + from urllib import quote import os from requests.auth import HTTPBasicAuth -from commons_configurator import Configuration -from commons_comun import internet_on import platform +from tokenizator import Tokenizator +from commons_comun import internet_on, TOKEN_DIR, TOKEN_FILE, TOKEN_PARAMS +from doitinbackgroundbullet import DoitInBackground +from idleobject import IdleObject + HOST = "https://api.pushbullet.com/v2" + def guess_type(filename): - return mimetypes.guess_type(filename)[0] or 'application/octet-stream' + return mimetypes.guess_type(filename)[0] or 'application/octet-stream' -class PushBullet(): - def __init__(self): - configuration = Configuration() - self.oauth_access_token = configuration.get('oauth_access_token') - self.source_user_iden = configuration.get('source_user_iden') - self.source_device_iden = configuration.get('source_device_iden') - self.contacts = {} - self.devices = {} - self.login = False - if internet_on(): - user = self.getUser() - print(user) - self.login = (user is not None) - print(self.login) - if self.login: - self.source_user_iden = user['iden'] - self.updateContacts() - self.updateDevices() - if self.source_device_iden is None or len(self.source_device_iden)==0 or self.source_device_iden not in self.devices.keys(): - found = False - model = platform.platform() - nickname = platform.linux_distribution()[0] - print(nickname,model) - for aiden in self.devices.keys(): - if 'model' in self.devices[aiden].keys() and self.devices[aiden]['model'] == model and self.devices[aiden]['active'] == True: - self.source_device_iden = aiden - print('Device exists, I found it') - found = True - if found == False: - print('Device doesnt exist, I will create new') - ans = self.createDevice(nickname,model) - self.source_device_iden = ans['iden'] - print('Device created') - configuration.set('source_user_iden',self.source_user_iden) - configuration.set('source_device_iden',self.source_device_iden) - configuration.save() - - def _request(self, method, url, postdata=None, params=None, files=None): - if internet_on(): - headers = {"Accept": "application/json", - "Content-Type": "application/json", - "User-Agent": "pyPushBullet"} - print(url) - print('self.oauth_access_token',self.oauth_access_token) - if postdata: - postdata = json.dumps(postdata) - try: - r = requests.request(method, - url, - data=postdata, - params=params, - headers=headers, - files=files, - auth=HTTPBasicAuth(self.oauth_access_token, "")) - - r.raise_for_status() - return r.json() - except requests.exceptions.HTTPError as e: - print(e) - if e.response.status_code == 401: - self.login = False - return None - - def isLogin(self): - return self.login - - def get_oauth_access_token(self): - return self.oauth_access_token - - def set_oauth_access_token(self,oauth_access_token): - self.oauth_access_token = oauth_access_token - - def get_source_user_iden(self): - return self.source_user_iden - - def get_source_device_iden(self): - return self.source_device_iden - - def updateDevices(self): - """ Get devices - https://docs.pushbullet.com/v2/devices - - Get a list of devices, and data about them. - """ - ans = {} - devices = self._request("GET", HOST + "/devices")["devices"] - for adevice in devices: - ans[adevice['iden']] = adevice - self.devices = ans - - def getDevices(self): - return self.devices - - def getActiveDevices(self): - """ Get active devices - https://docs.pushbullet.com/v2/devices - - Get a list of active devices, and data about them. - """ - ans = {} - for akey in self.devices.keys(): - adevice = self.devices[akey] - if 'active' in adevice.keys() and adevice['active']: - ans[akey] = adevice - return ans - - def getPushableDevices(self): - """ Get pushable devices - https://docs.pushbullet.com/v2/devices - - Get a list of pushable devices, and data about them. - """ - ans = {} - for akey in self.devices.keys(): - adevice = self.devices[akey] - if 'pushable' in adevice.keys() and adevice['pushable']: - ans[akey] = adevice - return ans - - def createDevice(self, nickname, model): - """ Create a new device - https://docs.pushbullet.com/v2/devices - - Arguments: - device_iden -- iden of device to push to - nickname -- nickname of device to push to - """ - data = {"nickname": nickname, - "type": "stream", - "model": model} - return self._request("POST", HOST + "/devices", data) - - - def deleteDevice(self, device_iden): - """ Delete a device - https://docs.pushbullet.com/v2/devices - - Arguments: - device_iden -- iden of device to push to - """ - - return self._request("DELETE", HOST + "/devices/" + device_iden) - - def pushNote(self, identification, title, body, iscontact = False): - """ Push a note - https://docs.pushbullet.com/v2/pushes - - Arguments: - device_iden -- iden of device to push to - title -- a title for the note - body -- the body of the note - """ - if iscontact: - identificator = 'email' - else: - identificator = 'device_iden' - data = {"type": "note", - identificator: identification, - "title": title, - "body": body} - return self._request("POST", HOST + "/pushes", data) - - def sendReply(self, package_name, source_user_iden, target_device_iden, conversation_iden, message): - """ Send a reply - https://docs.pushbullet.com/v2/pushes - - Arguments: - package_name -- package name - source_user_iden -- iden of device to push from - target_device_iden -- iden of device to push to - conversation_iden -- iden of the conversation - message -- The message - """ - data = {"type": "push", - "push": { - "type": "messaging_extension_reply", - "package_name": package_name, - "source_user_iden": source_user_iden, - "target_device_iden":target_device_iden, - "conversation_iden":conversation_iden, - "message":message - } - } - return self._request("POST", HOST + "/ephemerals", data) - - def pushCopy(self, body): - """ Push a copy - https://docs.pushbullet.com/v2/pushes - - Arguments: - device_iden -- iden of device to push to - title -- a title for the note - body -- the body of the note - """ - #"source_device_iden":source_device_iden - data = {"type": "push", - "push": { - "type": "clip", - "body": body, - "source_user_iden": self.source_user_iden, - "source_device_iden":self.source_device_iden - } - } - return self._request("POST", HOST + "/ephemerals", data) - - def pushLink(self, identification, title, body, url, iscontact = False): - """ Push a link - https://docs.pushbullet.com/v2/pushes - - Arguments: - device_iden -- iden of device to push to - title -- link title - url -- link url - """ - if iscontact: - identificator = 'email' - else: - identificator = 'device_iden' - data = {"type": "link", - identificator: identification, - "title": title, - "body":body, - "url": url} - return self._request("POST", HOST + "/pushes", data) - - def pushSMS(self, device_iden, number, message): - """ Push a sms - https://docs.pushbullet.com/v2/pushes - - Arguments: - device_iden -- iden of device to push from - number -- number of mobile to push to - message -- the message - """ - data = {"type": "push", - "push": { - "type": "messaging_extension_reply", - "package_name": "com.pushbullet.android", - "source_user_iden": self.source_user_iden, - "target_device_iden": device_iden, - "conversation_iden": number, - "message": message - } - } - return self._request("POST", HOST + "/ephemerals", data) - - def pushFile(self, identification, afile, body, iscontact = False): - """ Push a file - https://docs.pushbullet.com/v2/pushes - https://docs.pushbullet.com/v2/upload-request - - Arguments: - device_iden -- iden of device to push to - file_name -- name of the file - file -- a file object - file_type -- file mimetype, if not set, python-magic will be used - """ - if iscontact: - identificator = 'email' - else: - identificator = 'device_iden' - file_name = quote(os.path.basename(afile)) - file_type = guess_type(afile) - data = {"file_name": file_name, - "file_type": file_type} - - upload_request = self._request("GET", - HOST + "/upload-request", - None, - data) - - upload = requests.post(upload_request["upload_url"], - data=upload_request["data"], - files={"file": open(afile,'rb')}, - headers={"User-Agent": "pyPushBullet"}) - - upload.raise_for_status() - - data = {"type": "file", - identificator: identification, - "file_name": file_name, - "file_type": file_type, - "file_url": upload_request["file_url"], - "body": body} - - return self._request("POST", HOST + "/pushes", data) - - def getPushHistory(self, modified_after=0, cursor=None): - """ Get Push History - https://docs.pushbullet.com/v2/pushes - - Returns a list of pushes - - Arguments: - modified_after -- Request pushes modified after this timestamp - cursor -- Request another page of pushes (if necessary) - """ - data = {"modified_after": modified_after} - if cursor: - data["cursor"] = cursor - return self._request("GET", HOST + "/pushes", None, data)["pushes"] - - def getLastPush(self): - """ Get Push History - https://docs.pushbullet.com/v2/pushes - - Returns a list of pushes - - Arguments: - modified_after -- Request pushes modified after this timestamp - cursor -- Request another page of pushes (if necessary) - """ - ans = self._request("GET", HOST + "/pushes", None)["pushes"] - if len(ans)>0: - return ans[0] - return None - - def deletePush(self, push_iden): - """ Delete push - https://docs.pushbullet.com/v2/pushes - - Arguments: - push_iden -- the iden of the push to delete - """ - return self._request("DELETE", HOST + "/pushes/" + push_iden) - - def updateContacts(self): - """ Gets your contacts - https://docs.pushbullet.com/v2/contacts - - returns a list of contacts - """ - ans = {} - contacts = self._request("GET", HOST + "/contacts")["contacts"] - for acontact in contacts: - ans[acontact['iden']] = acontact - self.contacts = ans - - def getContacts(self): - return self.contacts - - def getPushableContacts(self): - """ Gets your pushable contacts - https://docs.pushbullet.com/v2/contacts - - returns a list of pushable contacts - """ - ans = {} - for akey in self.contacts.keys(): - acontact = self.contacts[akey] - if acontact['active'] and 'name' in acontact.keys() and 'email' in acontact.keys(): - ans[akey] = acontact - return ans - - def getSubscriptions(self): - """ List subscriptions - https://docs.pushbullet.com/v2/subscriptions - - Arguments: - """ - return self._request("GET", HOST + "/subscriptions") - - def subscribeToChannel(self, channel_tag): - """ Subscribe to channels to receive any updates pushed that channel - https://docs.pushbullet.com/v2/subscriptions - - Arguments: - channel_tag - The tag of the channel you wish to subscribe to. - """ - data = {"channel_tag": channel_tag - } - - return self._request("POST", HOST + "/subscriptions", data) - - def unsubscribeFromAChannel(self, channel_iden): - """ unubscribe from a channel - https://docs.pushbullet.com/v2/subscriptions - - Arguments: - channel_tag - The tag of the channel you wish to subscribe to. - """ - return self._request("DELETE", HOST + "/subscriptions/%s"%(channel_iden)) - - def getInfoAboutChannel(self, channel_tag): - """ Get info about channel - https://docs.pushbullet.com/v2/subscriptions - - Arguments: - channel_tag - The tag of the channel you wish to subscribe to. - """ - params = {"tag": channel_tag - } - - return self._request("GET", HOST + "/channel-info", params=params) - - - def createContact(self, email, name): - """ Create a new contact - https://docs.pushbullet.com/v2/contacts - - Arguments: - name -- the name of the contact to push to - email -- the email of the contact to push to - """ - data = {"name": name, - "email": email} - - return self._request("POST", HOST + "/contacts", data) - - def deleteContact(self, contact_iden): - """ Delete a contact - https://docs.pushbullet.com/v2/contacts - - Arguments: - contact_iden -- the iden of the contact to delete - """ - return self._request("DELETE", HOST + "/contacts/" + contact_iden) - - def getUser(self): - """ Get this users information - https://docs.pushbullet.com/v2/users - """ - return self._request("GET", HOST + "/users/me") -if __name__ == '__main__': - from logindialog import LoginDialog - pb = PushBullet() - while(pb.isLogin() == False): - ld = LoginDialog() - ld.run() - oauth_access_token = ld.code - print(ld.code) - configuration = Configuration() - configuration.set('oauth_access_token',oauth_access_token) - configuration.save() - pb = PushBullet() - print(pb.getActiveDevices()) - #print(pb.getDevices()) - #print(pb.getContacts()) - ''' - from commons_configurator import Configuration - from logindialog import LoginDialog - configuration = Configuration() - oauth_access_token = configuration.get('oauth_access_token') - while(oauth_access_token is None or len(oauth_access_token)==0): - ld = LoginDialog() - ld.run() - oauth_access_token = ld.code - print(oauth_access_token) - configuration.set('oauth_access_token',oauth_access_token) - configuration.save() - configuration.read() - oauth_access_token = configuration.get('oauth_access_token') - pb = PushBullet(oauth_access_token) - print(pb.getDevices()) - print('-----------------------------------------') - #print(pb.getContacts()) - #print(pb.getActiveDevices()) - #print(pb.getPushHistory()) - #print(pb.getPushableDevices()) - #print(pb.createDevice("test123")) - import platform - print(platform.architecture()) - print(platform.machine()) - print(platform.node()) - print(platform.platform()) - print(platform.processor()) - print(platform.release()) - print(platform.system()) - print(platform.version()) - print(platform.uname()) - #pb.pushList('ujEzQo9UWJMdjzZ2K35GjQ','Ejemplo',['1','2','3','4']) - #pb.pushNote('lorenzo.carbonell.cerezo@gmail.com','Ejemplo','Ejemplo',True) - print('--------------') - print(pb.getLastPush()) - print('--------------') - print(pb.getUser()) - print('--------------') - #print(pb.getSubscriptions()) - #print(pb.pushCopy('test')) - #iden = pb.getInfoAboutChannel('jblow')['iden'] - #print('--------------') - #print(iden) - #print(pb.unsubscribeFromAChannel(iden)) - #print(pb.pushCopy('ujEzQo9UWJM','ujEzQo9UWJMsjAdnpXG7P2','Probando, probando, ...')) - conversation_iden = {"package_name":"com.whatsapp","tag":None,"id":1} - - #conversation_iden = "+34600408294" - #package_name = "com.pushbullet.android" - #package_name = "com.whatsapp" - ''' - #package_name = "org.telegram.messenger" - #conversation_iden = {"package_name":"org.telegram.messenger","tag":None,"id":1000} - #print(pb.sendReply(package_name,'ujEzQo9UWJM','ujEzQo9UWJMsjz56puQSIe',conversation_iden,"%s"%1551)) - print(pb.pushSMS('ujEzQo9UWJMsjz56puQSIe','+34600408294','Esto es una prueba desde el Motorola')) - exit(0) +class PushBullet(IdleObject): + __gsignals__ = { + 'pushing': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + 'pushed': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()), + } + + def __init__(self, encryption_password=''): + IdleObject.__init__(self) + tokenizator = Tokenizator( + config_file_dir=TOKEN_DIR, + config_file=TOKEN_FILE, + default_params=TOKEN_PARAMS) + self.oauth_access_token = tokenizator.get('oauth_access_token') + self.source_user_iden = tokenizator.get('source_user_iden') + self.source_device_iden = tokenizator.get('source_device_iden') + self.contacts = {} + self.devices = {} + self.encryption_key = None + self.login = False + if internet_on(): + user = self.getUser() + print(user) + self.login = (user is not None) + print(self.login) + if self.login: + self.source_user_iden = user['iden'] + self.updateContacts() + self.updateDevices() + if self.source_device_iden is None or\ + len(self.source_device_iden) == 0 or\ + self.source_device_iden not in self.devices.keys(): + found = False + model = platform.platform() + nickname = platform.linux_distribution()[0] + print(nickname, model) + for aiden in self.devices.keys(): + if 'model' in self.devices[aiden].keys() and\ + self.devices[aiden]['model'] == model and\ + self.devices[aiden]['active'] is True: + self.source_device_iden = aiden + print('Device exists, I found it') + found = True + if found is False: + print('Device doesnt exist, I will create new') + ans = self.createDevice(nickname, model) + self.source_device_iden = ans['iden'] + print('Device created') + tokenizator.set('source_user_iden', self.source_user_iden) + tokenizator.set('source_device_iden', + self.source_device_iden) + tokenizator.save() + if self.source_device_iden is not None and\ + len(encryption_password) > 0: + try: + from cryptography.hazmat.primitives.kdf.pbkdf2 import \ + PBKDF2HMAC + from cryptography.hazmat.backends import default_backend + from cryptography.hazmat.primitives import hashes + except ImportError as e: + raise NoEncryptionModuleError(str(e)) + + kdf = PBKDF2HMAC( + algorithm=hashes.SHA256(), + length=32, + salt=self.source_user_iden.encode("ASCII"), + iterations=30000, + backend=default_backend() + ) + self.encryption_key = kdf.derive( + encryption_password.encode("UTF-8")) + + def _encrypt_data(self, data): + assert self.encryption_key + from cryptography.hazmat.primitives.ciphers import Cipher, \ + algorithms, modes + from cryptography.hazmat.backends import default_backend + from base64 import standard_b64encode + iv = os.urandom(12) + encryptor = Cipher( + algorithms.AES(self.encryption_key), + modes.GCM(iv), + backend=default_backend() + ).encryptor() + ciphertext = encryptor.update( + json.dumps(data).encode("UTF-8")) + encryptor.finalize() + ciphertext = b"1" + encryptor.tag + iv + ciphertext + return standard_b64encode(ciphertext).decode("ASCII") + + def _decrypt_data(self, encoded_message): + assert self.encryption_key + from cryptography.hazmat.primitives.ciphers import Cipher, \ + algorithms, modes + from cryptography.hazmat.backends import default_backend + from base64 import standard_b64decode + encoded_message = standard_b64decode( + encoded_message.encode('ASCII')) + version = encoded_message[0:1].decode() + if (version != "1"): + print('version:', version) + raise Exception('Invalid Version') + tag = encoded_message[1:17] # 128 bits + iv = encoded_message[17:29] # 96 bits + encrypted_message = encoded_message[29:] + decryptor = Cipher( + algorithms.AES(self.encryption_key), + modes.GCM(iv, tag), + backend=default_backend() + ).decryptor() + ciphertext = decryptor.update(encrypted_message) + decryptor.finalize() + return ciphertext.decode('utf-8') + + def _request(self, method, url, postdata=None, params=None, files=None): + if internet_on(): + headers = {"Accept": "application/json", + "Content-Type": "application/json", + "User-Agent": "pyPushBullet"} + print(url) + print('self.oauth_access_token', self.oauth_access_token) + if postdata: + postdata = json.dumps(postdata) + try: + r = requests.request(method, + url, + data=postdata, + params=params, + headers=headers, + files=files, + auth=HTTPBasicAuth( + self.oauth_access_token, "")) + + r.raise_for_status() + return r.json() + except requests.exceptions.HTTPError as e: + print(e) + if e.response.status_code == 401: + self.login = False + return None + + def restart(self): + self.__init__() + + def is_login(self): + return self.login + + def get_oauth_access_token(self): + return self.oauth_access_token + + def set_oauth_access_token(self, oauth_access_token): + self.oauth_access_token = oauth_access_token + + def get_source_user_iden(self): + return self.source_user_iden + + def get_source_device_iden(self): + return self.source_device_iden + + def updateDevices(self): + """ Get devices + https://docs.pushbullet.com/v2/devices + + Get a list of devices, and data about them. + """ + ans = {} + devices = self._request("GET", HOST + "/devices")["devices"] + for adevice in devices: + ans[adevice['iden']] = adevice + self.devices = ans + + def getDevices(self): + return self.devices + + def getActiveDevices(self): + """ Get active devices + https://docs.pushbullet.com/v2/devices + + Get a list of active devices, and data about them. + """ + ans = {} + for akey in self.devices.keys(): + adevice = self.devices[akey] + if 'active' in adevice.keys() and adevice['active']: + ans[akey] = adevice + return ans + + def getPushableDevices(self): + """ Get pushable devices + https://docs.pushbullet.com/v2/devices + + Get a list of pushable devices, and data about them. + """ + ans = {} + for akey in self.devices.keys(): + adevice = self.devices[akey] + if 'pushable' in adevice.keys() and adevice['pushable']: + ans[akey] = adevice + return ans + + def createDevice(self, nickname, model): + """ Create a new device + https://docs.pushbullet.com/v2/devices + + Arguments: + device_iden -- iden of device to push to + nickname -- nickname of device to push to + """ + data = {"nickname": nickname, + "type": "stream", + "model": model} + return self._request("POST", HOST + "/devices", data) + + def deleteDevice(self, device_iden): + """ Delete a device + https://docs.pushbullet.com/v2/devices + + Arguments: + device_iden -- iden of device to push to + """ + + return self._request("DELETE", HOST + "/devices/" + device_iden) + + def send_note(self, identification, title, body, iscontact=False): + dib = DoitInBackground( + self._send_note, identification, title, body, iscontact) + dib.connect('finished', self.post_emit, 'pushed') + self.emit('pushing') + dib.start() + + def _send_note(self, identification, title, body, iscontact=False): + """ Push a note + https://docs.pushbullet.com/v2/pushes + + Arguments: + device_iden -- iden of device to push to + title -- a title for the note + body -- the body of the note + """ + if iscontact: + identificator = 'email' + else: + identificator = 'device_iden' + data = {"type": "note", + identificator: identification, + "title": title, + "body": body} + return self._request("POST", HOST + "/pushes", data) + + def send_reply(self, package_name, source_user_iden, target_device_iden, + conversation_iden, message): + dib = DoitInBackground( + self._send_reply, package_name, source_user_iden, + target_device_iden, conversation_iden, message) + dib.connect('finished', self.post_emit, 'pushed') + self.emit('pushing') + dib.start() + + def _send_reply(self, package_name, source_user_iden, target_device_iden, + conversation_iden, message): + """ Send a reply + https://docs.pushbullet.com/v2/pushes + + Arguments: + package_name -- package name + source_user_iden -- iden of device to push from + target_device_iden -- iden of device to push to + conversation_iden -- iden of the conversation + message -- The message + """ + if self.encryption_key is None: + data = {"type": "push", + "push": { + "type": "messaging_extension_reply", + "package_name": package_name, + "source_user_iden": source_user_iden, + "target_device_iden": target_device_iden, + "conversation_iden": conversation_iden, + "message": message + } + } + else: + push = {"type": "messaging_extension_reply", + "package_name": package_name, + "source_user_iden": source_user_iden, + "target_device_iden": target_device_iden, + "conversation_iden": conversation_iden, + "message": message + } + ciphertext = self._encrypt_data(push) + data = {"type": "push", + "push": {'encrypted': True, + 'ciphertext': ciphertext} + } + return self._request("POST", HOST + "/ephemerals", data) + + def send_dimissal(self, notification_id, notification_tag, + package_name, sourse_user_iden): + dib = DoitInBackground( + self._send_dimissal, notification_id, notification_tag, + package_name, sourse_user_iden) + dib.connect('finished', self.post_emit, 'pushed') + self.emit('pushing') + dib.start() + + def _send_dimissal(self, notification_id, notification_tag, + package_name, sourse_user_iden): + """ Send a reply + https://docs.pushbullet.com/v2/pushes + + Arguments: + package_name -- package name + source_user_iden -- iden of device to push from + target_device_iden -- iden of device to push to + conversation_iden -- iden of the conversation + message -- The message + """ + if self.encryption_key is None: + data = {"type": "push", + "push": { + 'notification_id': notification_id, + 'notification_tag': notification_tag, + 'package_name': package_name, + 'sourse_user_iden': sourse_user_iden, + 'type': 'dimissal' + } + } + else: + push = {'notification_id': notification_id, + 'notification_tag': notification_tag, + 'package_name': package_name, + 'sourse_user_iden': sourse_user_iden, + 'type': 'dimissal' + } + ciphertext = self._encrypt_data(push) + data = {"type": "push", + "push": {'encrypted': True, + 'ciphertext': ciphertext} + } + return self._request("POST", HOST + "/ephemerals", data) + + def send_copy(self, body): + dib = DoitInBackground( + self._send_copy, body) + dib.connect('finished', self.post_emit, 'pushed') + self.emit('pushing') + dib.start() + + def _send_copy(self, body): + """ Push a copy + https://docs.pushbullet.com/v2/pushes + + Arguments: + device_iden -- iden of device to push to + title -- a title for the note + body -- the body of the note + """ + if self.encryption_key is None: + data = {"type": "push", + "push": { + "type": "clip", + "body": "%s" % str(body), + "source_user_iden": self.source_user_iden, + "source_device_iden": self.source_device_iden + } + } + else: + push = {"type": "clip", + "body": "%s" % str(body), + "source_user_iden": self.source_user_iden, + "source_device_iden": self.source_device_iden + } + ciphertext = self._encrypt_data(push) + data = {"type": "push", + "push": {'encrypted': True, + 'ciphertext': ciphertext} + } + return self._request("POST", HOST + "/ephemerals", data) + + def send_link(self, identification, title, body, url, iscontact=False): + dib = DoitInBackground( + self._send_link, identification, title, body, url, iscontact) + dib.connect('finished', self.post_emit, 'pushed') + self.emit('pushing') + dib.start() + + def _send_link(self, identification, title, body, url, iscontact=False): + """ Push a link + https://docs.pushbullet.com/v2/pushes + + Arguments: + device_iden -- iden of device to push to + title -- link title + url -- link url + """ + if iscontact: + identificator = 'email' + else: + identificator = 'device_iden' + data = {"type": "link", + identificator: identification, + "title": title, + "body": body, + "url": url} + return self._request("POST", HOST + "/pushes", data) + + def send_sms(self, device_iden, number, message): + dib = DoitInBackground( + self._send_sms, device_iden, number, message) + dib.connect('finished', self.post_emit, 'pushed') + self.emit('pushing') + dib.start() + + def _send_sms(self, device_iden, number, message): + """ Push a sms + https://docs.pushbullet.com/v2/pushes + + Arguments: + device_iden -- iden of device to push from + number -- number of mobile to push to + message -- the message + """ + data = {"type": "push", + "push": { + "type": "messaging_extension_reply", + "package_name": "com.pushbullet.android", + "source_user_iden": self.source_user_iden, + "target_device_iden": device_iden, + "conversation_iden": number, + "message": message + } + } + if self.encryption_key is not None: + data["push"] = { + "ciphertext": self._encrypt_data(data["push"]), + "encrypted": True + } + return self._request("POST", HOST + "/ephemerals", data) + + def send_file(self, identification, afile, body, iscontact=False): + dib = DoitInBackground( + self._send_file, identification, afile, body, iscontact) + dib.connect('finished', self.post_emit, 'pushed') + self.emit('pushing') + dib.start() + + def send_a_file(self, afile=None, identification=None, + body=None, iscontact=False): + self._send_file(identification=identification, afile=afile, + body=body, iscontact=False) + + def post_emit(self, dib, signal): + self.emit(signal) + + def _send_file(self, identification=None, afile=None, + body=None, iscontact=False): + """ Push a file + https://docs.pushbullet.com/v2/pushes + https://docs.pushbullet.com/v2/upload-request + + Arguments: + device_iden -- iden of device to push to + file_name -- name of the file + file -- a file object + file_type -- file mimetype, if not set, python-magic will be used + """ + if iscontact: + identificator = 'email' + else: + identificator = 'device_iden' + file_name = quote(os.path.basename(afile)) + file_type = guess_type(afile) + data = {"file_name": file_name, + "file_type": file_type} + + upload_request = self._request("GET", + HOST + "/upload-request", + None, + data) + + upload = requests.post(upload_request["upload_url"], + data=upload_request["data"], + files={"file": open(afile, 'rb')}, + headers={"User-Agent": "pyPushBullet"}) + + upload.raise_for_status() + + data = {"type": "file", + identificator: identification, + "file_name": file_name, + "file_type": file_type, + "file_url": upload_request["file_url"], + "body": body} + return self._request("POST", HOST + "/pushes", data) + + def getPushHistory(self, modified_after=0, cursor=None): + """ Get Push History + https://docs.pushbullet.com/v2/pushes + + Returns a list of pushes + + Arguments: + modified_after -- Request pushes modified after this timestamp + cursor -- Request another page of pushes (if necessary) + """ + data = {"modified_after": modified_after} + if cursor: + data["cursor"] = cursor + return self._request("GET", HOST + "/pushes", None, data)["pushes"] + + def getLastPush(self): + """ Get Push History + https://docs.pushbullet.com/v2/pushes + + Returns a list of pushes + + Arguments: + modified_after -- Request pushes modified after this timestamp + cursor -- Request another page of pushes (if necessary) + """ + ans = self._request("GET", HOST + "/pushes", None)["pushes"] + if len(ans) > 0: + return ans[0] + return None + + def deletePush(self, push_iden): + """ Delete push + https://docs.pushbullet.com/v2/pushes + + Arguments: + push_iden -- the iden of the push to delete + """ + return self._request("DELETE", HOST + "/pushes/" + push_iden) + + def updateContacts(self): + """ Gets your contacts + https://docs.pushbullet.com/v2/contacts + + returns a list of contacts + """ + ans = {} + contacts = self._request("GET", HOST + "/contacts")["contacts"] + for acontact in contacts: + ans[acontact['iden']] = acontact + self.contacts = ans + + def getContacts(self): + return self.contacts + + def getPushableContacts(self): + """ Gets your pushable contacts + https://docs.pushbullet.com/v2/contacts + + returns a list of pushable contacts + """ + ans = {} + for akey in self.contacts.keys(): + acontact = self.contacts[akey] + if acontact['active'] and 'name' in acontact.keys() and\ + 'email' in acontact.keys(): + ans[akey] = acontact + return ans + + def getSubscriptions(self): + """ List subscriptions + https://docs.pushbullet.com/v2/subscriptions + + Arguments: + """ + return self._request("GET", HOST + "/subscriptions") + + def subscribeToChannel(self, channel_tag): + """ Subscribe to channels to receive any updates pushed that channel + https://docs.pushbullet.com/v2/subscriptions + + Arguments: + channel_tag - The tag of the channel you wish to subscribe to. + """ + data = {"channel_tag": channel_tag} + return self._request("POST", HOST + "/subscriptions", data) + + def unsubscribeFromAChannel(self, channel_iden): + """ unubscribe from a channel + https://docs.pushbullet.com/v2/subscriptions + + Arguments: + channel_tag - The tag of the channel you wish to subscribe to. + """ + return self._request( + "DELETE", HOST + "/subscriptions/%s" % (channel_iden)) + + def getInfoAboutChannel(self, channel_tag): + """ Get info about channel + https://docs.pushbullet.com/v2/subscriptions + + Arguments: + channel_tag - The tag of the channel you wish to subscribe to. + """ + params = {"tag": channel_tag} + return self._request("GET", HOST + "/channel-info", params=params) + + def createContact(self, email, name): + """ Create a new contact + https://docs.pushbullet.com/v2/contacts + + Arguments: + name -- the name of the contact to push to + email -- the email of the contact to push to + """ + data = {"name": name, + "email": email} + + return self._request("POST", HOST + "/contacts", data) + + def deleteContact(self, contact_iden): + """ Delete a contact + https://docs.pushbullet.com/v2/contacts + + Arguments: + contact_iden -- the iden of the contact to delete + """ + return self._request("DELETE", HOST + "/contacts/" + contact_iden) + + def getUser(self): + """ Get this users information + https://docs.pushbullet.com/v2/users + """ + return self._request("GET", HOST + "/users/me") + def getChats(self): + return self._request("GET", HOST + "/chats") + +if __name__ == '__main__': + from logindialog import LoginDialog + pb = PushBullet('euldlmdc') + while(pb.is_login() is False): + ld = LoginDialog() + ld.run() + oauth_access_token = ld.code + print(ld.code) + tokenizator = Tokenizator() + tokenizator.set('oauth_access_token', oauth_access_token) + tokenizator.save() + pb = PushBullet() + print(pb.getActiveDevices()) + # print(pb.getDevices()) + # print(pb.getContacts()) + ''' + from commons_configurator import Configuration + from logindialog import LoginDialog + tokenizator = Tokenizator() + oauth_access_token = tokenizator.get('oauth_access_token') + while(oauth_access_token is None or len(oauth_access_token)==0): + ld = LoginDialog() + ld.run() + oauth_access_token = ld.code + print(oauth_access_token) + tokenizator.set('oauth_access_token',oauth_access_token) + tokenizator.save() + tokenizator.read() + oauth_access_token = tokenizator.get('oauth_access_token') + pb = PushBullet(oauth_access_token) + print(pb.getDevices()) + print('-----------------------------------------') + #print(pb.getContacts()) + #print(pb.getActiveDevices()) + #print(pb.getPushHistory()) + #print(pb.getPushableDevices()) + #print(pb.createDevice("test123")) + import platform + print(platform.architecture()) + print(platform.machine()) + print(platform.node()) + print(platform.platform()) + print(platform.processor()) + print(platform.release()) + print(platform.system()) + print(platform.version()) + print(platform.uname()) + #pb.pushList('ujEzQo9UWJMdjzZ2K35GjQ','Ejemplo',['1','2','3','4']) + #pb.pushNote('lorenzo.carbonell.cerezo@gmail.com','Ejemplo','Ejemplo',True) + print('--------------') + print(pb.getLastPush()) + print('--------------') + print(pb.getUser()) + print('--------------') + #print(pb.getSubscriptions()) + #print(pb.pushCopy('test')) + #iden = pb.getInfoAboutChannel('jblow')['iden'] + #print('--------------') + #print(iden) + #print(pb.unsubscribeFromAChannel(iden)) + #print(pb.pushCopy( + 'ujEzQo9UWJM', 'ujEzQo9UWJMsjAdnpXG7P2','Probando, probando, ...')) + conversation_iden = {"package_name":"com.whatsapp","tag":None,"id":1} + + #conversation_iden = "+34600408294" + #package_name = "com.pushbullet.android" + #package_name = "com.whatsapp" + ''' + ''' + package_name = "org.telegram.messenger" + conversation_iden = {"package_name": "org.telegram.messenger", + "tag":None, "id":1000} + #print(pb.sendReply( + package_name, 'ujEzQo9UWJM', 'ujEzQo9UWJMsjz56puQSIe', + conversation_iden,"%s"%1551)) + ''' + # print(pb.getUser()) + ans = pb._encrypt_data({'test': 'esto es una prueba'}) + print(ans) + print(pb._decrypt_data(ans)) + exit(0) diff -Nru pushbullet-commons-0.4.0/src/pushbullet_dialogs.py pushbullet-commons-0.5.6/src/pushbullet_dialogs.py --- pushbullet-commons-0.4.0/src/pushbullet_dialogs.py 2015-03-28 06:10:08.000000000 +0000 +++ pushbullet-commons-0.5.6/src/pushbullet_dialogs.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,594 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# pushbulet_dialogs.py -# -# This file is part of PushBullet-Indicator -# -# Copyright (C) 2014 -# Lorenzo Carbonell Cerezo -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk -from gi.repository import Gdk -from gi.repository import GdkPixbuf -import os -from os.path import splitext, basename -import commons_comun -from commons_comun import _ -from commons_configurator import Configuration -from commons_comun import internet_on -try: - from urllib.request import urlopen - from urllib.request import Request - from urllib.parse import urlparse - from urllib.request import url2pathname -except ImportError: - from urllib import url2pathname - from urllib import urlopen - from urllib2 import Request - from urlparse import urlparse -NOTE_PAGE = 0 -LINK_PAGE = 1 -FILE_PAGE = 2 -IMAGE_PAGE = 3 - -class DropArea(Gtk.EventBox): - def __init__(self,on_clicked_response=False, message=_('Drop one file on me!')): - Gtk.EventBox.__init__(self) - self.label = Gtk.Label(message) - dnd_list = Gtk.TargetEntry.new('text/uri-list', 0, 0) - self.label.drag_dest_set(Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP,[dnd_list],Gdk.DragAction.MOVE ) - self.label.drag_dest_add_uri_targets() - self.label.connect('drag-data-received', self.on_drag_data_received) - self.add(self.label) - self.connect('button_press_event',self.on_clicked) - self.filename = None - self.fileurl = None - self.on_clicked_response = on_clicked_response - def on_clicked(self,widget,data): - if self.filename and self.fileurl and self.on_clicked_response: - dialog = Gtk.FileChooserDialog(_('Please choose a directory to download the file'), None, - Gtk.FileChooserAction.SELECT_FOLDER,(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) - response = dialog.run() - if response == Gtk.ResponseType.OK: - dialog.hide() - directory = dialog.get_filename() - dialog.destroy() - while Gtk.events_pending(): - Gtk.main_iteration() - print(self.fileurl) - filename = os.path.join(directory,basename(urlparse(self.fileurl).path)) - headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', - 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', - 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', - 'Accept-Encoding': 'none', - 'Accept-Language': 'en-US,en;q=0.8', - 'Connection': 'keep-alive'} - arequest = Request(self.fileurl, headers=headers) - page = urlopen(arequest) - with open(filename, 'bw') as f: - f.write(page.read()) - else: - dialog.destroy() - - def on_drag_data_received(self, widget, drag_context, x,y, selection_data,info, time): - if info == 0: - response = [] - filenames = selection_data.get_uris() - self.fileurl = url2pathname(filenames[0])[7:] - self.filename = os.path.basename(self.fileurl) - self.label.set_text(self.filename) - - def set_filename(self,filename): - self.filename = filename - self.label.set_text(filename+'\n\n'+_('(Click on me to download file)')) - - def get_filename(self): - return self.filename - - def set_fileurl(self,fileurl): - self.fileurl = fileurl - - def get_fileurl(self): - return self.fileurl - -class SendToDialog(Gtk.Dialog): - def __init__(self,devices=None,contacts=None): - # - Gtk.Dialog.__init__(self, _('PushBullet action'),None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)) - self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) - self.connect('close', self.close_application) - self.set_icon_from_file(commons_comun.ICON) - # - vbox0 = Gtk.VBox(spacing = 5) - vbox0.set_border_width(5) - #vbox0.set_size_request(400, 80) - self.get_content_area().add(vbox0) - ''' - devices = [] - devices.append({'label':'1','device_iden':'11'}) - devices.append({'label':'2','device_iden':'12'}) - devices.append({'label':'3','device_iden':'13'}) - contacts = [] - contacts.append({'name':'4','contact_iden':'41'}) - contacts.append({'name':'5','contact_iden':'52'}) - contacts.append({'name':'6','contact_iden':'63'}) - ''' - #*************************************************************** - table_to = Gtk.Table(2, 2, False) - vbox0.pack_start(table_to,False,False,0) - label_to = Gtk.Label(_('Send bullet to')+':') - label_to.set_alignment(0, 0.5) - table_to.attach(label_to,0,1,0,1, xpadding=5, ypadding=5) - name_store = Gtk.ListStore(str,str,GdkPixbuf.Pixbuf,str) - toall = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(commons_comun.ICONDIR,"infinity.svg"), 32, 32) - tomobile = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(commons_comun.ICONDIR,"mobile.svg"), 32, 32) - touser = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(commons_comun.ICONDIR,"user.svg"), 32, 32) - name_store.append([_('All'),'',toall,'all']) - for adevice in devices: - name_store.append([adevice['label'],adevice['device_iden'],tomobile,'device']) - for acontact in contacts: - name_store.append([acontact['name'],acontact['contact_iden'],touser,'contact']) - self.bulletTo = Gtk.ComboBox.new_with_model(name_store) - renderertext = Gtk.CellRendererText() - renderertext.props.mode = Gtk.CellRendererMode.ACTIVATABLE - self.bulletTo.pack_start(renderertext, False) - self.bulletTo.add_attribute(renderertext, "text", 0) - renderer = Gtk.CellRendererPixbuf() - self.bulletTo.pack_start(renderer, False) - self.bulletTo.add_attribute(renderer, "pixbuf", 2) - table_to.attach(self.bulletTo,1,2,0,1, xpadding=5, ypadding=5) - self.bulletTo.set_active(0) - self.show_all() - - def get_selected_in_combo(self): - tree_iter = self.bulletTo.get_active_iter() - if tree_iter != None: - model = self.bulletTo.get_model() - label, iden, pb, ttype = model[tree_iter] - return {'label':label,'iden':iden,'type':ttype} - return None - - def get_response(self): - return self.get_selected_in_combo() - - def close_application(self, widget): - self.hide() - -class ActionDialog(Gtk.Dialog): - - def __init__(self,push=None,devices=None,contacts=None): - # - Gtk.Dialog.__init__(self, _('PushBullet action'),None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)) - self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) - self.connect('close', self.close_application) - self.set_icon_from_file(commons_comun.ICON) - # - vbox0 = Gtk.VBox(spacing = 5) - vbox0.set_border_width(5) - vbox0.set_size_request(400, 400) - self.get_content_area().add(vbox0) - ''' - devices = [] - devices.append({'label':'1','device_iden':'11'}) - devices.append({'label':'2','device_iden':'12'}) - devices.append({'label':'3','device_iden':'13'}) - contacts = [] - contacts.append({'name':'4','contact_iden':'41'}) - contacts.append({'name':'5','contact_iden':'52'}) - contacts.append({'name':'6','contact_iden':'63'}) - ''' - self.bulletTo = None - #*************************************************************** - if devices is not None and contacts is not None: - table_to = Gtk.Table(2, 2, False) - vbox0.pack_start(table_to,True,True,0) - label_to = Gtk.Label(_('To')+':') - label_to.set_alignment(0, 0.5) - table_to.attach(label_to,0,1,0,1, xpadding=5, ypadding=5) - name_store = Gtk.ListStore(str,str,GdkPixbuf.Pixbuf,str) - toall = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(commons_comun.ICONDIR,"infinity.svg"), 32, 32) - tomobile = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(commons_comun.ICONDIR,"mobile.svg"), 32, 32) - touser = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(commons_comun.ICONDIR,"user.svg"), 32, 32) - name_store.append([_('All'),'',toall,'all']) - for adevice in devices: - name_store.append([adevice['label'],adevice['device_iden'],tomobile,'device']) - for acontact in contacts: - name_store.append([acontact['name'],acontact['contact_iden'],touser,'contact']) - #self.bulletTo = Gtk.ComboBox.new_with_model_and_entry(name_store) - self.bulletTo = Gtk.ComboBox.new_with_model(name_store) - renderertext = Gtk.CellRendererText() - renderertext.props.mode = Gtk.CellRendererMode.ACTIVATABLE - self.bulletTo.pack_start(renderertext, False) - self.bulletTo.add_attribute(renderertext, "text", 0) - renderer = Gtk.CellRendererPixbuf() - self.bulletTo.pack_start(renderer, False) - self.bulletTo.add_attribute(renderer, "pixbuf", 2) - table_to.attach(self.bulletTo,1,2,0,1, xpadding=5, ypadding=5) - self.bulletTo.set_active(0) - - self.notebook = Gtk.Notebook() - self.notebook.set_tab_pos(Gtk.PositionType.BOTTOM) - vbox0.pack_start(self.notebook,True,True,0) - self.action = {} - # - self.action['note'] = {} - frame_note = Gtk.Frame() - frame_note.set_border_width(10) - vbox_note = Gtk.VBox() - frame_note.add(vbox_note) - table_note = Gtk.Table(2, 2, False) - vbox_note.pack_start(table_note,False,False,0) - label_note_1 = Gtk.Label(_('Title')+':') - label_note_1.set_alignment(0, 0.5) - table_note.attach(label_note_1,0,1,0,1, xpadding=5, ypadding=5) - self.action['note']['title'] = Gtk.Entry() - table_note.attach(self.action['note']['title'],1,2,0,1, xpadding=5, ypadding=5) - label_note_2 = Gtk.Label(_('Message')+':') - label_note_2.set_alignment(0, 0.5) - table_note.attach(label_note_2,0,1,1,2, xpadding=5, ypadding=5) - scrolledwindow_note = Gtk.ScrolledWindow() - scrolledwindow_note.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) - scrolledwindow_note.set_shadow_type(Gtk.ShadowType.ETCHED_OUT) - table_note.attach(scrolledwindow_note,1,2,1,2, xpadding=5, ypadding=5) - self.action['note']['body'] = Gtk.TextView() - self.action['note']['body'].set_wrap_mode(Gtk.WrapMode.WORD) - scrolledwindow_note.add(self.action['note']['body']) - scrolledwindow_note.set_size_request(200, 200) - image_note = Gtk.Image() - image_note.set_from_file(commons_comun.NOTE_ICON) - image_note_container = Gtk.Button() - image_note_container.set_name('note') - image_note_container.set_tooltip_text(_('Note')) - image_note_container.set_size_request(24,24) - image_note_container.set_image(image_note) - image_note_container.connect('clicked',self.on_container_clicked,'note') - self.notebook.append_page(frame_note,image_note_container) - # - self.action['link'] = {} - frame_link = Gtk.Frame() - frame_link.set_border_width(10) - vbox_link = Gtk.VBox() - frame_link.add(vbox_link) - table_link = Gtk.Table(2, 2, False) - vbox_link.pack_start(table_link,False,False,0) - label_link_1 = Gtk.Label(_('Title')+':') - label_link_1.set_alignment(0, 0.5) - table_link.attach(label_link_1,0,1,0,1, xpadding=5, ypadding=5) - self.action['link']['title'] = Gtk.Entry() - table_link.attach(self.action['link']['title'],1,2,0,1, xpadding=5, ypadding=5) - label_link_2 = Gtk.Label(_('Link')+':') - label_link_2.set_alignment(0, 0.5) - table_link.attach(label_link_2,0,1,1,2, xpadding=5, ypadding=5) - self.action['link']['link'] = Gtk.Entry() - table_link.attach(self.action['link']['link'],1,2,1,2, xpadding=5, ypadding=5) - - label_link_3 = Gtk.Label(_('Message')+':') - label_link_3.set_alignment(0, 0.5) - table_link.attach(label_link_3,0,1,2,3, xpadding=5, ypadding=5) - scrolledwindow_link = Gtk.ScrolledWindow() - scrolledwindow_link.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) - scrolledwindow_link.set_shadow_type(Gtk.ShadowType.ETCHED_OUT) - table_link.attach(scrolledwindow_link,1,2,2,3, xpadding=5, ypadding=5) - self.action['link']['body'] = Gtk.TextView() - self.action['link']['body'].set_wrap_mode(Gtk.WrapMode.WORD) - scrolledwindow_link.add(self.action['link']['body']) - scrolledwindow_link.set_size_request(200, 200) - image_link = Gtk.Image() - image_link.set_from_file(commons_comun.LINK_ICON) - image_link_container = Gtk.Button() - image_link_container.set_name('link') - image_link_container.set_tooltip_text(_('Link')) - image_link_container.set_size_request(24,24) - image_link_container.set_image(image_link) - image_link_container.connect('clicked',self.on_container_clicked,'link') - self.notebook.append_page(frame_link,image_link_container) - # - self.action['file'] = {} - frame_file = Gtk.Frame() - frame_file.set_border_width(10) - vbox_file = Gtk.VBox() - frame_file.add(vbox_file) - self.action['file']['file'] = DropArea(push is not None,_('Drop one file on me!')) - vbox_file.pack_start(self.action['file']['file'],True,True,0) - table_file = Gtk.Table(2, 2, False) - vbox_file.pack_start(table_file,True,True,0) - label_file = Gtk.Label(_('Message')+':') - label_file.set_alignment(0, 0.5) - table_file.attach(label_file,0,1,0,1, xpadding=5, ypadding=5) - scrolledwindow_file = Gtk.ScrolledWindow() - scrolledwindow_file.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) - scrolledwindow_file.set_shadow_type(Gtk.ShadowType.ETCHED_OUT) - table_file.attach(scrolledwindow_file,1,2,0,1, xpadding=5, ypadding=5) - self.action['file']['body'] = Gtk.TextView() - self.action['file']['body'].set_wrap_mode(Gtk.WrapMode.WORD) - scrolledwindow_file.add(self.action['file']['body']) - scrolledwindow_file.set_size_request(200, 100) - image_file = Gtk.Image() - image_file.set_from_file(commons_comun.FILE_ICON) - image_file_container = Gtk.Button() - image_file_container.set_name('file') - image_file_container.set_tooltip_text(_('File')) - image_file_container.set_size_request(24,24) - image_file_container.set_image(image_file) - image_file_container.connect('clicked',self.on_container_clicked,'file') - self.notebook.append_page(frame_file,image_file_container) - # - self.action['image'] = {} - frame_image = Gtk.Frame() - frame_image.set_border_width(10) - vbox_image = Gtk.VBox() - frame_image.add(vbox_image) - self.action['image']['file'] = DropArea(push is not None,_('Drop one image on me!')) - vbox_image.pack_start(self.action['image']['file'],True,True,0) - - table_image = Gtk.Table(2, 2, False) - vbox_image.pack_start(table_image,True,True,0) - label_image = Gtk.Label(_('Message')+':') - label_image.set_alignment(0, 0.5) - table_image.attach(label_image,0,1,0,1, xpadding=5, ypadding=5) - scrolledwindow_image = Gtk.ScrolledWindow() - scrolledwindow_image.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) - scrolledwindow_image.set_shadow_type(Gtk.ShadowType.ETCHED_OUT) - table_image.attach(scrolledwindow_image,1,2,0,1, xpadding=5, ypadding=5) - self.action['image']['body'] = Gtk.TextView() - self.action['image']['body'].set_wrap_mode(Gtk.WrapMode.WORD) - scrolledwindow_image.add(self.action['image']['body']) - scrolledwindow_image.set_size_request(200, 100) - - image_image = Gtk.Image() - image_image.set_from_file(commons_comun.IMAGE_ICON) - image_image_container = Gtk.Button() - image_image_container.set_name('image') - image_image_container.set_tooltip_text(_('File')) - image_image_container.set_size_request(24,24) - image_image_container.set_image(image_image) - image_image_container.connect('clicked',self.on_container_clicked,'image') - self.notebook.append_page(frame_image,image_image_container) - # - style_provider = Gtk.CssProvider() - css = """ - #address{ - border-image: none; - background-image: none; - border-radius: 0px; - background-color: @bg_color; - } - #address:hover{ - transition: 1000ms linear; - border-image: none; - background-image: none; - border-radius: 0px; - background-color: rgba(241, 196, 15, 255); - } - #link{ - border-image: none; - background-image: none; - border-radius: 0px; - background-color: @bg_color; - } - #link:hover{ - transition: 1000ms linear; - border-image: none; - background-image: none; - border-radius: 0px; - background-color: rgba(52, 152, 219, 255); - } - #list{ - border-image: none; - background-image: none; - border-radius: 0px; - background-color: @bg_color; - } - #list:hover{ - transition: 1000ms linear; - border-image: none; - background-image: none; - border-radius: 0px; - background-color: rgba(155, 89, 182, 255); - } - #file{ - border-image: none; - background-image: none; - border-radius: 0px; - background-color: @bg_color; - } - #file:hover{ - transition: 1000ms linear; - border-image: none; - background-image: none; - border-radius: 0px; - background-color: rgba(231, 76, 60, 255); - } - #image{ - border-image: none; - background-image: none; - border-radius: 0px; - background-color: @bg_color; - } - #image:hover{ - transition: 1000ms linear; - border-image: none; - background-image: none; - border-radius: 0px; - background-color: rgba(76, 231, 60, 255); - } - #note{ - border-image: none; - background-image: none; - border-radius: 0px; - background-color: @bg_color; - } - #note:hover{ - transition: 1000ms linear; - border-image: none; - background-image: none; - border-radius: 0px; - background-color: rgba(230, 126, 34, 255); - } - """ - style_provider.load_from_data(css.encode('UTF-8')) - Gtk.StyleContext.add_provider_for_screen( - Gdk.Screen.get_default(), - style_provider, - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION - ) - self.show_all() - if push is not None and 'type' in push.keys(): - if push['type'] == 'note': - self.notebook.set_current_page(NOTE_PAGE) - if 'title' in push: - self.action['note']['title'].set_text(push['title']) - if 'body' in push: - self.action['note']['body'].get_buffer().set_text(push['body']) - self.notebook.remove_page(IMAGE_PAGE) - self.notebook.remove_page(FILE_PAGE) - self.notebook.remove_page(LINK_PAGE) - elif push['type'] == 'link': - self.notebook.set_current_page(LINK_PAGE) - if 'title' in push: - self.action['link']['title'].set_text(push['title']) - if 'url' in push: - self.action['link']['link'].set_text(push['url']) - if 'body' in push: - self.action['link']['body'].get_buffer().set_text(push['body']) - self.notebook.remove_page(LIST_PAGE) - self.notebook.remove_page(FILE_PAGE) - self.notebook.remove_page(NOTE_PAGE) - elif push['type'] == 'file': - self.notebook.set_current_page(FILE_PAGE) - if 'file_name' in push: - self.action['file']['file'].set_filename(push['file_name']) - if 'file_url' in push: - self.action['file']['file'].set_fileurl(push['file_url']) - if 'body' in push: - self.action['file']['body'].get_buffer().set_text(push['body']) - self.notebook.remove_page(IMAGE_PAGE) - self.notebook.remove_page(LINK_PAGE) - self.notebook.remove_page(NOTE_PAGE) - elif push['type'] == 'image': - self.notebook.set_current_page(IMAGE_PAGE) - if 'file_name' in push: - self.action['file']['file'].set_filename(push['file_name']) - if 'file_url' in push: - self.action['file']['file'].set_fileurl(push['file_url']) - if 'body' in push: - self.action['image']['body'].get_buffer().set_text(push['body']) - self.notebook.remove_page(FILE_PAGE) - self.notebook.remove_page(LINK_PAGE) - self.notebook.remove_page(NOTE_PAGE) - # - def get_selected_in_combo(self): - tree_iter = self.bulletTo.get_active_iter() - if tree_iter != None: - model = self.bulletTo.get_model() - label, iden, pb, ttype = model[tree_iter] - return {'label':label,'iden':iden,'type':ttype} - - def on_container_clicked(self,widget,container_id): - if container_id == 'note': - self.notebook.set_current_page(NOTE_PAGE) - elif container_id == 'link': - self.notebook.set_current_page(LINK_PAGE) - elif container_id == 'file': - self.notebook.set_current_page(FILE_PAGE) - elif container_id == 'image': - self.notebook.set_current_page(IMAGE_PAGE) - def close_application(self, widget): - self.hide() - def get_response(self): - page = self.notebook.get_current_page() - response = {} - if self.bulletTo is not None: - ans = self.get_selected_in_combo() - response['to'] = ans - if page == FILE_PAGE: - response['kind'] = 'file' - response['file'] = self.action['file']['file'].get_fileurl() - tbuffer =self.action['file']['body'].get_buffer() - inicio = tbuffer.get_start_iter() - fin = tbuffer.get_end_iter() - response['body'] = tbuffer.get_text(inicio,fin,True) - elif page == IMAGE_PAGE: - response['kind'] = 'image' - response['file'] = self.action['image']['file'].get_fileurl() - tbuffer =self.action['image']['body'].get_buffer() - inicio = tbuffer.get_start_iter() - fin = tbuffer.get_end_iter() - response['body'] = tbuffer.get_text(inicio,fin,True) - elif page == LINK_PAGE: - response['kind'] = 'link' - response['title'] = self.action['link']['title'].get_text() - link = self.action['link']['link'].get_text() - if not link.startswith('http://') and not link.startswith('https://'): - link = 'http://' + link - response['link'] = link - tbuffer =self.action['link']['body'].get_buffer() - inicio = tbuffer.get_start_iter() - fin = tbuffer.get_end_iter() - response['body'] = tbuffer.get_text(inicio,fin,True) - elif page == NOTE_PAGE: - response['kind'] = 'note' - response['title'] = self.action['note']['title'].get_text() - tbuffer =self.action['note']['body'].get_buffer() - inicio = tbuffer.get_start_iter() - fin = tbuffer.get_end_iter() - response['body'] = tbuffer.get_text(inicio,fin,True) - else: - response = None - return response - -if __name__ == "__main__": - from logindialog import LoginDialog - ''' - from pushbulletapi import PushBullet - configuration = Configuration() - pb = PushBullet() - print(pb.isLogin()) - while(pb.isLogin() == False and internet_on()): - ld = LoginDialog() - ld.run() - oauth_access_token = ld.code - configuration.set('oauth_access_token',oauth_access_token) - configuration.save() - pb = PushBullet() - idevices = pb.getDevices() - icontacts = pb.getContacts() - tdevices = [] - tcontacts = [] - for device in idevices: - if 'nickname' in idevices[device].keys() and len(idevices[device]['nickname'])>0: - label = idevices[device]['nickname'] - tdevices.append({'device_iden':device,'label':label}) - elif 'model' in idevices[device].keys() and len(idevices[device]['model'])>0: - label = idevices[device]['model'] - tdevices.append({'device_iden':device,'label':label}) - sdevices = sorted(tdevices, key=lambda k: k['label']) - for contact in icontacts: - if icontacts[contact]['active'] and 'name' in icontacts[contact].keys() and 'email' in icontacts[contact].keys(): - tcontacts.append({'contact_iden':contact,'name':icontacts[contact]['name'],'email':icontacts[contact]['email']}) - scontacts = sorted(tcontacts, key=lambda k: k['name']) - sdevices = sorted(tdevices, key=lambda k: k['label']) - #cm = ActionDialog(None,sdevices,scontacts) - ''' - cm = SendSMSDialog() - if cm.run() == Gtk.ResponseType.ACCEPT: - cm.hide() - print(cm.get_response()) - cm.destroy() - exit(0) diff -Nru pushbullet-commons-0.4.0/src/pushbullet_service.py pushbullet-commons-0.5.6/src/pushbullet_service.py --- pushbullet-commons-0.4.0/src/pushbullet_service.py 2015-03-24 07:34:21.000000000 +0000 +++ pushbullet-commons-0.5.6/src/pushbullet_service.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,152 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# pushbullet_service.py -# -# This file is part of PushBullet-Indicator -# -# Copyright (C) 2014 -# Lorenzo Carbonell Cerezo -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -from gi.repository import Gtk -import dbus -import dbus.service -import json -from dbus.mainloop.glib import DBusGMainLoop -import os -from pushbulletapi import PushBullet - -print(dbus.__version__) - -class PushBulletDBUSService(dbus.service.Object): - def __init__(self): - bus_name = dbus.service.BusName('es.atareao.pushbullet', bus=dbus.SessionBus()) - dbus.service.Object.__init__(self, bus_name, '/es/atareao/pushbullet') - self.pushBullet = PushBullet() - - @dbus.service.method('es.atareao.pushbullet') - def restart(self): - self.pushBullet = PushBullet() - - - @dbus.service.method('es.atareao.pushbullet') - def get_source_user_iden(self): - return self.pushBullet.get_source_user_iden() - - @dbus.service.method('es.atareao.pushbullet') - def get_source_device_iden(self): - return self.pushBullet.get_source_device_iden() - - - @dbus.service.method('es.atareao.pushbullet') - def getPushHistory(self, modified_after=0, cursor=None): - ans = self.pushBullet.getPushHistory(modified_after, cursor) - return json.dumps(ans) - - @dbus.service.method('es.atareao.pushbullet') - def getLastPush(self): - ans = self.pushBullet.getLastPush() - return json.dumps(ans) - - @dbus.service.method('es.atareao.pushbullet') - def getDevices(self): - return json.dumps(self.pushBullet.getDevices()) - - @dbus.service.method('es.atareao.pushbullet') - def getUser(self): - return json.dumps(self.pushBullet.getUser()) - - @dbus.service.method('es.atareao.pushbullet') - def getContacts(self): - return json.dumps(self.pushBullet.getContacts()) - - @dbus.service.method('es.atareao.pushbullet') - def updateDevices(self): - self.pushBullet.updateDevices() - return self.getDevices() - - @dbus.service.method('es.atareao.pushbullet') - def updateContacts(self): - self.pushBullet.updateContacts() - return self.getContacts() - - @dbus.service.method('es.atareao.pushbullet') - def is_pushing(self): - return self.pushing - - @dbus.service.method('es.atareao.pushbullet') - def send_file(self,identification,filename, body, iscontact): - self.pushing(True,'file') - self.pushBullet.pushFile(identification,filename, body, iscontact) - self.pushing(False,'file') - - @dbus.service.method('es.atareao.pushbullet') - def send_link(self,identification,title,body, link, iscontact): - self.pushing(True,'link') - self.pushBullet.pushLink(identification,title,body,link, iscontact) - self.pushing(False,'link') - - @dbus.service.method('es.atareao.pushbullet') - def send_note(self,identification,title,body, iscontact): - self.pushing(True,'note') - self.pushBullet.pushNote(identification,title,body, iscontact) - self.pushing(False,'note') - - @dbus.service.method('es.atareao.pushbullet') - def send_copy(self, body): - self.pushing(True,'copy') - self.pushBullet.pushCopy(body) - self.pushing(False,'copy') - - @dbus.service.method('es.atareao.pushbullet') - def send_reply(self, package_name, source_user_iden, target_device_iden, conversation_iden, message): - self.pushing(True,'reply') - self.pushBullet.sendReply(package_name, source_user_iden, target_device_iden,conversation_iden,message) - self.pushing(False,'reply') - - @dbus.service.method('es.atareao.pushbullet') - def send_sms(self, device_iden, number, message): - self.pushing(True,'reply') - self.pushBullet.pushSMS(device_iden, number, message) - self.pushing(False,'reply') - - - @dbus.service.method('es.atareao.pushbullet') - def create_device(self, name, model): - return json.dumps(self.pushBullet.createDevice(name, model)) - - @dbus.service.method('es.atareao.pushbullet') - def delete_device(self, device_iden): - return json.dumps(self.pushBullet.deleteDevice(device_iden)) - - @dbus.service.method('es.atareao.pushbullet') - def set_pushing(self, is_pushing,kind,push=None): - self.pushing(is_pushing,kind,push) - - @dbus.service.signal('es.atareao.pushbullet') - def pushing(self, is_pushing,kind,push=None): - pass - @dbus.service.method('es.atareao.pushbullet') - def is_login(self): - return self.pushBullet.isLogin() - -if __name__ == '__main__': - DBusGMainLoop(set_as_default=True) - mPushBulletDBUSService = PushBulletDBUSService() - print(mPushBulletDBUSService.getDevices()) - #print(mPushBulletDBUSService.set_apikey('ddd')) - Gtk.main() diff -Nru pushbullet-commons-0.4.0/src/tokenizator.py pushbullet-commons-0.5.6/src/tokenizator.py --- pushbullet-commons-0.4.0/src/tokenizator.py 1970-01-01 00:00:00.000000000 +0000 +++ pushbullet-commons-0.5.6/src/tokenizator.py 2016-06-26 16:35:29.000000000 +0000 @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# This file is part of PushBullet-Commons +# +# Copyright (C) 2014-2016 +# Lorenzo Carbonell Cerezo +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import codecs +import os +import json +from commons_comun import internet_on, TOKEN_DIR, TOKEN_FILE, TOKEN_PARAMS + + +class Tokenizator(object): + def __init__(self, + config_file_dir=TOKEN_DIR, + config_file=TOKEN_FILE, + default_params=TOKEN_PARAMS): + self.config_file_dir = config_file_dir + self.config_file = config_file + self.default_params = default_params + self.params = default_params + self.read() + + def get(self, key): + try: + return self.params[key] + except KeyError as e: + print(e) + self.params[key] = self.default_params[key] + return self.params[key] + + def set(self, key, value): + self.params[key] = value + + def reset(self): + if os.path.exists(self.config_file): + os.remove(self.config_file) + self.params = self.default_params + self.save() + + def set_defaults(self): + self.params = self.default_params + self.save() + + def read(self): + try: + f = codecs.open(self.config_file, 'r', 'utf-8') + except IOError as e: + print(e) + self.save() + f = codecs.open(self.config_file, 'r', 'utf-8') + try: + self.params = json.loads(f.read()) + except ValueError as e: + print(e) + self.save() + f.close() + + def save(self): + if not os.path.exists(self.config_file_dir): + os.makedirs(self.config_file_dir) + f = codecs.open(self.config_file, 'w', 'utf-8') + f.write(json.dumps(self.params, indent=4, sort_keys=True)) + f.close()