1
# OpenShot Video Editor is a program that creates, modifies, and edits video files.
2
# Copyright (C) 2009 Jonathan Thomas
4
# This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
6
# OpenShot Video Editor is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# OpenShot Video Editor is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with OpenShot Video Editor. If not, see <http://www.gnu.org/licenses/>.
25
""" Check and see if this is the only instance of OpenShot. If not, then kill this instance. """
26
path = os.path.dirname(os.path.abspath(sys.argv[0]))
27
pidPath = os.path.join(path, "pid.lock")
29
if os.path.exists(pidPath):
31
pid=int(open(pidPath, 'r').read().strip())
34
# check if pid is running (this doesn't kill it)
37
# OpenShot is alreay running, so kill this instance (ONLY KILL IF IT CONTAINS ARGS)
38
# The user should be able to run as many instances of OpenShot as needed... but when ARGS
39
# are passed, it should only allow 1 instance
42
# loop through the remaining args
43
for arg in sys.argv[1:]:
44
# create a import queue file for the primary instance of OpenShot
45
fp=open(os.path.join(path, "queue", str(uuid.uuid1())), 'w')
50
sys.exit("Another instance of this program is already running")
53
# not running anymore (maybe program crashed... and left this pid file)
55
fp.write(str(os.getpid()))
59
# pid file doesn't exist
61
fp.write(str(os.getpid()))
65
class queue_watcher ( threading.Thread ):
66
""" This class polls the /queue/ folder, looking for files to import into OpenShot. When it finds
67
a text file, it should get the path out of the file, import the file, and then delete the file. Only
68
1 instance of OpenShot should be polling this folder. """
70
def set_form(self, main_form):
74
""" This is the main method on this thread. This method should not return anything, or the
75
thread will no longer be active... """
79
self.path = os.path.dirname(os.path.abspath(sys.argv[0]))
80
self.queue_location = os.path.join(self.path, "queue")
81
pidPath = os.path.join(self.path, "pid.lock")
83
pid=int(open(pidPath, 'r').read().strip())
85
# only allow this thread to run if this instance of OpenShot is the primary instance.
86
# we can't have 2 instances both watching the /queue/ folder.
87
if os.getpid() == pid:
89
# this loop will continue as long as OpenShot is running
93
# check for files in the /queue/ folder
94
for filename in os.listdir(self.queue_location):
96
full_filename = os.path.join(self.queue_location, filename)
98
# read the content of the file
99
import_path = open(full_filename, 'r').read().strip()
102
#self.form.project.project_folder.AddFile(import_path)
103
gobject.idle_add(self.form.project.project_folder.AddFile, import_path)
107
os.remove(full_filename)
109
# refresh project files list (if needed)
112
gobject.idle_add(self.form.refresh)
118
print "Not the primary instance of OpenShot. Not starting queue watcher thread."