~openshot.code/openshot/main

« back to all changes in this revision

Viewing changes to main/classes/lock.py

  • Committer: Jonathan Thomas
  • Date: 2009-09-08 04:49:08 UTC
  • Revision ID: jonathan@jonathan64-20090908044908-kzhw2m1dl251yt9y
Bumping version to 0.9.30

Here it goes.  Massive re-factoring across OpenShot.  I put
a ton of regression work into this to ensure everything still
works, but as always, I could have missed something.

The biggest changes: 
------------------------------
1) Distutils is now used to install OpenShot (setup.py install).
   Installing OpenShot this way will copy Mime Types, Register Icons,
   Add launcher to Application menu, and copy the OpenShot .py code 
   to the /site-packages/ folder.
2) Python code moved into ~/openshot/openshot/
3) New folders ~/openshot/[bin,docs,xdg]
4) Translations moved to ~/openshot/openshot/locale
5) classes/project.py contains all of the PATH variables
6) classes/info.py contains the version of OpenShot
7) after installing (using setup.py), the /openshot/bin/openshot 
   is the launcher that gets copied to the /usr/bin
8) A few bug fixes have also been added:
   A) removing marker clears timeline
   B) opening a project stopped some changes from refreshing the video
9) Arguments can be passed to OpenShot ($ openshot 'video1.avi', 'video2.avi')
------------------------------

There are now 2 ways to launch OpenShot.

$ openshot (assuming setup.py was used to install OpenShot)
$ ~/openshot/openshot/openshot.py  (I know... it looks funny)

Good luck to everyone testing this!  =)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#       OpenShot Video Editor is a program that creates, modifies, and edits video files.
2
 
#   Copyright (C) 2009  Jonathan Thomas
3
 
#
4
 
#       This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
5
 
#
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.
10
 
#
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.
15
 
#
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/>.
18
 
 
19
 
import os, sys
20
 
import threading
21
 
import time
22
 
import uuid
23
 
 
24
 
def check_pid():
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")
28
 
        
29
 
        if os.path.exists(pidPath):
30
 
                # pid file exists
31
 
                pid=int(open(pidPath, 'r').read().strip())
32
 
                
33
 
                try:
34
 
                        # check if pid is running (this doesn't kill it)
35
 
                        os.kill(pid, 0)
36
 
                        
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
40
 
                        if len(sys.argv) > 1:
41
 
                                
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')
46
 
                                        fp.write(arg)
47
 
                                        fp.close()
48
 
                                
49
 
                                # exit the program
50
 
                                sys.exit("Another instance of this program is already running")
51
 
                        
52
 
                except OSError:
53
 
                        # not running anymore (maybe program crashed... and left this pid file)
54
 
                        fp=open(pidPath, 'w')
55
 
                        fp.write(str(os.getpid()))
56
 
                        fp.close()
57
 
 
58
 
        else:
59
 
                # pid file doesn't exist
60
 
                fp=open(pidPath, 'w')
61
 
                fp.write(str(os.getpid()))
62
 
                fp.close()
63
 
                
64
 
 
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. """
69
 
        
70
 
        def set_form(self, main_form):
71
 
                self.form = main_form
72
 
 
73
 
        def run ( self ):
74
 
                """ This is the main method on this thread.  This method should not return anything, or the 
75
 
                thread will no longer be active...  """
76
 
                
77
 
                import gobject
78
 
 
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")
82
 
                self.amAlive = True
83
 
                pid=int(open(pidPath, 'r').read().strip())
84
 
                
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:
88
 
 
89
 
                        # this loop will continue as long as OpenShot is running
90
 
                        while self.amAlive:
91
 
                                needs_refresh = False
92
 
 
93
 
                                # check for files in the /queue/ folder
94
 
                                for filename in os.listdir(self.queue_location):
95
 
                                        # get full file path
96
 
                                        full_filename = os.path.join(self.queue_location, filename)
97
 
                                        
98
 
                                        # read the content of the file
99
 
                                        import_path = open(full_filename, 'r').read().strip()
100
 
 
101
 
                                        # IMPORT FILE
102
 
                                        #self.form.project.project_folder.AddFile(import_path)
103
 
                                        gobject.idle_add(self.form.project.project_folder.AddFile, import_path)
104
 
                                        needs_refresh = True
105
 
        
106
 
                                        # delete import file
107
 
                                        os.remove(full_filename)
108
 
                                        
109
 
                                # refresh project files list (if needed)
110
 
                                if needs_refresh:
111
 
                                        #self.form.refresh()
112
 
                                        gobject.idle_add(self.form.refresh)
113
 
 
114
 
                                # wait 2 seconds
115
 
                                time.sleep(1) 
116
 
                
117
 
                else:
118
 
                        print "Not the primary instance of OpenShot. Not starting queue watcher thread."