-
Notifications
You must be signed in to change notification settings - Fork 1
/
moveit.py
71 lines (63 loc) · 2.79 KB
/
moveit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
GUI tool to create a Bag from a filesystem folder.
"""
import sys
import os
import shutil
import bagit
from time import strftime
from distutils.dir_util import copy_tree
import tempfile
import zerorpc
import json
from datetime import datetime
class MoveIt(object):
def bag_package(self, contactname, jobtitle, department, email, phone, creator, rrsda, title, datefrom, dateto, description, package_folder):
bag_dir_parent = tempfile.mkdtemp()
if os.path.isdir(bag_dir_parent):
shutil.rmtree(bag_dir_parent)
bag_dir = os.path.join(bag_dir_parent, 'bag')
os.makedirs(os.path.join(bag_dir, os.path.basename(package_folder.strip('"'))))
copy_tree(os.path.normpath(package_folder.strip('"')), os.path.join(bag_dir, os.path.basename(package_folder.strip('"'))))
for root, sub, files in os.walk(bag_dir):
for file in files:
if file == ".DS_Store":
os.remove(os.path.abspath(os.path.join(root, file)))
version = "2.0.6"
try:
bag = bagit.make_bag(bag_dir, None, 1, ['sha256'])
bag.info['Package-Time'] = strftime("%Y-%m-%d %H:%M:%S")
bag.info['Bag-Software-Agent'] = "MoveIt " + version
bag.info['Contact-Name'] = contactname
bag.info['Contact-Title'] = jobtitle
bag.info['Contact-Organization'] = department
bag.info['Contact-Email'] = email
bag.info['Contact-Phone'] = phone
bag.info['Source-Organization'] = creator
bag.info['RRSDA-Number'] = rrsda
bag.info['External-Identifier'] = title
bag.info['Year-Start'] = datefrom
bag.info['Year-End'] = dateto
bag.info['External-Description'] = description
bag.info['Internal-Sender-Identifier'] = ''
bag.info['Internal-Sender-Description'] = ''
bag.info['Internal-Validation-Date'] = ''
bag.info['Internal-Validation-By'] = ''
bag.info['Internal-Validation-Note'] = ''
bag.save()
except (bagit.BagError, Exception) as e:
desktop_log = os.path.join(os.environ["HOMEPATH"], "Desktop", "moveit_log.txt")
dt = datetime.now()
with open(desktop_log, "a") as logfile:
logfile.write((str(dt) + " " + str(e)))
return False
bag_destination = os.path.join(str(bag_dir_parent), (title))
zipname = shutil.make_archive(bag_destination, 'zip', bag_dir)
shutil.rmtree(bag_dir)
desktopPath = os.path.expanduser("~/Desktop/")
shutil.move(zipname, os.path.join(desktopPath, os.path.basename(zipname)))
return True
if __name__ == '__main__':
s = zerorpc.Server(MoveIt())
s.bind('tcp://127.0.0.1:' + str(sys.argv[1]))
s.run()