diff --git a/Makefile b/Makefile index 26ddbc4..031ddfc 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,10 @@ pep8: test: python3 ./tests/test_cli.py +.PHONY: doc doc: - $(MAKE) -C docs html - @echo "xdg-open docs/build/html/index.html" + $(MAKE) -C doc html + @echo "xdg-open doc/build/html/index.html" clean: $(MAKE) -C docs clean diff --git a/readme.rst b/README.rst similarity index 100% rename from readme.rst rename to README.rst diff --git a/bam.py b/bam.py new file mode 100755 index 0000000..f1aafaa --- /dev/null +++ b/bam.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys + +if __name__ == '__main__': + from bam.cli import main + sys.exit(main(sys.argv[1:])) + diff --git a/bam/__init__.py b/bam/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/bam/__init__.py @@ -0,0 +1 @@ + diff --git a/modules/blendfile.py b/bam/blend/blendfile.py similarity index 100% rename from modules/blendfile.py rename to bam/blend/blendfile.py diff --git a/modules/blendfile_pack.py b/bam/blend/blendfile_pack.py similarity index 99% rename from modules/blendfile_pack.py rename to bam/blend/blendfile_pack.py index 5fda392..15ceb24 100755 --- a/modules/blendfile_pack.py +++ b/bam/blend/blendfile_pack.py @@ -18,7 +18,7 @@ # # ***** END GPL LICENCE BLOCK ***** -import blendfile_path_walker +from bam.blend import blendfile_path_walker TIMEIT = False @@ -139,7 +139,7 @@ def pack( import os import shutil - from bam_utils.system import colorize + from bam.utils.system import colorize # first check args are OK # fakeroot _cant_ start with a separator, since we prepend chars to it. @@ -294,7 +294,7 @@ def pack( del relbase if paths_uuid is not None: - from bam_utils.system import uuid_from_file + from bam.utils.system import uuid_from_file for src, dst in path_copy_files: paths_uuid[os.path.relpath(dst, base_dir_dst).decode('utf-8')] = uuid_from_file(src) diff --git a/modules/blendfile_pack_restore.py b/bam/blend/blendfile_pack_restore.py similarity index 99% rename from modules/blendfile_pack_restore.py rename to bam/blend/blendfile_pack_restore.py index c309fe7..653d362 100755 --- a/modules/blendfile_pack_restore.py +++ b/bam/blend/blendfile_pack_restore.py @@ -26,7 +26,7 @@ This script takes Blend-File and remaps their paths to the original locations. VERBOSE = 1 -import blendfile_path_walker +from bam.blend import blendfile_path_walker def blendfile_remap( diff --git a/modules/blendfile_path_remap.py b/bam/blend/blendfile_path_remap.py similarity index 98% rename from modules/blendfile_path_remap.py rename to bam/blend/blendfile_path_remap.py index 9b28e48..d424391 100644 --- a/modules/blendfile_path_remap.py +++ b/bam/blend/blendfile_path_remap.py @@ -120,7 +120,7 @@ def start( # ------------------------------------------------------------------------ # First walk over all blends - import blendfile_path_walker + from bam.blend import blendfile_path_walker for blendfile_src in _iter_files(paths, check_ext=_is_blend): if not is_quiet: @@ -217,7 +217,7 @@ def finish( remap_dst_to_src[f_dst] = f_src # now the fun begins, remap _all_ paths - import blendfile_path_walker + from bam.blend import blendfile_path_walker for blendfile_dst in _iter_files(paths, check_ext=_is_blend): blendfile_src = remap_dst_to_src.get(blendfile_dst) diff --git a/modules/blendfile_path_walker.py b/bam/blend/blendfile_path_walker.py similarity index 99% rename from modules/blendfile_path_walker.py rename to bam/blend/blendfile_path_walker.py index 269c4ad..c8a71dd 100644 --- a/modules/blendfile_path_walker.py +++ b/bam/blend/blendfile_path_walker.py @@ -315,7 +315,7 @@ class FilePath: # store info to pass along with each iteration extra_info = rootdir, os.path.basename(filepath) - import blendfile + from bam.blend import blendfile blend = blendfile.open_blend(filepath_tmp, "rb" if readonly else "r+b") for code in blend.code_index.keys(): @@ -528,7 +528,7 @@ class bf_utils: def iter_array(block, length=-1): assert(block.code == b'DATA') - import blendfile + from bam.blend import blendfile import os handle = block.file.handle header = block.file.header diff --git a/client/cli/bam.py b/bam/cli.py similarity index 98% rename from client/cli/bam.py rename to bam/cli.py index 861944e..5c85a99 100755 --- a/client/cli/bam.py +++ b/bam/cli.py @@ -151,7 +151,7 @@ class bam_config: descr="bam repository", ) - from bam_utils.system import write_json_to_file + from bam.utils.system import write_json_to_file write_json_to_file(filepath, data) @staticmethod @@ -215,7 +215,7 @@ class bam_session: paths_remove = {} paths_modified = {} - from bam_utils.system import uuid_from_file + from bam.utils.system import uuid_from_file session_rootdir = os.path.abspath(session_rootdir) @@ -506,7 +506,7 @@ class bam_commands: @staticmethod def commit(paths, message): - from bam_utils.system import write_json_to_file, write_json_to_zip + from bam.utils.system import write_json_to_file, write_json_to_zip import requests # Load project configuration @@ -584,7 +584,7 @@ class bam_commands: f_rel_in_proj = remap_filepath(f_rel) proj_base_b = os.path.dirname(f_rel_in_proj).encode("utf-8") - import blendfile_pack_restore + from bam.blend import blendfile_pack_restore blendfile_pack_restore.blendfile_remap( f_abs.encode('utf-8'), dir_remap.encode('utf-8'), @@ -780,7 +780,7 @@ class bam_commands: def deps(paths, recursive=False, use_json=False): def deps_path_walker(): - import blendfile_path_walker + from bam.blend import blendfile_path_walker for blendfile_src in paths: blendfile_src = blendfile_src.encode('utf-8') yield from blendfile_path_walker.FilePath.visit_from_blend( @@ -828,7 +828,7 @@ class bam_commands: use_quiet=False, ): # Local packing (don't use any project/session stuff) - import blendfile_pack + from .blend import blendfile_pack # TODO(cam) multiple paths path = paths[0] @@ -864,7 +864,7 @@ class bam_commands: if os.path.exists(filepath_remap): fatal("Remap in progress, run with 'finish' or remove %r" % filepath_remap) - import blendfile_path_remap + from bam.blend import blendfile_path_remap remap_data = blendfile_path_remap.start( paths, use_json=use_json, @@ -896,7 +896,7 @@ class bam_commands: import pickle remap_data = pickle.load(fh) - import blendfile_path_remap + from bam.blend import blendfile_path_remap blendfile_path_remap.finish( paths, remap_data, force_relative=force_relative, @@ -1242,7 +1242,6 @@ def create_argparse(): def main(argv=None): - if argv is None: argv = sys.argv[1:] diff --git a/modules/bam_utils/system.py b/bam/utils/system.py similarity index 100% rename from modules/bam_utils/system.py rename to bam/utils/system.py diff --git a/client/client/__init__.py b/client/client/__init__.py deleted file mode 100755 index bb68925..0000000 --- a/client/client/__init__.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python3 - -import requests -import json - -import os -MODULE_DIR = os.path.dirname(__file__) - -with open(os.path.join(MODULE_DIR, 'config.json'), 'r') as config: - config = json.load(config) - - -def request_url(path): - return ('%s%s' % (config['BAM_SERVER'], path)) - - -# payload = {'path': ''} -# r = requests.get(request_url('/files'), params=payload, auth=('bam', 'bam')) -# print (r.json()) - -# payload = { -# 'filepath': 'shots', -# 'command' : 'info', -# } - -# r = requests.get(request_url('/file'), params=payload, auth=('bam', 'bam'), stream=True) -# local_filename = payload['filepath'].split('/')[-1] - -# print (r.json()) -# with open(local_filename, 'wb') as f: -# for chunk in r.iter_content(chunk_size=1024): -# if chunk: # filter out keep-alive new chunks -# f.write(chunk) -# f.flush() -# print(local_filename) - -# filepath = 'yourfilename.txt' -# with open(filepath) as fh: -# mydata = fh.read() -# response = requests.put('https://api.elasticemail.com/attachments/upload', -# data=mydata, -# auth=('omer', 'b01ad0ce'), -# headers={'content-type':'text/plain'}, -# params={'file': filepath} -# ) - -args = { - 'message': "Adding test file." -} - -payload = { - 'command': 'commit', - 'arguments': json.dumps(args) -} - -files = {'file': open('buck.mp4', 'rb')} -# files = {'name': ('filename', (open('mytest.txt', 'rb')))} - -r = requests.put(request_url('/file'), - params=payload, - auth=('bam', 'bam'), - files=files) - -print(r.text) diff --git a/client/client/config.json.example.json b/client/client/config.json.example.json deleted file mode 100644 index a12e2d4..0000000 --- a/client/client/config.json.example.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "BAM_SERVER" : "http://localhost:5000" -} diff --git a/client/gui/browser.py b/client/gui/browser.py deleted file mode 100755 index 3972682..0000000 --- a/client/gui/browser.py +++ /dev/null @@ -1,237 +0,0 @@ -#!/usr/bin/env python3 -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# 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 2 -# 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, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENSE BLOCK ##### - -import tkinter as tk - - -class PathHandle: - """ - Manage storing path, cache json. - """ - __slots__ = ( - "filepath", - "json", - "path", - ) - - def __init__(self): - self.json = None - # list of strings - self.path = [] - - # self.filepath_set("gui.json") - self.refresh() - - def refresh(self): - # import json - # self.json = json.load(fp) - self.json = self.json_from_server(self.path) - print(self.json) - - # def filepath_set(self, filepath): - # self.filepath = filepath - - def append_path(self, path_item): - if path_item == "..": - # maybe we should raise error - if self.path: - self.path.pop() - else: - self.path.append(path_item) - self.refresh() - - @staticmethod - def request_url(req_path): - # TODO, get from config - BAM_SERVER = "http://localhost:5000" - result = "%s/%s" % (BAM_SERVER, req_path) - print(result) - return result - - @staticmethod - def json_from_server(path): - - import requests - payload = {"path": "/".join(path)} - r = requests.get(PathHandle.request_url("file_list"), params=payload, auth=("bam", "bam")) - print(r.text) - return r.json() - - @staticmethod - def download_from_server(path, idname, file_type, local_filename=None): - import requests - payload = { - "filepath": "/".join(path) + "/" + idname, - "command": "checkout", - } - r = requests.get(PathHandle.request_url(file_type), params=payload, auth=("bam", "bam"), stream=True) - local_filename = payload['filepath'].split('/')[-1] - - if file_type == "file": - local_filename += ".zip" - - with open(local_filename, 'wb') as f: - for chunk in r.iter_content(chunk_size=1024): - if chunk: # filter out keep-alive new chunks - f.write(chunk) - f.flush() - print(local_filename) - - -class Application(tk.Frame): - def __init__(self, root): - - # ---- - # Menu - menubar = tk.Menu(root) - menubar.add_command(label="Project", command=lambda: print("Switch-Project")) - menubar.add_command(label="Preferences", command=lambda: print("Preferences")) - root.config(menu=menubar) - - # local data - self.item_list = [] - - tk.Frame.__init__(self, root) - - self.canvas = tk.Canvas(root, borderwidth=0, background="#d9d9d9") - self.frame = tk.Frame(self.canvas, background="#d9d9d9") - self.vsb = tk.Scrollbar(root, orient="vertical", command=self.canvas.yview) - self.canvas.configure(yscrollcommand=self.vsb.set) - - self.vsb.pack(side="right", fill="y") - self.canvas.pack(side="left", fill="both", expand=True) - self.canvas.create_window((4, 4), window=self.frame, anchor="nw", - tags="self.frame") - - self.frame.bind("", self.OnFrameConfigure) - - self.path_handle = PathHandle() - - self.grid_members = [] - - self.populate() - - def repopulate(self): - for b in self.grid_members: - b.destroy() - self.grid_members.clear() - self.populate() - - def populate(self): - '''Put in some fake data''' - pass - """ - for row in range(100): - tk.Label(self.frame, text="%s" % row, width=3, borderwidth="1", - relief="solid").grid(row=row, column=0) - t="this is the second colum for row %s" %row - tk.Label(self.frame, text=t).grid(row=row, column=1) - """ - - def calc_label_text(): - return "Path: " + "/".join(self.path_handle.path) - - def exec_path_dir(idname, but_path): - self.path_handle.append_path(idname) - print(self.path_handle.path) - - but_path.config(text=calc_label_text()) - - self.repopulate() - - def exec_path_file(idname): - self.path_handle.download_from_server(self.path_handle.path, idname, "file") - self.repopulate() - - def exec_path_blendfile(idname): - self.path_handle.download_from_server(self.path_handle.path, idname, "file") - self.repopulate() - - js = self.path_handle.json - items = js.get("items_list") - items.sort() - if items is None: - tk.Label(self, text="Empty") - - but_path = tk.Label(self.frame, text=calc_label_text()) - but_path.grid(row=0, column=1, sticky="nw") - self.grid_members.append(but_path) - - row = 1 - - # import random - # random.shuffle(items) - - for name_short, name_full, item_type in [("..", "", "dir")] + items: - print(name_short, name_full, item_type) - if item_type == "dir": - but = tk.Label(self.frame, text="(/)", width=3, borderwidth="1", relief="solid") - but.grid(row=row, column=0) - self.grid_members.append(but) - - def fn(idname=name_short, but_path=but_path): - exec_path_dir(idname, but_path) - - but = tk.Button(self.frame, text=name_short + "/", fg="green", command=fn) - but.grid(row=row, column=1, sticky="nw") - del fn - - self.grid_members.append(but) - row += 1 -# -# for name_short, name_full, item_type in items: -# print(name_short, name_full, item_type) -# if item_type == "file": -# but = tk.Label(self.frame, text="(f)", width=3, borderwidth="1", relief="solid") -# but.grid(row=row, column=0) -# def fn(idname=name_short): exec_path_file(idname) -# self.grid_members.append(but) -# -# but = tk.Button(self.frame, text=name_short, fg="blue", command=fn) -# but.grid(row=row, column=1, sticky="nw") -# del fn -# -# self.grid_members.append(but) -# row += 1 - - for name_short, name_full, item_type in items: - print(name_short, name_full, item_type) - if item_type == "file": - but = tk.Label(self.frame, text="(b)", width=3, borderwidth="1", relief="solid") - but.grid(row=row, column=0) - - def fn(idname=name_short): - exec_path_blendfile(idname) - self.grid_members.append(but) - - but = tk.Button(self.frame, text=name_short, fg="blue", command=fn) - but.grid(row=row, column=1, sticky="nw") - del fn - - self.grid_members.append(but) - row += 1 - - def OnFrameConfigure(self, event): - '''Reset the scroll region to encompass the inner frame''' - self.canvas.configure(scrollregion=self.canvas.bbox("all")) - -root = tk.Tk() -app = Application(root).pack(side="top", fill="both", expand=True) -root.title("BAM") -root.mainloop() diff --git a/client/requirements.txt b/client/requirements.txt deleted file mode 100644 index 2f2d5f4..0000000 --- a/client/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -requests==2.4.3 diff --git a/docs/Makefile b/doc/Makefile similarity index 100% rename from docs/Makefile rename to doc/Makefile diff --git a/docs/exts/sphinxarg/__init__.py b/doc/exts/sphinxarg/__init__.py similarity index 100% rename from docs/exts/sphinxarg/__init__.py rename to doc/exts/sphinxarg/__init__.py diff --git a/docs/exts/sphinxarg/ext.py b/doc/exts/sphinxarg/ext.py similarity index 100% rename from docs/exts/sphinxarg/ext.py rename to doc/exts/sphinxarg/ext.py diff --git a/docs/exts/sphinxarg/parser.py b/doc/exts/sphinxarg/parser.py similarity index 100% rename from docs/exts/sphinxarg/parser.py rename to doc/exts/sphinxarg/parser.py diff --git a/docs/make.bat b/doc/make.bat similarity index 100% rename from docs/make.bat rename to doc/make.bat diff --git a/docs/source/conf.py b/doc/source/conf.py similarity index 99% rename from docs/source/conf.py rename to doc/source/conf.py index a95e4ba..3437cc4 100644 --- a/docs/source/conf.py +++ b/doc/source/conf.py @@ -37,7 +37,7 @@ if 1: extensions += ['sphinxarg.ext'] sys.path.extend([ # to import 'bam.py' - os.path.join(os.path.dirname(__file__), "..", "..", "client", "cli"), + os.path.join(os.path.dirname(__file__), "..", ".."), # to access the 'sphinxarg' extension os.path.abspath(os.path.join("..", "exts")) ]) diff --git a/docs/source/design/milestones.rst b/doc/source/design/milestones.rst similarity index 100% rename from docs/source/design/milestones.rst rename to doc/source/design/milestones.rst diff --git a/docs/source/design/planning.rst b/doc/source/design/planning.rst similarity index 100% rename from docs/source/design/planning.rst rename to doc/source/design/planning.rst diff --git a/docs/source/index.rst b/doc/source/index.rst similarity index 100% rename from docs/source/index.rst rename to doc/source/index.rst diff --git a/docs/source/install/index.rst b/doc/source/install/index.rst similarity index 100% rename from docs/source/install/index.rst rename to doc/source/install/index.rst diff --git a/docs/source/manual/index.rst b/doc/source/manual/index.rst similarity index 100% rename from docs/source/manual/index.rst rename to doc/source/manual/index.rst diff --git a/docs/source/reference/index.rst b/doc/source/reference/index.rst similarity index 87% rename from docs/source/reference/index.rst rename to doc/source/reference/index.rst index 3baf54a..a4cd7ef 100644 --- a/docs/source/reference/index.rst +++ b/doc/source/reference/index.rst @@ -4,6 +4,6 @@ Client Reference Here is a reference of all the BAM cli commands. .. argparse:: - :module: bam + :module: bam.cli :func: create_argparse :prog: bam diff --git a/modules/bam_utils/__init__.py b/modules/bam_utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_cli.py b/tests/test_cli.py index 3bbc458..9c9f4e3 100755 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -26,7 +26,7 @@ if VERBOSE: # Ensure module path import os import sys -path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "client", "cli")) +path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) if path not in sys.path: sys.path.append(path) del os, sys, path @@ -234,7 +234,7 @@ def svn_repo_checkout(repo, path): def bam_run(argv, cwd=None): with CHDir(cwd): - import bam + import bam.cli if VERBOSE: sys.stdout.write("\n running: ") @@ -246,7 +246,7 @@ def bam_run(argv, cwd=None): # input('press_key!:') with StdIO() as fakeio: - bam.main(argv) + bam.cli.main(argv) ret = fakeio.read() if VERBOSE: diff --git a/webservice/bam/application/__init__.py b/webservice/bam/application/__init__.py index 19021f0..6718b65 100644 --- a/webservice/bam/application/__init__.py +++ b/webservice/bam/application/__init__.py @@ -27,7 +27,7 @@ Environment vars: # Ensure module path import os import sys -path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..", "modules")) +path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..")) if path not in sys.path: sys.path.append(path) del os, sys, path diff --git a/webservice/bam/application/modules/resources/__init__.py b/webservice/bam/application/modules/resources/__init__.py index e43a853..ec41fb1 100644 --- a/webservice/bam/application/modules/resources/__init__.py +++ b/webservice/bam/application/modules/resources/__init__.py @@ -295,7 +295,7 @@ class FileAPI(Resource): we want all paths to be relative to this so we don't get server path included. """ import os - import blendfile_pack + from bam.blend import blendfile_pack assert(os.path.exists(filepath) and not os.path.isdir(filepath)) log.info(" Source path: %r" % filepath) @@ -324,7 +324,7 @@ class FileAPI(Resource): return else: # non blend-file - from bam_utils.system import uuid_from_file + from bam.utils.system import uuid_from_file paths_uuid[os.path.basename(filepath)] = uuid_from_file(filepath) del uuid_from_file