Browse files

Adding functionality to delete assets

  • Loading branch information...
1 parent b52405e commit 3db0a2f737f12f2ae8f4a0ac83a7486a07fa97d5 @drdogbiscuit committed Mar 24, 2012
View
61 src/tools/ueDestroyAsset.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import sys, os, getopt
+
+import ueClient, ueSpec
+
+import ueCore.Destroy as ueDestroy
+
+global asset
+asset = ""
+
+def destroyAsset():
+ if asset == "":
+ print "ERROR: Spec not set"
+ sys.exit(2)
+
+ spec = ueSpec.Spec(asset)
+
+ ueDestroy.destroyAsset(spec)
+
+def parse():
+ global asset
+
+ sArgs = "hs:"
+ lArgs = ["help", "spec="]
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], sArgs, lArgs)
+ except getopt.GetoptError, e:
+ print "ERROR: Parsing argument (%s)" % e
+ sys.exit(2)
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ usage()
+ sys.exit(0)
+ elif o in ("-s", "--spec"):
+ asset = a
+ else:
+ print "ERROR: Unrecognised argument '%s'" % o
+ sys.exit(2)
+
+def usage():
+ print "Usage: %s -n [NAME] -s [SPEC] ..." % os.path.basename(sys.argv[0])
+ print "Deletes a ue asset."
+ print ""
+ print "\t-s, --spec Asset spec"
+ print "\t-h, --help Print this help"
+
+
+if __name__ == "__main__":
+ if len(sys.argv) == 1:
+ usage()
+ sys.exit(0)
+
+ parse()
+ ueClient.Client()
+ destroyAsset()
+
+ sys.exit(0)
+
View
61 src/tools/ueDestroyElement.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import sys, os, getopt
+
+import ueClient, ueSpec
+
+import ueCore.Destroy as ueDestroy
+
+global element
+element = ""
+
+def destroyElement():
+ if element == "":
+ print "ERROR: Spec not set"
+ sys.exit(2)
+
+ spec = ueSpec.Spec(element)
+
+ ueDestroy.destroyElement(spec)
+
+def parse():
+ global element
+
+ sArgs = "hs:"
+ lArgs = ["help", "spec="]
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], sArgs, lArgs)
+ except getopt.GetoptError, e:
+ print "ERROR: Parsing argument (%s)" % e
+ sys.exit(2)
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ usage()
+ sys.exit(0)
+ elif o in ("-s", "--spec"):
+ element = a
+ else:
+ print "ERROR: Unrecognised argument '%s'" % o
+ sys.exit(2)
+
+def usage():
+ print "Usage: %s -n [NAME] -s [SPEC] ..." % os.path.basename(sys.argv[0])
+ print "Deletes a ue element."
+ print ""
+ print "\t-s, --spec Element spec"
+ print "\t-h, --help Print this help"
+
+
+if __name__ == "__main__":
+ if len(sys.argv) == 1:
+ usage()
+ sys.exit(0)
+
+ parse()
+ ueClient.Client()
+ destroyElement()
+
+ sys.exit(0)
+
View
63 src/tools/ueDestroyGroup.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+import sys, os, getopt
+
+import ueClient, ueSpec
+
+import ueCore.Destroy as ueDestroy
+
+global group
+group = ""
+
+def destroyGroup():
+ if group == "":
+ print "ERROR: Spec not set"
+ sys.exit(2)
+
+ spec = ueSpec.Spec(group)
+
+ ueDestroy.destroyGroup(spec)
+
+def parse():
+ global group
+
+ sArgs = "hs:"
+ lArgs = ["help", "spec="]
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], sArgs, lArgs)
+ except getopt.GetoptError, e:
+ print "ERROR: Parsing argument (%s)" % e
+ sys.exit(2)
+
+ group["spec"] = os.getenv("PROJ")
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ usage()
+ sys.exit(0)
+ elif o in ("-s", "--spec"):
+ group = a
+ else:
+ print "ERROR: Unrecognised argument '%s'" % o
+ sys.exit(2)
+
+def usage():
+ print "Usage: %s -n [NAME] -s [SPEC] ..." % os.path.basename(sys.argv[0])
+ print "Deletes a ue group."
+ print ""
+ print "\t-s, --spec Group spec"
+ print "\t-h, --help Print this help"
+
+
+if __name__ == "__main__":
+ if len(sys.argv) == 1:
+ usage()
+ sys.exit(0)
+
+ parse()
+ ueClient.Client()
+ destroyGroup()
+
+ sys.exit(0)
+
View
61 src/tools/ueDestroyProject.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import sys, os, getopt
+
+import ueClient, ueSpec
+
+import ueCore.Destroy as ueDestroy
+
+global project
+project = ""
+
+def deleteProject():
+ if project == "":
+ print "ERROR: Spec not set"
+ sys.exit(2)
+
+ spec = ueSpec.Spec(project)
+
+ ueDestroy.destroyProject(spec)
+
+def parse():
+ global project
+
+ sArgs = "hs:"
+ lArgs = ["help", "spec="]
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], sArgs, lArgs)
+ except getopt.GetoptError, e:
+ print "ERROR: Parsing argument (%s)" % e
+ sys.exit(2)
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ usage()
+ sys.exit(0)
+ elif o in ("-s", "--spec"):
+ project = a
+ else:
+ print "ERROR: Unrecognised argument '%s'" % o
+ sys.exit(2)
+
+def usage():
+ print "Usage: %s -n [NAME] ..." % os.path.basename(sys.argv[0])
+ print "Deletes a ue project."
+ print ""
+ print "\t-n, --spec Project spec"
+ print "\t-h, --help Print this help"
+
+
+if __name__ == "__main__":
+ if len(sys.argv) == 1:
+ usage()
+ sys.exit(0)
+
+ parse()
+ ueClient.Client()
+ deleteProject()
+
+ sys.exit(0)
+
View
45 src/ueClient/__init__.py
@@ -40,6 +40,9 @@ def __init__(self):
client = self
def get(self, get, *args):
+ if get == "assets":
+ get = "ueassets"
+
urlargs = self.parseUrlargs(args)
url = "/%s%s.json" % (get, urlargs)
@@ -63,6 +66,9 @@ def get(self, get, *args):
return jsonDict
def post(self, get, *args, **kwargs):
+ if get == "assets":
+ get = "ueassets"
+
urlargs = self.parseUrlargs(args)
url = "/%s%s.json" % (get, urlargs)
@@ -76,6 +82,9 @@ def post(self, get, *args, **kwargs):
sys.exit(2)
def put(self, get, spec, **kwargs):
+ if get == "assets":
+ get = "ueassets"
+
if not spec.proj == None:
kwargs["data"]["project"] = spec.proj
if not spec.grp == None:
@@ -101,6 +110,22 @@ def put(self, get, spec, **kwargs):
print "FATAL ERROR: %s" % e
sys.exit(2)
+ def destroy(self, get, *args):
+ if get == "assets":
+ get = "ueassets"
+
+ urlargs = self.parseUrlargs(args)
+
+ url = "/%s%s.json" % (get, urlargs)
+
+ try:
+ con = httplib.HTTPConnection(self.host)
+ con.request("DELETE", url)
+ request = con.getresponse()
+ except IOError, e:
+ print "FATAL ERROR: %s" % e
+ sys.exit(2)
+
def parseUrlargs(self, args):
if len(args) > 0:
@@ -123,10 +148,10 @@ def getGroup(self, spec):
return self.get("groups", spec.proj, spec.grp)
def getAssets(self, spec):
- return self.get("ueassets", spec.proj, spec.grp)
+ return self.get("assets", spec.proj, spec.grp)
def getAsset(self, spec):
- return self.get("ueassets", spec.proj, spec.grp, spec.asst)
+ return self.get("assets", spec.proj, spec.grp, spec.asst)
def getElements(self, spec):
return self.get("elements", spec.proj, spec.grp, spec.asst)
@@ -143,7 +168,7 @@ def saveGroup(self, spec, data):
self.post("groups", spec.proj, data={"group": data})
def saveAsset(self, spec, data):
- self.post("ueassets", spec.proj, spec.grp,
+ self.post("assets", spec.proj, spec.grp,
data={"asset": data})
def saveElement(self, spec, data):
@@ -172,3 +197,17 @@ def updateElement(self, spec, data):
def updateVersion(self, spec, data):
self.put("versions", spec, data=data)
+
+ def destroyProject(self, spec):
+ self.destroy("projects", spec.proj)
+
+ def destroyGroup(self, spec):
+ self.destroy("groups", spec.proj, spec.grp)
+
+ def destroyAsset(self, spec):
+ self.destroy("assets", spec.proj, spec.grp, spec.asst)
+
+ def destroyElement(self, spec):
+ self.destroy("elements", spec.proj, spec.grp, spec.asst,
+ spec.elclass, spec.eltype, spec.elname)
+
View
1 src/ueCore/Create.py
@@ -4,7 +4,6 @@
import ueClient, ueSpec
import ueCore.AssetUtils as ueAssetUtils
-import ueCore.FileUtils as ueFileUtils
def createProject(spec, dbMeta={}):
project = {}
View
19 src/ueCore/Destroy.py
@@ -0,0 +1,19 @@
+import ueClient, ueSpec
+
+import ueCore.AssetUtils as ueAssetUtils
+
+def destroyProject(spec):
+ ueClient.client.destroyProject(spec)
+
+def destroyGroup(spec):
+ ueClient.client.destroyGroup(spec)
+
+def destroyAsset(spec):
+ ueClient.client.destroyAsset(spec)
+
+def destroyElement(spec):
+ ueClient.client.destroyElement(spec)
+
+def destroyVersion(spec):
+ ueClient.client.destroyVersion(spec)
+
View
22 src/ueServer/app/controllers/assets_controller.rb
@@ -18,14 +18,7 @@ def show
end
def create
- @group = Project.where(:name => params[:proj]).first.groups.where(
- :name => params[:grp]).first
-# @asset = @group.assets.new(:name => params[:name],
-# :asset_type => params[:asset_type],
-# :created_by => params[:created_by],
-# :path => params[:path],
-# :startFrame => params[:startFrame],
-# :endFrame => params[:endFrame])
+ @group = Group.get_group(params[:proj], params[:grp])
@asset = @group.assets.new(params[:asset])
respond_to do |format|
@@ -45,5 +38,18 @@ def update
end
def destroy
+ @asset = Asset.get_asset(params[:proj], params[:grp], params[:asst])
+
+ respond_to do |format|
+ if @asset.destroy
+ format.html
+ format.json { render :json => @asset,
+ :status => :ok }
+ else
+ format.html
+ format.json { render :json => @asset.errors,
+ :status => :unprocessable_entity }
+ end
+ end
end
end
View
36 src/ueServer/app/controllers/elements_controller.rb
@@ -19,15 +19,10 @@ def show
end
def create
- @asset = Project.where(:name => params[:proj]).first.groups.where(
- :name => params[:grp]).first.assets.where(
- :name => params[:asst]).first
-# @element = @asset.elements.new(:elname => params[:elname],
-# :eltype => params[:eltype],
-# :elclass => params[:elclass],
-# :comment => params[:comment],
-# :thumbnail => params[:thumbnail],
-# :created_by => params[:created_by])
+# @asset = Project.where(:name => params[:proj]).first.groups.where(
+# :name => params[:grp]).first.assets.where(
+# :name => params[:asst]).first
+ @asset = Asset.get_asset(params[:proj], params[:grp], params[:asst])
@element = @asset.elements.new(params[:element])
@element.elclass = params[:elclass]
@element.eltype = params[:eltype]
@@ -53,11 +48,6 @@ def create_version
:elclass => params[:elclass],
:eltype => params[:eltype],
:elname => params[:elname]).first
-# @version = @element.versions.new(:version => params[:version],
-# :comment => params[:comment],
-# :passes => params[:passes],
-# :thumbnail => params[:thumbnail],
-# :created_by => params[:created_by])
@version = @element.versions.new(params[:version])
respond_to do |format|
@@ -77,5 +67,23 @@ def update
end
def destroy
+ @element = Project.where(:name => params[:proj]).first.groups.where(
+ :name => params[:grp]).first.assets.where(
+ :name => params[:asst]).first.elements.where(
+ :elclass => params[:elclass],
+ :eltype => params[:eltype],
+ :elname => params[:elname]).first
+
+ respond_to do |format|
+ if @element.destroy
+ format.html
+ format.json { render :json => @element,
+ :status => :ok }
+ else
+ format.html
+ format.json { render :json => @element.errors,
+ :status => :unprocessable_entity }
+ end
+ end
end
end
View
19 src/ueServer/app/controllers/groups_controller.rb
@@ -18,11 +18,7 @@ def show
end
def create
- @project = Project.where(:name => params[:proj]).first
-# @group = @project.groups.new(:name => params[:name],
-# :group_type => params[:group_type],
-# :created_by => params[:created_by],
-# :path => params[:path])
+ @project = Project.get_project(params[:proj])
@group = @project.groups.new(params[:group])
respond_to do |format|
@@ -42,5 +38,18 @@ def update
end
def destroy
+ @group = Group.get_group(params[:proj], params[:grp])
+
+ respond_to do |format|
+ if @group.destroy
+ format.html
+ format.json { render :json => @group,
+ :status => :ok }
+ else
+ format.html
+ format.json { render :json => @group.errors,
+ :status => :unprocessable_entity }
+ end
+ end
end
end
View
16 src/ueServer/app/controllers/projects_controller.rb
@@ -18,9 +18,6 @@ def show
end
def create
-# @project = Project.new(:name => params[:name],
-# :created_by => params[:created_by],
-# :path => params[:path])
@project = Project.new(params[:project])
respond_to do |format|
@@ -62,5 +59,18 @@ def update
end
def destroy
+ @project = Project.get_project(params[:proj])
+
+ respond_to do |format|
+ if @project.destroy
+ format.html
+ format.json { render :json => @project,
+ :status => :ok }
+ else
+ format.html
+ format.json { render :json => @project.errors,
+ :status => :unprocessable_entity }
+ end
+ end
end
end
View
14 src/ueServer/app/models/asset.rb
@@ -17,7 +17,15 @@ class Asset
before_save do
self.path = get_path
end
- after_save :create_dirs
+
+ after_save do
+ UeFileUtils::create_dir_tree get_path, UeFileUtils::asset_dirs[self.asset_type][0]
+ end
+
+ before_destroy do
+ self.elements.destroy_all
+ UeFileUtils::delete_dir self.path
+ end
def self.get_asset project, group, asset
g = Group.get_group project, group
@@ -51,8 +59,4 @@ def get_path
self.path
end
end
-
- def create_dirs
- UeFileUtils::create_dir_tree get_path, UeFileUtils::asset_dirs[self.asset_type][0]
- end
end
View
14 src/ueServer/app/models/element.rb
@@ -18,7 +18,15 @@ class Element
before_save do
self.path = get_path
end
- after_save :create_dirs
+
+ after_save do
+ UeFileUtils::create_dir get_path
+ end
+
+ before_destroy do
+ self.versions.destroy_all
+ UeFileUtils::delete_dir self.path
+ end
def self.get_element project, group, asset, elclass, eltype, elname
a = Asset.get_asset project, group, asset
@@ -52,8 +60,4 @@ def get_path
self.path
end
end
-
- def create_dirs
- UeFileUtils::create_dir get_path
- end
end
View
14 src/ueServer/app/models/group.rb
@@ -17,7 +17,15 @@ class Group
before_save do
self.path = get_path
end
- after_save :create_dirs
+
+ after_save do
+ UeFileUtils::create_dir_tree get_path, UeFileUtils::group_dirs[self.group_type][0]
+ end
+
+ before_destroy do
+ self.assets.destroy_all
+ UeFileUtils::delete_dir self.path
+ end
def self.get_group project, group
p = Project.get_project project
@@ -51,8 +59,4 @@ def get_path
self.path
end
end
-
- def create_dirs
- UeFileUtils::create_dir_tree get_path, UeFileUtils::group_dirs[self.group_type][0]
- end
end
View
14 src/ueServer/app/models/project.rb
@@ -15,7 +15,15 @@ class Project
before_save do
self.path = get_path
end
- after_save :create_dirs
+
+ after_save do
+ UeFileUtils::create_dir_tree get_path, UeFileUtils::project_dirs
+ end
+
+ before_destroy do
+ self.groups.destroy_all
+ UeFileUtils::delete_dir self.path
+ end
def self.get_project project
p = Project.where(:name => project).first
@@ -35,8 +43,4 @@ def get_path
self.path
end
end
-
- def create_dirs
- UeFileUtils::create_dir_tree get_path, UeFileUtils::project_dirs
- end
end
View
22 src/ueServer/app/models/version.rb
@@ -15,13 +15,15 @@ class Version
before_save do
self.path = get_path
- self.file_name = UeFileUtils::get_element_name self.element.asset.group.project.name,
- self.element.asset.group.name,
- self.element.asset.name, self.element.elclass,
- self.element.eltype, self.element.elname,
- self.version.to_i
+ self.file_name = get_name
+ end
+ after_save do
+ UeFileUtils::create_dir get_path
+ end
+
+ before_destroy do
+ UeFileUtils::delete_dir self.path
end
- after_save :create_dirs
private
@@ -34,7 +36,11 @@ def get_path
end
end
- def create_dirs
- UeFileUtils::create_dir get_path
+ def get_name
+ UeFileUtils::get_element_name self.element.asset.group.project.name,
+ self.element.asset.group.name,
+ self.element.asset.name, self.element.elclass,
+ self.element.eltype, self.element.elname,
+ self.version.to_i
end
end
View
4 src/ueServer/config/environments/production.rb
@@ -6,7 +6,7 @@
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
- config.action_controller.perform_caching = true
+ config.action_controller.perform_caching = false
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
@@ -15,7 +15,7 @@
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
- config.assets.compile = false
+ config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
View
10 src/ueServer/config/mongoid.yml
@@ -8,11 +8,11 @@ test:
# set these environment variables on your prod server
production:
- host: <%= ENV['MONGOID_HOST'] %>
- port: <%= ENV['MONGOID_PORT'] %>
- username: <%= ENV['MONGOID_USERNAME'] %>
- password: <%= ENV['MONGOID_PASSWORD'] %>
- database: <%= ENV['MONGOID_DATABASE'] %>
+ host: localhost
+ #port:
+ #username:
+ #password:
+ database: ue
# slaves:
# - host: slave1.local
# port: 27018
View
14 src/ueServer/config/routes.rb
@@ -1,27 +1,27 @@
UeServer::Application.routes.draw do
match "/projects" => "projects#index", :as => :projects, :via => :get
match "/projects" => "projects#create", :as => :project, :via => :post
- match "/projects" => "projects#update", :as => :project, :via => :put
- match "/projects" => "projects#destroy", :as => :project, :via => :destroy
+ match "/projects/:proj" => "projects#update", :as => :project, :via => :put
+ match "/projects/:proj" => "projects#destroy", :as => :project, :via => :delete
match "/projects/:proj" => "projects#show", :as => :project
match "/groups/:proj" => "groups#index", :as => :groups, :via => :get
match "/groups/:proj" => "groups#create", :as => :group, :via => :post
- match "/groups/:proj" => "groups#update", :as => :group, :via => :put
- match "/groups/:proj" => "groups#destroy", :as => :group, :via => :destroy
+ match "/groups/:proj/:grp" => "groups#update", :as => :group, :via => :put
+ match "/groups/:proj/:grp" => "groups#destroy", :as => :group, :via => :delete
match "/groups/:proj/:grp" => "groups#show", :as => :group
match "/ueassets/:proj/:grp" => "assets#index", :as => :assets, :via => :get
match "/ueassets/:proj/:grp" => "assets#create", :as => :asset, :via => :post
- match "/ueassets/:proj/:grp" => "assets#update", :as => :asset, :via => :put
- match "/ueassets/:proj/:grp" => "assets#destroy", :as => :asset, :via => :destroy
+ match "/ueassets/:proj/:grp/:asst" => "assets#update", :as => :asset, :via => :put
+ match "/ueassets/:proj/:grp/:asst" => "assets#destroy", :as => :asset, :via => :delete
match "/ueassets/:proj/:grp/:asst" => "assets#show", :as => :asset
match "/elements/:proj/:grp/:asst" => "elements#index", :as => :elements
match "/elements/:proj/:grp/:asst/:elclass/:eltype/:elname" => "elements#show", :as => :element, :via => :get
match "/elements/:proj/:grp/:asst/:elclass/:eltype/:elname" => "elements#create", :as => :element, :via => :post
match "/elements/:proj/:grp/:asst/:elclass/:eltype/:elname" => "elements#update", :as => :element, :via => :put
- match "/elements/:proj/:grp/:asst/:elclass/:eltype/:elname" => "elements#destroy", :as => :element, :via => :destroy
+ match "/elements/:proj/:grp/:asst/:elclass/:eltype/:elname" => "elements#destroy", :as => :element, :via => :delete
match "/versions/:proj/:grp/:asst/:elclass/:eltype/:elname" => "elements#create_version", :as => :version, :via => :post
View
4 src/ueServer/lib/ue_file_utils.rb
@@ -166,4 +166,8 @@ def copy_files f, d
copy_file(fi, d)
end
end
+
+ def delete_dir d
+ FileUtils.rm_rf d
+ end
end
View
4 ue_setup
@@ -26,6 +26,10 @@ ln -s $UE_PATH/src/tools/ueAddFiles.py $UE_PATH/bin/ueAddFiles
ln -s $UE_PATH/src/tools/ueCreateAsset.py $UE_PATH/bin/ueCreateAsset
ln -s $UE_PATH/src/tools/ueCreateGroup.py $UE_PATH/bin/ueCreateGroup
ln -s $UE_PATH/src/tools/ueCreateProject.py $UE_PATH/bin/ueCreateProject
+ln -s $UE_PATH/src/tools/ueDestroyElement.py $UE_PATH/bin/ueDestroyElement
+ln -s $UE_PATH/src/tools/ueDestroyAsset.py $UE_PATH/bin/ueDestroyAsset
+ln -s $UE_PATH/src/tools/ueDestroyGroup.py $UE_PATH/bin/ueDestroyGroup
+ln -s $UE_PATH/src/tools/ueDestroyProject.py $UE_PATH/bin/ueDestroyProject
ln -s $UE_PATH/src/tools/ueListElements.py $UE_PATH/bin/ueListElements
ln -s $UE_PATH/src/tools/ueListAssets.py $UE_PATH/bin/ueListAssets
ln -s $UE_PATH/src/tools/ueListGroups.py $UE_PATH/bin/ueListGroups

0 comments on commit 3db0a2f

Please sign in to comment.