re-arrange modules, preparing for python-package-index

This commit is contained in:
2014-12-19 00:28:47 +01:00
parent 54ef179788
commit 871600312c
31 changed files with 37 additions and 332 deletions

View File

@@ -10,9 +10,10 @@ pep8:
test: test:
python3 ./tests/test_cli.py python3 ./tests/test_cli.py
.PHONY: doc
doc: doc:
$(MAKE) -C docs html $(MAKE) -C doc html
@echo "xdg-open docs/build/html/index.html" @echo "xdg-open doc/build/html/index.html"
clean: clean:
$(MAKE) -C docs clean $(MAKE) -C docs clean

9
bam.py Executable file
View File

@@ -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:]))

1
bam/__init__.py Normal file
View File

@@ -0,0 +1 @@

View File

@@ -18,7 +18,7 @@
# #
# ***** END GPL LICENCE BLOCK ***** # ***** END GPL LICENCE BLOCK *****
import blendfile_path_walker from bam.blend import blendfile_path_walker
TIMEIT = False TIMEIT = False
@@ -139,7 +139,7 @@ def pack(
import os import os
import shutil import shutil
from bam_utils.system import colorize from bam.utils.system import colorize
# first check args are OK # first check args are OK
# fakeroot _cant_ start with a separator, since we prepend chars to it. # fakeroot _cant_ start with a separator, since we prepend chars to it.
@@ -294,7 +294,7 @@ def pack(
del relbase del relbase
if paths_uuid is not None: 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: for src, dst in path_copy_files:
paths_uuid[os.path.relpath(dst, base_dir_dst).decode('utf-8')] = uuid_from_file(src) paths_uuid[os.path.relpath(dst, base_dir_dst).decode('utf-8')] = uuid_from_file(src)

View File

@@ -26,7 +26,7 @@ This script takes Blend-File and remaps their paths to the original locations.
VERBOSE = 1 VERBOSE = 1
import blendfile_path_walker from bam.blend import blendfile_path_walker
def blendfile_remap( def blendfile_remap(

View File

@@ -120,7 +120,7 @@ def start(
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
# First walk over all blends # 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): for blendfile_src in _iter_files(paths, check_ext=_is_blend):
if not is_quiet: if not is_quiet:
@@ -217,7 +217,7 @@ def finish(
remap_dst_to_src[f_dst] = f_src remap_dst_to_src[f_dst] = f_src
# now the fun begins, remap _all_ paths # 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): for blendfile_dst in _iter_files(paths, check_ext=_is_blend):
blendfile_src = remap_dst_to_src.get(blendfile_dst) blendfile_src = remap_dst_to_src.get(blendfile_dst)

View File

@@ -315,7 +315,7 @@ class FilePath:
# store info to pass along with each iteration # store info to pass along with each iteration
extra_info = rootdir, os.path.basename(filepath) 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") blend = blendfile.open_blend(filepath_tmp, "rb" if readonly else "r+b")
for code in blend.code_index.keys(): for code in blend.code_index.keys():
@@ -528,7 +528,7 @@ class bf_utils:
def iter_array(block, length=-1): def iter_array(block, length=-1):
assert(block.code == b'DATA') assert(block.code == b'DATA')
import blendfile from bam.blend import blendfile
import os import os
handle = block.file.handle handle = block.file.handle
header = block.file.header header = block.file.header

View File

@@ -151,7 +151,7 @@ class bam_config:
descr="bam repository", 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) write_json_to_file(filepath, data)
@staticmethod @staticmethod
@@ -215,7 +215,7 @@ class bam_session:
paths_remove = {} paths_remove = {}
paths_modified = {} 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) session_rootdir = os.path.abspath(session_rootdir)
@@ -506,7 +506,7 @@ class bam_commands:
@staticmethod @staticmethod
def commit(paths, message): 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 import requests
# Load project configuration # Load project configuration
@@ -584,7 +584,7 @@ class bam_commands:
f_rel_in_proj = remap_filepath(f_rel) f_rel_in_proj = remap_filepath(f_rel)
proj_base_b = os.path.dirname(f_rel_in_proj).encode("utf-8") 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( blendfile_pack_restore.blendfile_remap(
f_abs.encode('utf-8'), f_abs.encode('utf-8'),
dir_remap.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(paths, recursive=False, use_json=False):
def deps_path_walker(): def deps_path_walker():
import blendfile_path_walker from bam.blend import blendfile_path_walker
for blendfile_src in paths: for blendfile_src in paths:
blendfile_src = blendfile_src.encode('utf-8') blendfile_src = blendfile_src.encode('utf-8')
yield from blendfile_path_walker.FilePath.visit_from_blend( yield from blendfile_path_walker.FilePath.visit_from_blend(
@@ -828,7 +828,7 @@ class bam_commands:
use_quiet=False, use_quiet=False,
): ):
# Local packing (don't use any project/session stuff) # Local packing (don't use any project/session stuff)
import blendfile_pack from .blend import blendfile_pack
# TODO(cam) multiple paths # TODO(cam) multiple paths
path = paths[0] path = paths[0]
@@ -864,7 +864,7 @@ class bam_commands:
if os.path.exists(filepath_remap): if os.path.exists(filepath_remap):
fatal("Remap in progress, run with 'finish' or remove %r" % 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( remap_data = blendfile_path_remap.start(
paths, paths,
use_json=use_json, use_json=use_json,
@@ -896,7 +896,7 @@ class bam_commands:
import pickle import pickle
remap_data = pickle.load(fh) remap_data = pickle.load(fh)
import blendfile_path_remap from bam.blend import blendfile_path_remap
blendfile_path_remap.finish( blendfile_path_remap.finish(
paths, remap_data, paths, remap_data,
force_relative=force_relative, force_relative=force_relative,
@@ -1242,7 +1242,6 @@ def create_argparse():
def main(argv=None): def main(argv=None):
if argv is None: if argv is None:
argv = sys.argv[1:] argv = sys.argv[1:]

View File

@@ -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)

View File

@@ -1,3 +0,0 @@
{
"BAM_SERVER" : "http://localhost:5000"
}

View File

@@ -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("<Configure>", 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()

View File

@@ -1 +0,0 @@
requests==2.4.3

View File

@@ -37,7 +37,7 @@ if 1:
extensions += ['sphinxarg.ext'] extensions += ['sphinxarg.ext']
sys.path.extend([ sys.path.extend([
# to import 'bam.py' # 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 # to access the 'sphinxarg' extension
os.path.abspath(os.path.join("..", "exts")) os.path.abspath(os.path.join("..", "exts"))
]) ])

View File

@@ -4,6 +4,6 @@ Client Reference
Here is a reference of all the BAM cli commands. Here is a reference of all the BAM cli commands.
.. argparse:: .. argparse::
:module: bam :module: bam.cli
:func: create_argparse :func: create_argparse
:prog: bam :prog: bam

View File

@@ -26,7 +26,7 @@ if VERBOSE:
# Ensure module path # Ensure module path
import os import os
import sys 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: if path not in sys.path:
sys.path.append(path) sys.path.append(path)
del os, sys, path del os, sys, path
@@ -234,7 +234,7 @@ def svn_repo_checkout(repo, path):
def bam_run(argv, cwd=None): def bam_run(argv, cwd=None):
with CHDir(cwd): with CHDir(cwd):
import bam import bam.cli
if VERBOSE: if VERBOSE:
sys.stdout.write("\n running: ") sys.stdout.write("\n running: ")
@@ -246,7 +246,7 @@ def bam_run(argv, cwd=None):
# input('press_key!:') # input('press_key!:')
with StdIO() as fakeio: with StdIO() as fakeio:
bam.main(argv) bam.cli.main(argv)
ret = fakeio.read() ret = fakeio.read()
if VERBOSE: if VERBOSE:

View File

@@ -27,7 +27,7 @@ Environment vars:
# Ensure module path # Ensure module path
import os import os
import sys 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: if path not in sys.path:
sys.path.append(path) sys.path.append(path)
del os, sys, path del os, sys, path

View File

@@ -295,7 +295,7 @@ class FileAPI(Resource):
we want all paths to be relative to this so we don't get server path included. we want all paths to be relative to this so we don't get server path included.
""" """
import os import os
import blendfile_pack from bam.blend import blendfile_pack
assert(os.path.exists(filepath) and not os.path.isdir(filepath)) assert(os.path.exists(filepath) and not os.path.isdir(filepath))
log.info(" Source path: %r" % filepath) log.info(" Source path: %r" % filepath)
@@ -324,7 +324,7 @@ class FileAPI(Resource):
return return
else: else:
# non blend-file # 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) paths_uuid[os.path.basename(filepath)] = uuid_from_file(filepath)
del uuid_from_file del uuid_from_file