diff --git a/install_minimal/include/AirtimeInstall.php b/install_minimal/include/AirtimeInstall.php index 5ce52c05b..1459ff2d7 100644 --- a/install_minimal/include/AirtimeInstall.php +++ b/install_minimal/include/AirtimeInstall.php @@ -116,19 +116,19 @@ class AirtimeInstall } } - + /* TODO: This function should be moved to the media-monitor * install script. */ public static function InstallStorageDirectory() { global $CC_CONFIG, $CC_DBC; echo "* Storage directory setup".PHP_EOL; - + $ini = parse_ini_file(__DIR__."/airtime-install.ini"); $stor_dir = $ini["storage_dir"]; - + $dirs = array($stor_dir, $stor_dir."/organize"); - + foreach ($dirs as $dir){ if (!file_exists($dir)) { @mkdir($dir, 02777, true); @@ -152,7 +152,7 @@ class AirtimeInstall echo "* Giving Apache permission to access $rp".PHP_EOL; $success = chgrp($rp, $CC_CONFIG["webServerUser"]); - $success = chown($rp, "pypo"); + $success = chown($rp, "www-data"); $success = chmod($rp, 02777); } } @@ -270,7 +270,7 @@ class AirtimeInstall } return true; } - + public static function SetUniqueId() { global $CC_DBC; @@ -404,12 +404,12 @@ class AirtimeInstall exec("rm -rf \"$path\""); } - + public static function CreateCronFile(){ // Create CRON task to run every day. Time of day is initialized to a random time. $hour = rand(0,23); $minute = rand(0,59); - + $fp = fopen('/etc/cron.d/airtime-crons','w'); fwrite($fp, "$minute $hour * * * root /usr/lib/airtime/utils/phone_home_stat\n"); fclose($fp); diff --git a/install_minimal/upgrades/airtime-1.9.0/media-monitor-upgrade.py b/install_minimal/upgrades/airtime-1.9.0/media-monitor-upgrade.py index f7adcfc52..7ccc68bf1 100644 --- a/install_minimal/upgrades/airtime-1.9.0/media-monitor-upgrade.py +++ b/install_minimal/upgrades/airtime-1.9.0/media-monitor-upgrade.py @@ -9,6 +9,7 @@ import json import ConfigParser import pwd import grp +import subprocess import os.path @@ -28,35 +29,34 @@ config.read('/etc/airtime/airtime.conf') stor_dir = config.get('general', 'base_files_dir') + "/stor" organize_dir = stor_dir + '/organize' -try: - os.makedirs(organize_dir) - omask = os.umask(0) - - uid = pwd.getpwnam('pypo')[2] - gid = grp.getgrnam('www-data')[2] - - os.chown(organize_dir, uid, gid) - os.chmod(organize_dir, 02777) - -except Exception, e: - print e -finally: - os.umask(omask) - mmconfig.storage_directory = os.path.normpath(stor_dir) mmconfig.imported_directory = os.path.normpath(stor_dir + '/imported') mmconfig.organize_directory = os.path.normpath(organize_dir) mmc = MediaMonitorCommon(mmconfig) +try: + os.makedirs(organize_dir) +except Exception, e: + print e + +#older versions of Airtime installed from repository at least had owner of stor dir as "root" +mmc.set_needed_file_permissions(stor_dir, True) +mmc.set_needed_file_permissions(organize_dir, True) + #read list of all files in stor location.....and one-by-one pass this through to #mmc.organize_files. print out json encoding of before and after pairs = [] for root, dirs, files in os.walk(mmconfig.storage_directory): for f in files: - #print os.path.join(root, f) - #print mmc.organize_new_file(os.path.join(root, f)) - pair = os.path.join(root, f), mmc.organize_new_file(os.path.join(root, f)) + old_filepath = os.path.join(root, f) + new_filepath = mmc.organize_new_file(os.path.join(root, f)) + pair = old_filepath, new_filepath pairs.append(pair) + mmc.set_needed_file_permissions(new_filepath, False) + +#need to set all the dirs in imported to be owned by www-data. +command = "chown -R www-data " + stor_dir +subprocess.call(command.split(" ")) print json.dumps(pairs) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py index af709b17d..d420ec074 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py @@ -136,11 +136,16 @@ class AirtimeMetadata: #incase track number is in format u'4/11' #need to also check that the tracknumber is even a tracknumber (cc-2582) if 'MDATA_KEY_TRACKNUMBER' in md: + try: + md['MDATA_KEY_TRACKNUMBER'] = int(md['MDATA_KEY_TRACKNUMBER']) + except Exception, e: + pass + if isinstance(md['MDATA_KEY_TRACKNUMBER'], basestring): match = re.search('^(\d*/\d*)?', md['MDATA_KEY_TRACKNUMBER']) if match.group(0) is not u'': - md['MDATA_KEY_TRACKNUMBER'] = md['MDATA_KEY_TRACKNUMBER'].split("/")[0] + md['MDATA_KEY_TRACKNUMBER'] = int(md['MDATA_KEY_TRACKNUMBER'].split("/")[0]) else: del md['MDATA_KEY_TRACKNUMBER'] diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py index acbe3602b..7c4e706f8 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py @@ -92,8 +92,6 @@ class AirtimeNotifier(Notifier): self.logger.info("Removing watch on: %s wd %s", storage_directory, wd) mm.wm.rm_watch(wd, rec=True) - self.mmc.set_needed_file_permissions(new_storage_directory, True) - self.bootstrap.sync_database_to_filesystem(new_storage_directory_id, new_storage_directory) self.config.storage_directory = os.path.normpath(new_storage_directory) @@ -104,6 +102,10 @@ class AirtimeNotifier(Notifier): self.mmc.ensure_is_dir(self.config.imported_directory) self.mmc.ensure_is_dir(self.config.organize_directory) + self.mmc.set_needed_file_permissions(self.config.storage_directory, True) + self.mmc.set_needed_file_permissions(self.config.imported_directory, True) + self.mmc.set_needed_file_permissions(self.config.organize_directory, True) + self.watch_directory(new_storage_directory) elif m['event_type'] == "file_delete": filepath = m['filepath'].encode('utf-8') diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index aca32f6e4..fa1fcbd8f 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -179,10 +179,8 @@ class MediaMonitorCommon: else: md[m] = orig_md[m] - self.logger.debug(md['MDATA_KEY_TRACKNUMBER']) if 'MDATA_KEY_TRACKNUMBER' in orig_md: #make sure all track numbers are at least 2 digits long in the filepath. - self.logger.debug("formatting track number") md['MDATA_KEY_TRACKNUMBER'] = "%02d" % (int(md['MDATA_KEY_TRACKNUMBER'])) #format bitrate as 128kbps diff --git a/utils/airtime-import/airtime-import.py b/utils/airtime-import/airtime-import.py index 5d00a8f1d..77ea4bb75 100644 --- a/utils/airtime-import/airtime-import.py +++ b/utils/airtime-import/airtime-import.py @@ -37,6 +37,10 @@ def copy_or_move_files_to(paths, dest, flag): path = os.path.realpath(path) else: path = currentDir+path + path = path.decode('utf-8') + path = path.encode('utf-8') + dest = dest.decode('utf-8') + dest = dest.encode('utf-8') if(os.path.exists(path)): if(os.path.isdir(path)): path = format_dir_string(path) @@ -140,6 +144,8 @@ def WatchAddAction(option, opt, value, parser): elif(len(parser.rargs) == 0 ): raise OptionValueError("No argument found. This option requires exactly one argument.") path = parser.rargs[0] + path = path.decode('utf-8') + path = path.encode('utf-8') if(os.path.isdir(path)): res = api_client.add_watched_dir(path) if(res is None): @@ -175,6 +181,8 @@ def WatchRemoveAction(option, opt, value, parser): elif(len(parser.rargs) == 0 ): raise OptionValueError("No argument found. This option requires exactly one argument.") path = parser.rargs[0] + path = path.decode('utf-8') + path = path.encode('utf-8') if(os.path.isdir(path)): res = api_client.remove_watched_dir(path) if(res is None): @@ -215,6 +223,8 @@ def StorageSetAction(option, opt, value, parser): raise OptionValueError("No argument found. This option requires exactly one argument.") path = parser.rargs[0] + path = path.decode('utf-8') + path = path.encode('utf-8') if(os.path.isdir(path)): res = api_client.set_storage_dir(path) if(res is None):