From patchwork Thu Apr 9 13:31:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Domingo Cansino X-Patchwork-Id: 459737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1003E140082 for ; Thu, 9 Apr 2015 23:32:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=alQHyqsK; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 542A728BE59; Thu, 9 Apr 2015 15:31:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 337BF28BE1E for ; Thu, 9 Apr 2015 15:31:06 +0200 (CEST) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 9 Apr 2015 15:31:05 +0200 (CEST) Received: by wizk4 with SMTP id k4so92465936wiz.1 for ; Thu, 09 Apr 2015 06:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=BbLeQc85IhZJ8V8WLbszEeSjzQiYAHJdBJfLB00iR2o=; b=alQHyqsK5YshiAuN/GPe4yUHhyUQwUqVqs5ryRvUFxWW9C9Ufk/0IzrZw49oN5ckX4 PluYfAHANOK/ThQu5iJqLJYL/4kxV4fHqhFlSvGpdG7A+K1WFO2gtNiG/t+Dc1AOZiZ8 hzEKglN48s0xnntUK7TCi/IATuB2GzEIhgoxDzAf2ryWfm+QqBzuSbm7EKs1tSpoO3uf KKnvDbTIlZ6Wyd4xp75b3rowMLaLZ23EkQctZomWv51zybnC6tsIe2GqULtUER6SoJbo Kd5PGo36T/cUWpMOBDiLSx446u+ooy/GIWr3fp/ydlCa1EFBE/x5QdfMlYlxPs1Q5b9M NCMw== X-Received: by 10.194.60.4 with SMTP id d4mr61040232wjr.72.1428586312793; Thu, 09 Apr 2015 06:31:52 -0700 (PDT) Received: from rosita.endor.txomon.com ([195.16.128.138]) by mx.google.com with ESMTPSA id mv11sm16507731wic.23.2015.04.09.06.31.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Apr 2015 06:31:52 -0700 (PDT) From: Javier Domingo Cansino X-Google-Original-From: Javier Domingo Cansino To: openwrt-devel@lists.openwrt.org Date: Thu, 9 Apr 2015 15:31:48 +0200 Message-Id: <1428586308-12431-1-git-send-email-javier.domingo@fon.com> X-Mailer: git-send-email 2.3.2 Subject: [OpenWrt-Devel] [PATCH] Simple http server to expose opkg packages and images from bin/ X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" I have created a python script to make easily available packages under bin/xxxx easier. I got sick of installing a web server, or move the packages, or configure it. So I just thought that a python based solution based on the scripts/ folder would be the best solution. Hope you like it! --- scripts/package-server.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 scripts/package-server.py diff --git a/scripts/package-server.py b/scripts/package-server.py new file mode 100755 index 0000000..3954781 --- /dev/null +++ b/scripts/package-server.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +from __future__ import print_function +import operator +import os +import sys + +try: + from SimpleHTTPServer import SimpleHTTPRequestHandler as Handler +except ImportError: + from http.server import SimpleHTTPRequestHandler as Handler +try: + from SocketServer import TCPServer +except ImportError: + from socketserver import TCPServer + +PORT = 80 + + +def find_last_modification_date(path): + time = 0 + for root, dirs, files in os.walk(path): + for path in files: + _, _, _, _, _, _, _, _, last_m, _ = os.stat( + os.path.join(root, path)) + time = time if time > last_m else last_m + return time + + +(dirpath, dirnames, _) = next(os.walk(os.path.join(os.path.dirname(__file__), + '../bin'))) + +m_times = {} + +for dir in dirnames: + path = os.path.join(dirpath, dir) + m_times[path] = find_last_modification_date(path) +dir, m_path = sorted(m_times.items(), key=operator.itemgetter(1), + reverse=True)[0] +dir = os.path.relpath(dir) +print('Selecting', dir, 'as working dir for', m_path, 'modification date.') +os.chdir(dir) + +try: + httpd = TCPServer(("", PORT), Handler) +except PermissionError: + + sys.stderr.write('Permission denied for listening in port %d\n' % PORT) + sys.exit(1) +print("HTTP server started at port", PORT) +httpd.serve_forever()