<s> import shutil <EOL> import uuid <EOL> from django . contrib . auth . models import User <EOL> from django . db import models <EOL> from django . utils . translation import ugettext as _ <EOL> from ide . models . files import ResourceFile , ResourceIdentifier , SourceFile , ResourceVariant <EOL> from ide . utils import generate_half_uuid <EOL> from ide . models . meta import IdeModel <EOL> __author__ = '<STR_LIT>' <EOL> class Project ( IdeModel ) : <EOL> owner = models . ForeignKey ( User ) <EOL> name = models . CharField ( max_length = <NUM_LIT:50> ) <EOL> last_modified = models . DateTimeField ( auto_now_add = True ) <EOL> PROJECT_TYPES = ( <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> project_type = models . CharField ( max_length = <NUM_LIT:10> , choices = PROJECT_TYPES , default = '<STR_LIT>' ) <EOL> SDK_VERSIONS = ( <EOL> ( '<STR_LIT:2>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT:3>' , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> sdk_version = models . CharField ( max_length = <NUM_LIT:6> , choices = SDK_VERSIONS , default = '<STR_LIT:2>' ) <EOL> app_uuid = models . CharField ( max_length = <NUM_LIT> , blank = True , null = True , default = generate_half_uuid ) <EOL> app_company_name = models . CharField ( max_length = <NUM_LIT:100> , blank = True , null = True ) <EOL> app_short_name = models . CharField ( max_length = <NUM_LIT:100> , blank = True , null = True ) <EOL> app_long_name = models . CharField ( max_length = <NUM_LIT:100> , blank = True , null = True ) <EOL> app_version_label = models . CharField ( max_length = <NUM_LIT> , blank = True , null = True , default = '<STR_LIT:1.0>' ) <EOL> app_is_watchface = models . BooleanField ( default = False ) <EOL> app_is_hidden = models . BooleanField ( default = False ) <EOL> app_is_shown_on_communication = models . BooleanField ( default = False ) <EOL> app_capabilities = models . CharField ( max_length = <NUM_LIT:255> , blank = True , null = True ) <EOL> app_keys = models . TextField ( default = "<STR_LIT:{}>" ) <EOL> app_jshint = models . BooleanField ( default = True ) <EOL> app_platforms = models . TextField ( max_length = <NUM_LIT:255> , blank = True , null = True ) <EOL> app_modern_multi_js = models . BooleanField ( default = True ) <EOL> app_capability_list = property ( lambda self : self . app_capabilities . split ( '<STR_LIT:U+002C>' ) ) <EOL> app_platform_list = property ( lambda self : self . app_platforms . split ( '<STR_LIT:U+002C>' ) if self . app_platforms else [ ] ) <EOL> OPTIMISATION_CHOICES = ( <EOL> ( '<STR_LIT:0>' , '<STR_LIT:None>' ) , <EOL> ( '<STR_LIT:1>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:s>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:2>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:3>' , '<STR_LIT>' ) , <EOL> ) <EOL> optimisation = models . CharField ( max_length = <NUM_LIT:1> , choices = OPTIMISATION_CHOICES , default = '<STR_LIT:s>' ) <EOL> github_repo = models . CharField ( max_length = <NUM_LIT:100> , blank = True , null = True ) <EOL> github_branch = models . CharField ( max_length = <NUM_LIT:100> , blank = True , null = True ) <EOL> github_last_sync = models . DateTimeField ( blank = True , null = True ) <EOL> github_last_commit = models . CharField ( max_length = <NUM_LIT> , blank = True , null = True ) <EOL> github_hook_uuid = models . CharField ( max_length = <NUM_LIT> , blank = True , null = True ) <EOL> github_hook_build = models . BooleanField ( default = False ) <EOL> def get_last_build ( self ) : <EOL> try : <EOL> return self . builds . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> return None <EOL> def get_menu_icon ( self ) : <EOL> try : <EOL> return self . resources . filter ( is_menu_icon = True ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> return None <EOL> def has_platform ( self , platform ) : <EOL> return self . app_platforms is None or platform in self . app_platform_list <EOL> last_build = property ( get_last_build ) <EOL> menu_icon = property ( get_menu_icon ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT:%s>" % self . name <EOL> class TemplateProject ( Project ) : <EOL> KIND_TEMPLATE = <NUM_LIT:1> <EOL> KIND_SDK_DEMO = <NUM_LIT:2> <EOL> KIND_CHOICES = ( <EOL> ( KIND_TEMPLATE , _ ( '<STR_LIT>' ) ) , <EOL> ( KIND_SDK_DEMO , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> template_kind = models . IntegerField ( choices = KIND_CHOICES , db_index = True ) <EOL> def copy_into_project ( self , project ) : <EOL> uuid_string = "<STR_LIT:U+002CU+0020>" . join ( [ "<STR_LIT>" % ord ( b ) for b in uuid . uuid4 ( ) . bytes ] ) <EOL> for resource in self . resources . all ( ) : <EOL> new_resource = ResourceFile . objects . create ( project = project , file_name = resource . file_name , kind = resource . kind ) <EOL> for variant in resource . variants . all ( ) : <EOL> new_variant = ResourceVariant . objects . create ( resource_file = new_resource , tags = variant . tags ) <EOL> new_variant . save_string ( variant . get_contents ( ) ) <EOL> for i in resource . identifiers . all ( ) : <EOL> ResourceIdentifier . objects . create ( <EOL> resource_file = new_resource , <EOL> resource_id = i . resource_id , <EOL> character_regex = i . character_regex , <EOL> tracking = i . tracking , <EOL> compatability = i . compatibility , <EOL> target_platforms = i . target_platforms , <EOL> memory_format = i . memory_format , <EOL> storage_format = i . storage_format , <EOL> space_optmization = i . space_optimisation <EOL> ) <EOL> for source_file in self . source_files . all ( ) : <EOL> new_file = SourceFile . objects . create ( project = project , file_name = source_file . file_name ) <EOL> new_file . save_file ( source_file . get_contents ( ) . replace ( "<STR_LIT>" , uuid_string ) ) <EOL> project . app_capabilities = self . app_capabilities <EOL> project . app_is_watchface = self . app_is_watchface <EOL> project . app_is_hidden = self . app_is_hidden <EOL> project . app_is_shown_on_communication = self . app_is_shown_on_communication <EOL> project . app_keys = self . app_keys <EOL> project . app_jshint = self . app_jshint <EOL> project . app_modern_multi_js = self . app_modern_multi_js <EOL> project . save ( ) </s>
