From 3081d9d922ea9ca32cd0e9de52d8fca2078b4c70 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 11 Jan 2019 13:21:58 +0100 Subject: fixed <> positioning bug --- src/gui/edgeitem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/edgeitem.cpp b/src/gui/edgeitem.cpp index 454a276..45ae159 100644 --- a/src/gui/edgeitem.cpp +++ b/src/gui/edgeitem.cpp @@ -167,11 +167,11 @@ void EdgeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge QRectF rect = fm.boundingRect("<>"); if (sc->highlightHeads()) { - QPointF headMark(_edge->head().x(), _edge->head().y() + _edge->cpDist() - 0.25); + QPointF headMark(_edge->target()->point().x(), _edge->target()->point().y() + _edge->cpDist() - 0.25); rect.moveCenter(toScreen(headMark)); painter->drawText(rect, Qt::AlignCenter, "<>"); } else if (sc->highlightTails()) { - QPointF tailMark(_edge->tail().x(), _edge->tail().y() + _edge->cpDist() - 0.25); + QPointF tailMark(_edge->source()->point().x(), _edge->source()->point().y() + _edge->cpDist() - 0.25); rect.moveCenter(toScreen(tailMark)); painter->drawText(rect, Qt::AlignCenter, "<>"); } -- cgit v1.2.3 From 67e197c3ed5adaf7af497b86c36cb8b1ef2738a7 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 12 Jan 2019 11:35:11 +0100 Subject: added brew update to travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 52de1f4..f11e2bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ before_install: install: + - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew update' - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install qt5' - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew link --force qt5' - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install poppler --with-qt' @@ -40,4 +41,4 @@ script: - '[[ "$DEPLOY_TIKZIT" != 1 ]] || curl --upload-file $FILE https://transfer.sh/$FILE' notifications: - email: false \ No newline at end of file + email: false -- cgit v1.2.3 From 123f62d8e237905fb7c9b00725efa3aa84d5f730 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 12 Jan 2019 12:43:19 +0100 Subject: detect poppler version instead of assuming 83 --- deploy-osx.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/deploy-osx.sh b/deploy-osx.sh index 98043c0..ba8d7c1 100755 --- a/deploy-osx.sh +++ b/deploy-osx.sh @@ -6,8 +6,17 @@ macdeployqt tikzit.app # macdeployqt misses this path for some reason, so fix it cd tikzit.app/Contents/Frameworks -install_name_tool -id "@executable_path/../Frameworks/libpoppler.83.dylib" libpoppler.83.dylib -install_name_tool -change /usr/local/Cellar/poppler/0.72.0/lib/libpoppler.83.dylib "@executable_path/../Frameworks/libpoppler.83.dylib" libpoppler-qt5.1.dylib + +POPPLER_QT=`ls libpoppler-qt*` +POPPLER_PATH=`otool -L $POPPLER_QT | sed -e 'm!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\1!p'` +POPPLER_LIB=`otool -L $POPPLER_QT | sed -e 'm!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\2!p'` + +echo "Found $POPPLER_QT and $POPPLER_LIB" +echo "Replacing $POPPLER_PATH with relative path..." + +install_name_tool -id "@executable_path/../Frameworks/$POPPLER_LIB" $POPPLER_LIB +install_name_tool -change $POPPLER_PATH "@executable_path/../Frameworks/$POPPLER_LIB" $POPPLER_QT + cd ../../.. # create DMG -- cgit v1.2.3 From 3be7391da3eefe45b8982ebee4acdc0e3bc8ff02 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 12 Jan 2019 12:46:47 +0100 Subject: ... --- deploy-osx.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy-osx.sh b/deploy-osx.sh index ba8d7c1..0be5aa3 100755 --- a/deploy-osx.sh +++ b/deploy-osx.sh @@ -8,8 +8,8 @@ macdeployqt tikzit.app cd tikzit.app/Contents/Frameworks POPPLER_QT=`ls libpoppler-qt*` -POPPLER_PATH=`otool -L $POPPLER_QT | sed -e 'm!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\1!p'` -POPPLER_LIB=`otool -L $POPPLER_QT | sed -e 'm!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\2!p'` +POPPLER_PATH=`otool -L $POPPLER_QT | sed -e 's!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\1!p'` +POPPLER_LIB=`otool -L $POPPLER_QT | sed -e 's!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\2!p'` echo "Found $POPPLER_QT and $POPPLER_LIB" echo "Replacing $POPPLER_PATH with relative path..." -- cgit v1.2.3 From 8fe8ff000d48460583f542b932d8af3e3d3ae008 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 12 Jan 2019 03:57:39 -0800 Subject: fixed bug in sed commands --- deploy-osx.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/deploy-osx.sh b/deploy-osx.sh index 0be5aa3..dd9efcd 100755 --- a/deploy-osx.sh +++ b/deploy-osx.sh @@ -4,18 +4,23 @@ # copy in libraries and set (most) library paths macdeployqt tikzit.app -# macdeployqt misses this path for some reason, so fix it +# macdeployqt doesn't fix the path to libpoppler for some reason, so we do it by hand cd tikzit.app/Contents/Frameworks POPPLER_QT=`ls libpoppler-qt*` -POPPLER_PATH=`otool -L $POPPLER_QT | sed -e 's!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\1!p'` -POPPLER_LIB=`otool -L $POPPLER_QT | sed -e 's!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\2!p'` +POPPLER_PATH=`otool -L $POPPLER_QT | sed -n 's!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\1!p'` +POPPLER_LIB=`otool -L $POPPLER_QT | sed -n 's!.*\(/usr.*\(libpoppler\..*dylib\)\).*!\2!p'` echo "Found $POPPLER_QT and $POPPLER_LIB" -echo "Replacing $POPPLER_PATH with relative path..." -install_name_tool -id "@executable_path/../Frameworks/$POPPLER_LIB" $POPPLER_LIB -install_name_tool -change $POPPLER_PATH "@executable_path/../Frameworks/$POPPLER_LIB" $POPPLER_QT +if [ "$POPPLER_PATH" != "" ]; then + echo "Replacing $POPPLER_PATH with relative path..." + install_name_tool -id "@executable_path/../Frameworks/$POPPLER_LIB" $POPPLER_LIB + install_name_tool -change $POPPLER_PATH "@executable_path/../Frameworks/$POPPLER_LIB" $POPPLER_QT +else + echo "Poppler already has relative path, so nothing to do." +fi + cd ../../.. -- cgit v1.2.3 From d49cde5d0b948f24aa7b3bd9ad9b3b63333f2281 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 12 Jan 2019 15:01:41 +0100 Subject: reverse edge direction --- src/data/edge.cpp | 12 ++++++++++++ src/data/edge.h | 2 ++ src/gui/mainmenu.cpp | 6 ++++++ src/gui/mainmenu.h | 1 + src/gui/mainmenu.ui | 9 +++++++++ src/gui/tikzscene.cpp | 19 +++++++++++++++++++ src/gui/tikzscene.h | 2 ++ src/gui/undocommands.cpp | 30 ++++++++++++++++++++++++++++++ src/gui/undocommands.h | 11 +++++++++++ src/tikzit.h | 2 +- tikzit.pro | 2 +- 11 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/data/edge.cpp b/src/data/edge.cpp index fcd9959..4803547 100644 --- a/src/data/edge.cpp +++ b/src/data/edge.cpp @@ -365,6 +365,18 @@ void Edge::setWeight(qreal weight) _weight = weight; } +void Edge::reverse() +{ + Node *n = _source; + _source = _target; + _target = n; + int a = _inAngle; + _inAngle = _outAngle; + _outAngle = a; + _bend = -_bend; + updateData(); +} + int Edge::tikzLine() const { return _tikzLine; diff --git a/src/data/edge.h b/src/data/edge.h index 909824b..954145f 100644 --- a/src/data/edge.h +++ b/src/data/edge.h @@ -81,6 +81,8 @@ public: void setOutAngle(int outAngle); void setWeight(qreal weight); + void reverse(); + int tikzLine() const; void setTikzLine(int tikzLine); diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index 6f4f8db..d291390 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -227,6 +227,12 @@ void MainMenu::on_actionExtendRight_triggered() tikzit->activeWindow()->tikzScene()->extendSelectionRight(); } +void MainMenu::on_actionReverse_Edge_Direction_triggered() +{ + if (tikzit->activeWindow() != 0) + tikzit->activeWindow()->tikzScene()->reverseSelectedEdges(); +} + // Tikz void MainMenu::on_actionParse_triggered() diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index 4d672cd..287019c 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -65,6 +65,7 @@ public slots: void on_actionExtendDown_triggered(); void on_actionExtendLeft_triggered(); void on_actionExtendRight_triggered(); + void on_actionReverse_Edge_Direction_triggered(); // Tools void on_actionParse_triggered(); diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 08067aa..ddba6f0 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -72,6 +72,7 @@ + @@ -365,6 +366,14 @@ Preferences... + + + Reverse Edge Direction + + + Ctrl+/ + + diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 4d14f43..9ef4c20 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -212,6 +212,25 @@ void TikzScene::reorderSelection(bool toFront) _tikzDocument->undoStack()->push(cmd); } +void TikzScene::reverseSelectedEdges() +{ + // grab all the edges which are either selected themselves, or where + // both their source and target nodes are selected + QSet es; + foreach (Edge *e, graph()->edges()) { + if ((_edgeItems[e] && _edgeItems[e]->isSelected()) || + (_nodeItems[e->source()] && _nodeItems[e->target()] && + _nodeItems[e->source()]->isSelected() && + _nodeItems[e->target()]->isSelected())) + { + es << e; + } + } + + ReverseEdgesCommand *cmd = new ReverseEdgesCommand(this, es); + _tikzDocument->undoStack()->push(cmd); +} + void TikzScene::refreshZIndices() { qreal z = 0.0; diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index 3e46f6d..e2068eb 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -77,6 +77,8 @@ public: void reorderSelection(bool toFront); + void reverseSelectedEdges(); + void getSelection(QSet &selNodes, QSet &selEdges); QSet getSelectedNodes(); diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index 82b9455..91509ed 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -539,3 +539,33 @@ void ReorderCommand::redo() _scene->refreshZIndices(); GraphUpdateCommand::redo(); } + +ReverseEdgesCommand::ReverseEdgesCommand(TikzScene *scene, + QSet edgeSet, + QUndoCommand *parent) : + GraphUpdateCommand(scene, parent), _edgeSet(edgeSet) +{ +} + +void ReverseEdgesCommand::undo() +{ + EdgeItem *ei; + foreach (Edge *e, _edgeSet) { + e->reverse(); + ei = _scene->edgeItems()[e]; + if (ei) ei->readPos(); + } + GraphUpdateCommand::undo(); +} + +void ReverseEdgesCommand::redo() +{ + EdgeItem *ei; + foreach (Edge *e, _edgeSet) { + e->reverse(); + ei = _scene->edgeItems()[e]; + if (ei) ei->readPos(); + } + GraphUpdateCommand::redo(); +} + diff --git a/src/gui/undocommands.h b/src/gui/undocommands.h index ff51c90..42fed30 100644 --- a/src/gui/undocommands.h +++ b/src/gui/undocommands.h @@ -78,6 +78,17 @@ private: int _newOutAngle; }; +class ReverseEdgesCommand : public GraphUpdateCommand +{ +public: + explicit ReverseEdgesCommand(TikzScene *scene, QSet edgeSet, + QUndoCommand *parent = nullptr); + void undo() override; + void redo() override; +private: + QSet _edgeSet; +}; + class DeleteCommand : public GraphUpdateCommand { public: diff --git a/src/tikzit.h b/src/tikzit.h index 743e3f0..855efeb 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -49,7 +49,7 @@ #ifndef TIKZIT_H #define TIKZIT_H -#define TIKZIT_VERSION "2.1.1" +#define TIKZIT_VERSION "2.1.2" #include "mainwindow.h" #include "mainmenu.h" diff --git a/tikzit.pro b/tikzit.pro index b7b155d..db1773c 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -2,7 +2,7 @@ QT += core gui widgets network -VERSION = 2.1.1 +VERSION = 2.1.2 test { CONFIG += testcase -- cgit v1.2.3 From cfd6ae88b194d69d2a2c365d4a8a78644ba9079b Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 13 Jan 2019 18:13:29 +0100 Subject: added github AUTO deploy scripts --- .travis.yml | 48 +++++++++++++++--------------------------------- scripts/gh-list.py | 11 +++++++++++ scripts/gh-push.py | 30 ++++++++++++++++++++++++++++++ scripts/gh.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 scripts/gh-list.py create mode 100644 scripts/gh-push.py create mode 100644 scripts/gh.py diff --git a/.travis.yml b/.travis.yml index f11e2bf..056b543 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,44 +1,26 @@ language: cpp - branches: only: - - master - + - master matrix: - include: + include: - os: osx compiler: clang env: - - FILE=tikzit-osx.dmg - - QTVER=511 - - DEPLOY_TIKZIT=1 - # - os: osx - # compiler: clang - # env: - # - FILE=tikzit-osx-mountain.dmg - # - QTVER=56 - # - DEPLOY_TIKZIT=1 - -before_install: - # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || curl https://raw.githubusercontent.com/GiovanniBussi/macports-ci/master/macports-ci > macports-ci' - # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || source macports-ci install' - - - + - FILE=tikzit-osx.dmg + - QTVER=511 + - DEPLOY_TIKZIT=1 +before_install: install: - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew update' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install qt5' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew link --force qt5' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install poppler --with-qt' - # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || sudo port -N -k install qt56' - # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || export PATH=/opt/local/libexec/qt5/bin:$PATH' - +- brew update +- brew install qt5 +- brew link --force qt5 +- brew install poppler --with-qt script: - - qmake -v - - qmake -r - - make - - '[[ "$TRAVIS_OS_NAME" != osx ]] || (chmod +x deploy-osx.sh && ./deploy-osx.sh && mv tikzit.dmg $FILE)' - - '[[ "$DEPLOY_TIKZIT" != 1 ]] || curl --upload-file $FILE https://transfer.sh/$FILE' - +- qmake -v +- qmake -r +- make +- '(chmod +x deploy-osx.sh && ./deploy-osx.sh && mv tikzit.dmg $FILE)' +- python scripts/gh-push.py $FILE notifications: email: false diff --git a/scripts/gh-list.py b/scripts/gh-list.py new file mode 100644 index 0000000..1966db4 --- /dev/null +++ b/scripts/gh-list.py @@ -0,0 +1,11 @@ +from gh import gh, pr +import os + +tok = os.getenv('GITHUB_TOKEN') + +draft = [r for r in gh('releases') + if r['draft'] and r['name'] == 'AUTO'][0] + +for a in draft['assets']: + print(a['browser_download_url'] + + '?access_token=' + tok) diff --git a/scripts/gh-push.py b/scripts/gh-push.py new file mode 100644 index 0000000..3aedb15 --- /dev/null +++ b/scripts/gh-push.py @@ -0,0 +1,30 @@ +import sys, re +from gh import gh, get_release + +if len(sys.argv) != 2: + print("Usage: python gh-push.py FILENAME") + sys.exit(1) + +f = sys.argv[1] + +print('Pulling info on release AUTO.') +draft = get_release('AUTO') + +existing = [a for a in draft['assets'] if a['name'] == f] +if (len(existing) > 0): + print('Asset exists, deleting.') + gh('releases/assets/' + str(existing[0]['id']), + ['-X', 'DELETE']) + +print('Uploading new asset...') + +upload_url = re.sub( + '\\{.*\\}', '?name=' + f, + draft['upload_url']) + +resp = gh(upload_url, [ + '-H', 'Content-type: application/octet-stream', + '--data-binary', f + ]) + +print('Done.') diff --git a/scripts/gh.py b/scripts/gh.py new file mode 100644 index 0000000..13a8880 --- /dev/null +++ b/scripts/gh.py @@ -0,0 +1,29 @@ +import sys, os, json +from subprocess import Popen, PIPE + +api_url = 'https://api.github.com/repos/tikzit/tikzit' + +tok = os.getenv('GITHUB_TOKEN', '') + +if tok == '': + print("Must set GITHUB_TOKEN environment variable.") + sys.exit(1) + +# pretty-print JSON responses +def pr(j): print(json.dumps(j, indent=2)) + +# call GitHub API with curl +def gh(s, args=[]): + cmd = (["curl", "-s"] + args + + ["-H", "Authorization: token " + tok] + + [s if 'https://' in s else api_url + '/' + s]) + # ONLY UN-COMMENT FOR TESTING: + # print(' '.join(cmd)) + p = Popen(cmd, stdout=PIPE) + resp = p.stdout.read() + return json.loads(resp if resp else '{}') + +def get_release(n): + rs = [r for r in gh('releases') if r['name'] == n] + if len(rs) > 0: return rs[0] + else: return None -- cgit v1.2.3 From 0efa4c0d62e07c0864ab1d88fbc545f769698044 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 13 Jan 2019 18:22:47 +0100 Subject: updated appveyor for github deploys --- .appveyor.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index f54801e..9f2828f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -31,9 +31,11 @@ build_script: after_build: - sh: ./deploy-linux.sh - sh: mv dist/tikzit.tar.gz tikzit-linux.tar.gz - - sh: appveyor PushArtifact tikzit-linux.tar.gz + #- sh: appveyor PushArtifact tikzit-linux.tar.gz + - sh: python scripts/gh-push.py tikzit-linux.tar.gz - cmd: deploy-win.bat - cmd: move dist\tikzit.zip tikzit-win.zip - - cmd: appveyor PushArtifact tikzit-win.zip + - cmd: python scripts\gh-push.py tikzit-win.zip + #- cmd: appveyor PushArtifact tikzit-win.zip -- cgit v1.2.3 From 515cef87a1b676ad09b1fc2243815ffe3310b221 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 14 Jan 2019 08:16:09 +0100 Subject: fixed curl invokation in github scripts --- scripts/gh-list.py | 5 +++-- scripts/gh-push.py | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/gh-list.py b/scripts/gh-list.py index 1966db4..f8b1c91 100644 --- a/scripts/gh-list.py +++ b/scripts/gh-list.py @@ -1,10 +1,11 @@ +#!/usr/bin/env python + from gh import gh, pr import os tok = os.getenv('GITHUB_TOKEN') -draft = [r for r in gh('releases') - if r['draft'] and r['name'] == 'AUTO'][0] +draft = [r for r in gh('releases') if r['draft']][0] for a in draft['assets']: print(a['browser_download_url'] + diff --git a/scripts/gh-push.py b/scripts/gh-push.py index 3aedb15..dd3b940 100644 --- a/scripts/gh-push.py +++ b/scripts/gh-push.py @@ -1,30 +1,34 @@ -import sys, re -from gh import gh, get_release +#!/usr/bin/env python + +import sys, os, re +from gh import gh if len(sys.argv) != 2: print("Usage: python gh-push.py FILENAME") sys.exit(1) f = sys.argv[1] +fname = os.path.basename(f) -print('Pulling info on release AUTO.') -draft = get_release('AUTO') +print('Pulling info on draft release...') +draft = [r for r in gh('releases') if r['draft']][0] +print('Found: ' + draft['name']) -existing = [a for a in draft['assets'] if a['name'] == f] +existing = [a for a in draft['assets'] if a['name'] == fname] if (len(existing) > 0): - print('Asset exists, deleting.') + print('Asset %s exists, deleting.' % fname) gh('releases/assets/' + str(existing[0]['id']), ['-X', 'DELETE']) -print('Uploading new asset...') +print('Uploading %s...' % f) upload_url = re.sub( - '\\{.*\\}', '?name=' + f, + '\\{.*\\}', '?name=' + fname, draft['upload_url']) resp = gh(upload_url, [ '-H', 'Content-type: application/octet-stream', - '--data-binary', f + '--data-binary', '@' + f ]) print('Done.') -- cgit v1.2.3 From 099d86e68c0db0987bdb954d40a6fed7d65f88f2 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 14 Jan 2019 13:01:01 +0100 Subject: added get script --- scripts/gh-list.py | 3 +-- scripts/gh.py | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/gh-list.py b/scripts/gh-list.py index f8b1c91..a2e7955 100644 --- a/scripts/gh-list.py +++ b/scripts/gh-list.py @@ -8,5 +8,4 @@ tok = os.getenv('GITHUB_TOKEN') draft = [r for r in gh('releases') if r['draft']][0] for a in draft['assets']: - print(a['browser_download_url'] + - '?access_token=' + tok) + print(a['browser_download_url']) diff --git a/scripts/gh.py b/scripts/gh.py index 13a8880..d12b416 100644 --- a/scripts/gh.py +++ b/scripts/gh.py @@ -13,15 +13,18 @@ if tok == '': def pr(j): print(json.dumps(j, indent=2)) # call GitHub API with curl -def gh(s, args=[]): - cmd = (["curl", "-s"] + args + +def gh(s, args=[], quiet=True, parse=True): + cmd = (["curl"] + + (["-s"] if quiet else []) + + args + ["-H", "Authorization: token " + tok] + [s if 'https://' in s else api_url + '/' + s]) # ONLY UN-COMMENT FOR TESTING: # print(' '.join(cmd)) p = Popen(cmd, stdout=PIPE) resp = p.stdout.read() - return json.loads(resp if resp else '{}') + if parse: return json.loads(resp if resp else '{}') + else: return resp def get_release(n): rs = [r for r in gh('releases') if r['name'] == n] -- cgit v1.2.3 From 4b062a6a99a31b34e5a1556680f27369d690dc7b Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 14 Jan 2019 13:05:07 +0100 Subject: ... --- scripts/gh-get.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/gh-get.py diff --git a/scripts/gh-get.py b/scripts/gh-get.py new file mode 100644 index 0000000..9d9693f --- /dev/null +++ b/scripts/gh-get.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +from gh import gh, pr +import sys, os + +filter = None +if len(sys.argv) == 2: + filter = sys.argv[1] + +tok = os.getenv('GITHUB_TOKEN') + +draft = [r for r in gh('releases') if r['draft']][0] + +for a in draft['assets']: + if filter == None or filter in a['name']: + print('Downloading ' + a['name']) + b = gh('releases/assets/%s' % a['id'], + ['-L', '-H', 'Accept: application/octet-stream'], + parse=False, quiet=False) + f = open(a['name'], 'w') + f.write(b) + f.close() -- cgit v1.2.3 From d4b6e9839823e27af646a915436462254758e053 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 14 Jan 2019 13:19:52 +0100 Subject: pushed auth into query string for gh-get --- scripts/gh-get.py | 4 ++-- scripts/gh.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/gh-get.py b/scripts/gh-get.py index 9d9693f..bf95d97 100644 --- a/scripts/gh-get.py +++ b/scripts/gh-get.py @@ -14,9 +14,9 @@ draft = [r for r in gh('releases') if r['draft']][0] for a in draft['assets']: if filter == None or filter in a['name']: print('Downloading ' + a['name']) - b = gh('releases/assets/%s' % a['id'], + b = gh('releases/assets/%s?access_token=%s' % (a['id'], tok), ['-L', '-H', 'Accept: application/octet-stream'], - parse=False, quiet=False) + parse=False, quiet=False, auth=False) f = open(a['name'], 'w') f.write(b) f.close() diff --git a/scripts/gh.py b/scripts/gh.py index d12b416..81db1b2 100644 --- a/scripts/gh.py +++ b/scripts/gh.py @@ -13,11 +13,11 @@ if tok == '': def pr(j): print(json.dumps(j, indent=2)) # call GitHub API with curl -def gh(s, args=[], quiet=True, parse=True): +def gh(s, args=[], quiet=True, parse=True, auth=True): cmd = (["curl"] + (["-s"] if quiet else []) + args + - ["-H", "Authorization: token " + tok] + + (["-H", "Authorization: token " + tok] if auth else []) + [s if 'https://' in s else api_url + '/' + s]) # ONLY UN-COMMENT FOR TESTING: # print(' '.join(cmd)) -- cgit v1.2.3